Search code examples
odooodoo-14

Select Sequence to generate name for Invoice


In Accounting -> Invoices

When creating a new invoice and confirming it, the system will generate the next running sequence from Journal's sequence. However, I need to change it so that I have a Many2One field (already created into the model) named sequence to store the sequence to be generated for the name when confirm. The question is I don't know where or what method to inherit and customize in order to achieve such process.

I tried tracking it down to _compute_name method in account.move model but it goes further into _get_last_sequence which is more like a method from a general model that I think I should not be tinkering with it. So, I am stuck here.


Solution

  • I finally ended up solving the issue by overwriting _compute_name method in account.move model.

    @api.depends('posted_before', 'state', 'journal_id', 'date')
        def _compute_name(self):
            if self.state == 'draft':
                self.name = '/'
            elif self.state == 'posted':
                if self.sequence.code:
                    self.name = self.env['ir.sequence'].next_by_code(self.sequence.code)
                else:
                    super(AccountMoveInherit, self)._compute_name()