0
votes

I've created a module in Odoo 10 with the following code to inherit the product.product model and override the existing standard_price field definition to set it as a compute field:

class ProductProduct(models.Model):
    _inherit = 'product.product'

    standard_price = fields.Float(
        'Cost', company_dependent=True,
        digits=dp.get_precision('Product Price'),
        groups="base.group_user",
        compute='_compute_set_standard_price')

    def _compute_set_standard_price(self):
        .....
        # calculation for the value
        .....
        self.standard_price = 121 #this value is an example

The standard_price would be set to 121 because I've override the field definition to a compute field but the standard_price field is set to 0 and don't trigger the compute method. This code in Odoo v8 works fine.

What's the way to override an existing field difinition in a inherited model?

1

1 Answers

0
votes

You didn't use decorator api.depends.

 @api.depends('field_1', 'field_2')
 def _compute_set_standard_price(self):
        .....
        # calculation for the value
        .....
        self.standard_price = 121 #this value is an example

when odoo create a record or update a record it will check for computed field that depends on the field that are passed in the dictionary to recompute the computed field according to the new value. without a trigger odoo will not compute the value