Set sequence numbers for sales orders

As standard, Odoo has a single sequence number for Quotations and Sales Orders. It’s quite easy to customize this.

Sequence numbers

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 (so order numbers restart at the beginning of a month or 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.

Automated Action

Now we can start using it through an Automated Action

Navigate to Settings / Technical / (Automation) / Automated Actions and create a new Automated Action:

Python Code:

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 same Sequence Code [consumer.sale.order] as the one we used on the Sequence.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s