Hi, you can follow these steps, but before proceeding with the code, you need to create a sequence record.
Go to Settings -> Technical -> Sequences to create the sequence record before implementing the code.
To automate sequence generation for the Purchase model, follow these steps:
- Go to Settings -> Technical -> Automation Rules.
- Create a new rule.
- Set the Model to Purchase Order.
- Set Trigger to On Creation.
- Action: Choose Execute Python Code.
In the Python code block, use the following:
for record in records:
record['field_name'] = env['ir.sequence'].next_by_code('purchase.order.tn')
Replace 'field_name' with the appropriate field where you want to store the sequence.
See: https://www.youtube.com/watch?v=OCLGODE6lU0