Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
3725 Visualizações

Hi all,

In v16.4 you could configure a server action/automated action to create a new record in another model

https://www.odoo.com/documentation/master/applications/productivity/studio/automated_actions.html#create-a-new-record

Within the automated action you could add data to write (you could add field data to be saved in the target model.)


In v17 i can't find that functionality anymore (the data to write) although it is still in the documentation.

How should we proceed? 

Should we select python code and do it via python code?

or is there another thing i should know ?


thx for sharing your info!


kr

roeland

Avatar
Cancelar

Yes, the functionality has been lost in v17 as per this change in GitHub: https://github.com/odoo/odoo/pull/114352

You can create a record but you can't specify any fields. It's possible to do some of it in Python, but ironically this so-called simplification has made it more difficult.

https://www.odoo.com/forum/help-1/limitations-in-automation-rules-odoo-17-244783

a feature which encourages to learn Python or?

The improvement introduced regressions. Models created with Studio are named x_name. When the action is trying to create that record, it tries to fill name, which does not exist. Thus, fails.

Hi Moritz - I'm not sure this is a specific issue with models created with Studio. If you hardcode the name of the new record in the Automation Rules that will work whether it's a Studio model or not. The problem is how to set a value for each record, and the solution below does that if you write Python code (in which case you would need to set a value for x_name and any other mandatory fields on your new model)

Autor Melhor resposta

Hi all,


I think I have found the solution:

Create a server action with the type "Execute code".

Then use the following code:


 env['targetmodelname'].create({

         'field1':record.name,                          =>insert python expression

         'field2':25,                                          =>insert value (integer, float)

         'field3':record.id                                =>insert python expression (linked field)

​'field4':"characters"                          =>insert value (char)

 })

 

env['targetmodelname'].create({
         'field1':record.name,
         'field2':25,
         'field3':record.id,
	 'field4':"characters"
 })
Avatar
Cancelar

Indeed, this is possible, but so-called "simplification" has made it more difficult.

Melhor resposta

Hi,

In odoo17 you can create another record by using the automation rule by following the below steps

1)Open the Automation rule from settings ->Technical ->Automation -> Automation Rule


2) Create a new record by adding the fields


You can change the field values according to your needs

3) click on the Add an Action button from the Action To Do page Then a pop-up will appear. from that select Create Record option


Then you can fill in the values in the action details area.


Hope it helps


Avatar
Cancelar

You can create a record, but you cannot set any fields in the target model (as per my earlier comment)

Publicações relacionadas Respostas Visualizações Atividade
2
jul. 24
2886
2
abr. 25
2773
2
jan. 25
2587
2
out. 24
2478
2
abr. 24
1444