Skip to Content
Menu
This question has been flagged

Hello,

How can I create a field using Odoo 17 Studio that auto increases with every new purchase order?

For instance, a purchase order #P0001 can have tracking number TN0001, then the next purchase order TN0002, and so forth. I also need the numbers to be auto generated and to be unique without duplicates. 

Avatar
Discard
Best Answer

First go to Settings -> Technical->Sequences.  Create a new sequence.  It is quite straight forward, well explained in the interface.

The go to Settings->Technical->Automation Rules. Create a new rule. Set the model to Purchase and the trigger = On creation.  Action: Execute Python code.

Python code would look something like this:

for record in records:

    record['your field name'] = env['ir.sequence'].next_by_code('your sequence')




Avatar
Discard
Best Answer

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:

  1. Go to Settings -> Technical -> Automation Rules.
  2. Create a new rule.
  3. Set the Model to Purchase Order.
  4. Set Trigger to On Creation.
  5. 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.

Avatar
Discard
Related Posts Replies Views Activity
1
May 24
224
1
Feb 23
1540
1
Sep 21
1985
0
Sep 24
48
0
Jul 24
106