Computed Fields

Computed Fields can be added in Odoo Studio or directly (by enabling “Developer” mode and navigating to Settings / Technical / Fields).

They can provide some useful functionality, as shown in the examples below. This does require some Python (mostly quite simple).

The first example is a ‘target’ (sales) price calculated from the cost price. This might be useful so sales staff can check that the sales price is reasonable.

Start by adding a field (type = float)

Select the field you added and then click on “More”

  1. Stored
    • This should be set to FALSE in most cases.
    • If it is set to TRUE, the value of the computed field will only be changed if the value of one of the dependent fields changes, but it does mean that you can use the field in filters, grouping, domain, etc.
  2. Dependencies
    • Enter a list of field names:
      1. Used in the calculation (standard_price)
      2. To trigger recalculation of the computed field (if it is set to “Stored”).
  3. Compute (Python code)
for record in self:
  record['x_studio_target_price'] = record.standard_price * 1.15
  • standard_price is the cost price of the product.

Then save your changes.

Note: we can make this type of change for “custom fields” (whether created manually or by Odoo Studio), but if this is a “base field” you won’t be able to save your changes.

You can add further logic:

for record in self:
if record['standard_price'] !=0:
    record['x_studio_target_price'] = record.standard_price * 1.15

More examples

Simple calculations

for record in self: 
 record['difference'] = close_meter_reading - open_meter_reading
for record in self: 
  record['total_price'] = ltr * unit_price 

More complex usage

  1. Computed Field with count of POS orders
  2. Use Automated Actions to stop users archiving products
  3. Use a computed field to set field attributes
  4. Add tracking using Odoo Studio
  5. Sales Order Delivery Status

5 thoughts on “Computed Fields

  1. Hello,
    I have a field called “x_studio_field_6rsgA” and I want to display in the name of my opportunity. How can I do that ?
    This is my code:
    for record in self:
    record[‘x_studio_field_6rsgA’] = record.name

    Like

  2. As you may have noticed, I’m not a Python programmer! I just use simple Python code to help solve problems. So I don’t know the answer to this. Sorry!

    Like

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s