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

I want to assign my Opportunities an incremental value much like Sales Orders and Delivery Orders.

I have created a Sequence from the Sequences menu in Developer mode:


I have created a custom field on the crm.lead model.

How do I get the value of the field to come from the sequence when a new Opportunity is created?


Awatar
Odrzuć
Najlepsza odpowiedź

You create an Automated Action to listen to record creation and assign the value.

Use the Sequence code to find it and ask it for the next sequence value like this:



If you add the custom Sequence field to the view:


Awatar
Odrzuć

@ray how would this work in v17.

I tried following but its not working

Trigger after creation
Delay 0 hours

Actions to do
Update record
Compute Fuel Log Reference to this python expression

record.env['ir.sequence'].next_by_code('x_fuel_logs')

For some reason, the Form View in 17 has a widget that limits what triggers can be selected, and "on creation" is not available. But it still seems to be there so maybe you can create or update using upload - or use Studio to remove the "improvement".

Removing ON CREATE and ON UPDATE was intentional - read about the change at https://github.com/odoo/odoo/pull/114352 - you can use data import to populate these two options but they are likely to be removed in the future. It appears that ON SAVE is the suggestion option for automations that previously used either of the other two options.

Najlepsza odpowiedź

Hi,

For generating the sequence value for a field in any model,  first create a sequence from the sequence menu under the settings in the debug mode and then we have to create an automated action to assign the sequence value on the record creation.

See this example:  Assign Sequential Value For Field Using Automated Action And Sequence

For creating from the code, see this: How to Add New Sequence in odoo

Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
lip 19
6200
4
paź 24
11476
1
lip 19
3290
0
kwi 19
3151
12
kwi 24
14084