I've extended product template by adding a whole new tab / sheet with a lot of other custom fields and logic, which is working fine if you open the product edit from product list
But I've seen that from Sale Order you can open the product form as well, but it loads product.product model instead of product.template and even if all my custom fields are there, all the @onchange / @depends logic doesn't seems to be working
Is there an easy way to make this work without having to copy a lot of custom code to product.product model as well ? But I see that my custom fields are there, only the code update it's not triggered
So here's a basic example of what I have:
class ProductTemplate(models.Model):
_inherit = ['product.template']
my_custom_field_one = fields.Float('Custom One')
my_custom_field_two = fields.Float('Custom Two', compute=_compute_two, store=True)
@api.depends('my_custom_field_one')
def _compute_two(self):
for rec in self:
rec.my_custom_field_two = rec.my_custom_field_one * 2
Then all those two fields are automatically included in 'product.product' model as related fields and they do appear on edit form of the product.product model
If I change my custom field one from product template form then the value of custom field two it's updated automatically
If I change my custom field one from product product form then the value of custom field two it's updated ONLY after save (and not immediately on the form)
Is there an easy way to achieve that ? To update computed field before save the record ?
PS: in my real application, there are dozens of such fields ...
inherit the product.product form and add the fields into it and see
The fields are present on the product.product model as well, but none of the @onchange / @depends methods is triggered (which is doing some computations), those are working only on product.template