Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
2819 Widoki

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. 

Awatar
Odrzuć
Najlepsza odpowiedź

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')




Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
maj 24
1344
1
lut 23
2953
1
wrz 21
3452
0
paź 24
857
1
lis 24
1304