Odoo 15 Studio Book - Python Code

There may be cases where we may have to perform complex operations, in such cases we can execute python code. There are no limitations while using python code.

So In this documentation, we will be creating a new automation to confirm the sale order if the total is < 500. For that first we should Open Studio and then select Automations. Click on the create button to create a new automation.

odoo-studio

Fill all the necessary details and then select Execute Python Code in the Action to do field.

Now we can see how to use Python code space, so here we can write the python code.

The available variables in this python code field are:

  • env: Odoo Environment on which the action is triggered
  • model: Odoo Model of the record on which the action is triggered; is a void recordset
  • record: record on which the action is triggered; may be void
  • records: recordset of all records on which the action is triggered in multi-mode; may be void
  • time, datetime, dateutil, timezone: useful Python libraries
  • float_compare: Odoo function to compare floats based on specific precisions
  • log: log(message, level='info'): logging function to record debug information in ir.logging table
  • UserError: Warning Exception to use with raise
  • Command: x2Many commands namespace
  • To return an action, assign: action = {...}
odoo-studio

In this example, we have added one if condition and called the action_confirm button function.

odoo-studio

And Added domain in order to filter the records. By this way we can add python code in automated action.

whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message