Computed Fields

Computed Fields can be added in Odoo Studio. 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. Dependencies (enter the field names you will be using)
  2. 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: if this is a “base field” you won’t be able to save your changes. This is only available for “custom fields”.

You can add further logic:

for record in self:
if record['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

4 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

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