I want to know When and why we use next_by_code()? I have seen it in sales module. In sale.py file, it is written as:
seq_date = fields.Datetime.context_timestamp(self, fields.Datetime.to_datetime(vals['date_order']))
if 'company_id' in vals:
vals['name'] = self.env['ir.sequence'].with_context(force_company=vals['company_id']).next_by_code(
'sale.order', sequence_date=seq_date) or _('New')
Can you guys explain it for me? Thank You
The ir.sequence
contains sequences. You can see them in the Odoo when you go Settings > Technical > Sequences (Debug mode may be needed).
Your code just asks new code for the SO.