Skip to Content
Menu
This question has been flagged
4 Replies
7032 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 ?

 

 

 

Avatar
Discard
Best Answer

Hi,

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()
        else:
            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

 

 

Avatar
Discard

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..

Best Answer

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()
        else:
            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

Avatar
Discard
Best Answer

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

Avatar
Discard