0
votes

I have extended the product.template with following fields:

length = fields.Integer("Length", default=0)
length_float = fields.Float("Float", default=0.0)

Additionally I have extended the product.packaging model with this fields and an onchange method:

product_id_ref = fields.Many2one('product.product', string="Product Reference")
length = fields.Integer('Length')
length_float = fields.Float('Length_Float')

@api.onchange("product_id_ref")
def _onchange_product(self):        
    if self.product_id_ref:
        self.length_float = self.product_id_ref.length_float
        self.length = self.product_id_ref.length

Interestingly the FLOAT field length_float is changed as expected and shown in the view. The INTEGER field is not changed.

Something more suprising is that if I change the order of the onchange method

@api.onchange("product_id_ref")
def _onchange_product(self):        
    if self.product_id_ref:
        self.length = self.product_id_ref.length
        self.length_float = self.product_id_ref.length_float

NO value is changed!

How could that be?? Does anyone have an idea?

Thanks!

1
Do you have one onchange event, it may be another onchange event that cancel the modificationCharif DZ
would you please make sure that product_id_ref holds a value on both length, length_floatkerbrose

1 Answers

0
votes

It came out that the problem was the 'length' field itself. This name leads to problems on the javascript side. Renaming leads to the desired result.