Create analytic accounts for sales orders using Automated Actions

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

RecordEvaluation TypeValue
Analytic Account (account.analytic.account)Python
Customer (account.analytic.account)Python


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

  1. The model_id comparison is correct
  2. 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.
  3. 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


4 thoughts on “Create analytic accounts for sales orders using Automated Actions

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


  2. 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?



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s