Hey Cyllo community! Anyone got tips on setting up a compute field? I'm struggling a bit.
Welcome!
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.
This question has been flagged
Here's how you can achieve computed fields that store values in the database, focusing on the efficient use of 'store=True' and '@api.depends'. Computed fields automatically calculate values based on other fields or complex logic, providing dynamic data that updates when dependencies change. 'store=True' is used when we want a field to be saved in the database and not recalculated every time a form renders. Only compute fields with dependencies can be stored; otherwise, they wouldn't calculate properly. '@api.depends' is used to specify which fields the computed field depends on. class SaleOrder(models.Model): _inherit = 'sale.order' total_quantity = fields.Float( compute='_compute_total_quantity', store=True ) @api.depends('order_line.product_uom_qty') def _compute_total_quantity(self): for record in self: record.total_quantity = sum(record.order_line.mapped('product_uom_qty'))