This is similar to creating a BOM but adds some extra options (kinda). The requirement is to create an Analytic Account for each Sales Order – and use it on the order. This replicates the standard functionality in Odoo to automatically create an Analytic Account for each project.
Enable Developer Mode and navigate to Settings / Technical / (Automation) / Automated Actions:

- Model = Sale Order
- Action To Do = Create a new Record
- Trigger Condition = On Creation
- Create/Write Target Model = Analytic Account
- Link using field = Analytic Account (sale.order)
analytic_account_id
Data to Write
Record | Evaluation Type | Value |
---|---|---|
Analytic Account (account.analytic.account) | Python expression | record.name |
Customer (account.analytic.account) | Python expression | record.partner_id.id |
Problem
Unfortunately there’s a problem with this. It isn’t possible to enter the “Link Using Field” because the domain is incorrect in the XML. It’s a bug and it has been logged in GitHub (spoiler alert: they didn’t fix it, but I found a way to do it and I’m not even a Python programmer).
The problem is in the Form View for Server Action (base.view_server_action_form
). This is the domain (from Odoo 12):
domain="[('model_id', '=', model_id),
('relation', '=', crud_model_name),
('ttype', 'in', ['many2one'])]"
- The
model_id
comparison is correct - The
crud_model_name
comparison is wrong- It could be removed (which would allow selection of fields that do not link to the correct Model)
- Or it can be fixed using Odoo Studio, as explained here
- Or you could use the download / upload tool (Model
ir.actions.server
) to enter the correct value.
- In Odoo 13 the type has been expanded to include one2many and many2many, but that is not the issue here (and if line 2 was correct this would be redundant).
You can fix this yourself as explained here
Another technique
This is another way to create a record in another Model (but doesn’t solve the linking problem).

- Model = Sale Order
- Action To Do = Execute Python Code
- Trigger Condition = On Creation
Python Code
env['account.analytic.account'].create({
'name':record.name,
'partner_id':record.partner_id.id
})


What would be the python code to to update a field instead of write a new one. I am trying to update a field in a model that is different than the model which the automated action is writtten.
I am trying to capture the expiration date upon product receipts and write it to the stock.production.lot model into the removal_date field. I have the action tiggering properly but do not know how to get this data into the other table.
LikeLike
Unfortunately I’m not a Python expert, so I don’t know the answer to that!
LikeLike
I see that you got an answer from Ray Carnes on the Odoo Help forum!
Copy expiration date from receipt to removal date in lot model
LikeLike
Hello,
thanks a lot for this.
Using your automated action with the python code as explained in the second part, it creates the analytic account but does fill the analytic account field in my SO with the new created analytic account.
Any idea of what I missed there?
Thanks
LikeLike