Hello odooers & developers,
Its odoo tips and tricks article, where I would like to share more knowledge about the store true attribute in Compute fields
as an odoo developer, knowing the fundamentals of store attribute in Compute fields behaviour, its Syntax, and how we can use the store true attribute in Compute fields in Odoo is essential.
Explore Store true attribute in Compute fields in odoo:-
The _compute_total_discount method calculates the total discount based on order_line discounts and stores the result in total_discount. The @api.depends('order_line') decorator ensures the method is recomputed only when order_line changes.
Use of Store true attribute in Compute fields
:-
Odoo retrieves the stored value directly from the database, bypassing recalculations. Quicker loading times enhance the user experience, especially in forms and reports that frequently display this field.
Storing computed values increases database size, so use store=True judiciously for frequently accessed fields that are expensive to calculate.
Store true attribute in Compute fields
usage and Syntax:
.py
from odoo import models, fields, api
class SaleOrder(models.Model):
_name = 'sale.order'
total_discount = fields.Float(compute='_compute_total_discount', store=True)
order_line = fields.One2many('sale.order.line', 'order_id', string='Order Lines')
@api.depends('order_line')
def _compute_total_discount(self):
for record in self:
total_discount = sum(line.discount for line in record.order_line)
record.total_discount = total_discount
If you want specific odoo tips or tricks, please let us know the topic of your tips by mail at [email protected]. Then next, we would like to write a tips article based on your suggested topics, too
Devintellecs & team are odoo services providers in the USA and INDIA, so we will try our best to write the best content on your tips request
if you want to check your odoo technical or functional knowledge, then we have prepared the odoo EXam practice test for the odoo technical & functional people
Thanks, & Stay tuned for the following odoo tips soon...
How to add store true attribute in Compute fields ?