Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
2847 Представления

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. 

Аватар
Отменить
Лучший ответ

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




Аватар
Отменить
Лучший ответ

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.

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
мая 24
1372
1
февр. 23
2986
1
сент. 21
3502
0
окт. 24
897
1
нояб. 24
1315