How to Set Up a Sequence or Document Number in Odoo

Each transaction, it can be a Sales Order, a Purchase or an Invoice, usually has a unique document number to distinguish one document from another. In odoo the document numbering is very easy. We can adjust the document numbering format through the Settings > Technical > Sequences & Identifiers > Sequences menu, then find the document number you want to change. Of course you must be logged in as an administrator and in debug mode to access this menu.

These are some things you can adjust regarding document numbering in odoo.

Next Number

Next Number is the document number to be used in next transaction. Next Number will always change every time there is a new transaction. Generally, we rarely change the value of this field except in certain conditions, for example because the previous transaction was wrong and it was deleted, so we want to reset the document number starting from a certain number. When you change the value of this field, make sure that the number has not been used in the corresponding document, because if there is two transaction with same document number it will cause an error.

Step

Step is the value added to the Next Number after the transaction succesfully generates the new document number. For example, if the current Next Number value is 10, while the Step value is 1 then when we create a Sales Order, the Sales Order will get a document number of 10, while the new Next Number (next document number) will be 11. It is not recommended to change this field value other than 1, because the document number will be out of order.

Sequence Size

Sequence Size is used to set the minimum length of document number. For example, the current Next Number is “24” while the Sequence Size is “4”, when a transaction is made, this transaction will have a document number of “0024”. If the length of characters in the Next Number is less than the Sequence Size, the document number will be added with the character of “0” before the Next Number until the length of the document number is the same as the Sequence Size. Conversely, if the length of Next Number characters is greater than the Sequence Size, the document number will be the same as the Next Number without adding or subtracting the characters.

Prefix

The prefix is a set of characters that is added before the Next Number in the document number. For example, the prefix is ​​set to “SO” while the current Next Number is “10” then the document number will be “SO10”. Prefix can also use a legend or special phrase in odoo to generate certain values ​​in document number, for example the year or month that the transaction was made. We can use several legend in one prefix to create a unique document number.

If you use a legend in the prefix, use a clear separator between the legend for easy reading, for example using the “/” or “-” characters as shown below.

The image above is an example of filling a prefix using year and month legend, with the separator between legend using the “/” character. The result will look like the image below.

The image below is an example of filling a prefix using year and month legend, with the separator between legend using the “-” character.

The result will look like the image below.

Suffix

A suffix is a set of character that is added after Next Number in the document number. The filling is the same as the prefix, only it is added at the end of the document number. This is an example of filling suffix with date and hour legend.

The result will be like this.

Use subsequences per date_range

Check this option if you want that the document number (Next Number) to be reset at a certain period. For example, reset to 1 again every year. By default the period is one year. As shown below.

If you want that the document number should reset to 1 again each month, you must edit the date range manually like below.

IMPORTANT !!!

If you check the Use subsequences per date_range option, make sure that the prefix or suffix uses the year and month legend. If not, it will generate new transaction with the same document number and it can cause error.

Update

There is a question from Pulung in my bahasa indonesia blog, regarding the use of the (range_year)s prefix or suffix in the comment section. I will answer it here. If we check the Use subsequences per date_range option, a description will appear with the sentence of When subsequences per date range are used, you can prefix variables with ‘range_’ to use the beginning of the range instead of the current date, eg %(range_year)s instead of %(year)s. This means that if we use the %(range_year)s prefix, the year that used as the next document number is the initial year of the sequence range, not the year in which the transaction was made.

For example, I changed the Sales Order sequence on odoo 13 as below. Pay attention to the year and date range in the From field and the To field. In the image below, I created a sequence from January 1, 2019 to December 31, 2020.

Guess what, if I made a Sales Order on November 19, 2020, what year was the document number used for ? 2020 ? Apparently not. The year used is 2019, the year of the From field. Pay attention to this Sales Order.

So as odoo said, if we use the prefix or suffix %(range_xxx)s the date taken as the base of the document number is the start date of the sequence range (from the From field), not the date on which the transaction was made.

Implementation

There are two options, Standard and No Gap. Many people think that if we choose No Gap, the document number will not jump (not in order) if we delete the last transaction then create a new one. The fact is that whether we choose Standard or No Gap the document number will jump if we delete the last transaction then create a new transaction. No Gap only ensure that the document number does not jump if an error occur when generate the document number for a transaction. For example when we make a Sales Order, when we click the Save button and an error occurs, if we choose the Standard option, the Next Number of the related sequence will increase, so when the Sales Order is successfully saved, the transaction will have a skipped or jumped document number compared to the old transaction, whereas if you choose No Gap option it will not happen.

For a test case, download and install this force_sale_error module. Open the Sales Order sequence, make sure the implementation is Standard and write the Next Number in your note, in the image below it is 12.

Create a new Sales Order, when you click the Save button, an error will occur like this. Check the Sales Order sequence again.

You can see that the Next Number has changed. If you click the Save button 4 times and an error appears 4 times, the Next Number will increase by 4 x Step field value too. Now try changing the implementation to No Gap then save Sales Order again. Has the Next Number changed ? It shouldn’t be.

Related Article

2 Replies to “How to Set Up a Sequence or Document Number in Odoo”

  1. Hello There,

    When we want to reset the sequence, which is the better option, to create date range for every month, or use the scheduler to reset the value each month?

Leave a Reply