As standard, Odoo has a single sequence number for all Quotations / Sales Orders. It’s quite easy to customize this so that there are different sequences for each types of order.
Start by enabling developer mode and navigate to Settings / Technical / Sequences
Create a new sequence (or copy an existing one):
- The name is for information only, but it should be meaningful.
- The Sequence Code [
consumer.sale.order] will be used later.
- Company can be left blank if you want numbering to be common across all companies, or you can specify different numbering for each company (if you do this, it is recommended to include part of the company name in the prefix, or have some other way of identifying the company).
- The prefix and suffix can be a combination of fixed elements and variables (year, month, day, time).
- You can have sub-sequences by date. This allows you to specify the numbering for each week / month / year.
- Sequence size needs to be large enough to cover the expected number of orders (3 = 1-999, 4 = 1-9,999, 5 = 1 – 99,999, etc.)
- Normally the step will be 1
- Next Number defaults to 1 but could be set to something else if you already have documents from an old system and don’t want to re-use those numbers.
- This is updated by Odoo as invoices are created.
More information about Sequences
Now we can start using it through an Automated Action
Navigate to Settings / Technical / (Automation) / Automated Actions and create a new Automated Action:
for record in records: if record.x_studio_order_type == "Consumer": ref = env['ir.sequence'].next_by_code('consumer.sale.order') record['name'] = ref
This example uses a new field for Order Type (it’s a selection field created using Odoo Studio), but it could be conditioned on any other field.
- We need to use the Sequence Code [
consumer.sale.order] that we defined earlier.
Now when we create a “Consumer” Sales Order it will use this numbering:
13 thoughts on “Multiple sequence numbers for sales orders”
name = fields.Char(string=”Task No”, readonly=True, required=True, copy=False, default=’New’)
def create(self, vals):
if vals.get(‘name’, ‘New’) == ‘New’:
vals[‘name’] = self.env[‘ir.sequence’].next_by_code(‘project.task’) or ‘New’
result = super(FlightReport, self).create(vals)
what is next_by_core here i m facing issue to get this
I’m not a Python programmer, but in your example project.task should be the sequence code (consumer.sale.order in my example).
I nedd this happen base on the warehouse so I change this: record.x_studio_order_type == “Consumer” for record.warehouse_id == 1 but it did not work , I also type the warehouse name “branch1” instead of 1 neither works, please help.
Can you try:
if record.warehouse_id.id == 1
or I think it should also work with:
if record.warehouse_id.name == "branch1"
Yes now it is working both ways but I think the first one is moore secure, thanks a lot Chris
I have been trying to apply the same rule to the purchase order sequences.
In this case, instead of record.warehouse_id.name, I am trying to punch in the record.picking_type_id.name==”Unit A”: so that deliver to address can be used to generate the sequence. But it is not working. Kindly share your thoughts on the same.
I have applied the described scheme in v12 CE and it works 🙂 although not as described.
My Problem: I cannot trigger the action automatically.
It seems Odoo CE does not provide the option of a depicted trigger condition. Well, it doesn’t provide Automated Action at all, but instead Server Action without trigger conditions, which means I have to manually (drop down menu) trigger the action.
Is there python code so the action can be automated (e.g. on create)?
I added this to my model:
for record in records:
if record.x_studio_order_type == “Consumer”:
ref = env[‘ir.sequence’].next_by_code(‘consumer.sale.order’)
record[‘name’] = ref
but it wont work.
BTW, What does (.next_by_code) do?
Automated Actions are available in Community Edition. You may need to install the module.
next_by_code(‘consumer.sale.order’)is just an instruction to get the next number
Pretty embarrassed that I missed this one ;).
How would one add this in code?
I added my sequence like this:
But how to call the action? Help greatly appreciated.
api@model etc. ?
We have implemented this. Is working well, but when user uses Action>Duplicate on a sales order with a different prefix/sequence, the duplicate does not maintain the prefix/sequence, it goes back the the regular sales order sequence/prefix.
Yes, could be because the new field is not copied to the duplicated order. By the time you change it the order number is already allocated.
Thank you for all the tips!
wondering if is it possible to include a variable in the prefix? trying to add dynamic values from Product and merge them in the Sequence of Internal Referance
I think it should be possible with simple python code – I’m not a Python programmer, but there is a lot of information out there: https://www.w3schools.com/python/gloss_python_string_concatenation.asp