Hi all,
I updated product.template and added a field:
length = fields.Integer("Length", default=0)
I updated product_packaging_views.xml by adding product_id, which is already defined in product module:
<xpath expr="//field[@name='package_carrier_type']" position="after">
<field name="product_id"/>
<field name="company_id" invisible="1"/>
</xpath>
Now I would like to override length in product.packaging when a product is changed. So I wrote an onchange method:
@api.onchange("product_id")
def _onchange_product(self):
if self.product_id:
self.length = self.product_id.length
This method is working fine and if I print the result, the length is changed as expected. Unfortunately it is not changed in the UI and it is not stored.
I have tried to use a different field (which is a duplicate to 'length'):
length_pack = fields.Integer(string="Length Package")And this is working as expected - the value is changed and stored.
Has anyone an idea why I am not able to change the field 'length' in product packaging?
Thanks!
UPDATE
I was wrong stating that 'length_pack' as an Integer field is working.
I found out that this field is only working if it is Float.
Interestingly the onchange method is only working with float but not with integer.
How could that be?!
For this I opened another thread - see https://www.odoo.com/de_DE/forum/hilfe-1/question/odoo-13-override-integer-field-in-onchange-not-working-whereas-float-is-changed-why-175868
The onchange method looks good to me.
Be aware onchange doesn't update the record, you'd need to save the change.
You could also try 'related field', 'computed field' or 'api.depends'.