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”
- Dependencies (enter the field names you will be using)
- Compute (Python code)
for record in self: record['x_studio_target_price'] = record.standard_price * 1.15
standard_priceis 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
for record in self: record['difference'] = close_meter_reading - open_meter_reading
for record in self: record['total_price'] = ltr * unit_price