Reputation: 6728
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.
Upvotes: 1
Views: 1696
Reputation: 176
Check the resequence feature. They moved away from the next sequence by code. Now you generate the first invoice. Select it in the list view and under action you find resequence. Here you can set it to something like 2022-00001 and odoo recognizes the scheme. So from then all next invoices are 2022-00002 and so on.
Upvotes: 0
Reputation: 6728
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()
Upvotes: 1
Reputation: 129
You can change the sequence for invoice from method _get_starting_sequence on account.move
Upvotes: 1