跳至内容
菜单
此问题已终结
3 回复
13100 查看

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?


形象
丢弃
最佳答案

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:


形象
丢弃

@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.

最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
2
7月 19
5581
4
10月 24
10292
1
7月 19
2984
0
4月 19
2544
12
4月 24
13145