The reason of computed fields is been used is because it defines a filed whose value is computed rather then simply being read from the database.
Below are the attributes that are specific to computed fields. To define such a field, simply provide a value for the attribute compute and records value. For example you can seen the below code.
upper = fields.Char(compute='_compute_upper',
inverse='_inverse_upper',
search='_search_upper')
@api.depends('Demo')
def _compute_upper(self):
for rec in self:
rec.upper = rec.name.upper() if rec.name else False
def _inverse_upper(self):
for rec in self:
rec.name = rec.upper.lower() if rec.upper else False
def _search_upper(self, operator, value):
if operator == 'like':
operator = 'ilike'
return [('Demo', operator, value)]
self.pname = self.partner_id.name
Note- Acomputed field is not stored to the database.
0 Comment(s)