Odoo Help


Customized the invoice number to include the month of the invoice date

on 8/1/14, 7:29 AM 1,938 views

I would like to customize the invoice number.

I found the tips to go in the following menu:

  1. login as admin Go to Settings / Users
  2. Choose "admin" in the first column of user list
  3. switch to form view and click on "Edit"
  4. On tab "access rights" activate "Technical Features"
  5. Save & Click on the company logo to reload menus
  6. Go to menu Settings / Technical / Sequences & Identifiers / Sequences
  7. Choose "Account Default Sales Journal" and switch to form view
  8. Now you have to configure the sequence details to your example.

(from the link here: https://www.odoo.com/forum/help-1/question/how-do-i-customize-next-invoice-number-2779)

My issue is that the suffix %(month)s  is the current month, and not necessarly the month of the invoice date.

For example if we are the 01/08 and that I would like to write an invoice of 31/07, i will get "08" in the invoice number in place of "07". Is there a legend for the month of the invoice date in place of the current month ?




On 8/12/14, 9:19 AM


This can be done by editing the _next function in ir.sequence object.

First add 'date' in context of any function where you calling this sequence. eg: contex['date'] = invoice_date. Then modify the _next function like this. Need to add only two lines. These lines are highlighted.

    def _next(self, cr, uid, seq_ids, context=None):
        if not seq_ids:
            return False
        if context is None:
            context = {}
        force_company = context.get('force_company')
        if not force_company:
            force_company = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
        sequences = self.read(cr, uid, seq_ids, ['company_id','implementation','number_next','prefix','suffix','padding'])
        preferred_sequences = [s for s in sequences if s['company_id'] and s['company_id'][0] == force_company ]
        seq = preferred_sequences[0] if preferred_sequences else sequences[0]
        if seq['implementation'] == 'standard':
            cr.execute("SELECT nextval('ir_sequence_%03d')" % seq['id'])
            seq['number_next'] = cr.fetchone()
            cr.execute("SELECT number_next FROM ir_sequence WHERE id=%s FOR UPDATE NOWAIT", (seq['id'],))
            cr.execute("UPDATE ir_sequence SET number_next=number_next+number_increment WHERE id=%s ", (seq['id'],))
        d = self._interpolation_dict()

        if 'date' in context:
            d['month'] = str(context['date'])[5:7]

        interpolated_prefix = self._interpolate(seq['prefix'], d)
        interpolated_suffix = self._interpolate(seq['suffix'], d)
        return interpolated_prefix + '%%0%sd' % seq['padding'] % seq['number_next'] + interpolated_suffix



I tried but it's not working. I created today (15/09/2014)an invoice for the 01/10/2014. I was waiting -10 but it was -09 (because the current month is September) so ithe month of the invoice is not followed by well the current month..

Renaud Dubois
on 9/15/14, 3:09 PM
odoo.ma by IBS Group
On 8/10/14, 2:14 PM

You can't achieve this by configuration, some development is required.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 8/1/14, 7:29 AM
Seen: 1938 times
Last updated: 12/13/15, 4:46 AM