[FIX] product: hide barcode when with dynamic variants

Steps to reproduce:
- Inventory -> Configuration -> [Products] Attributes
- Create new Attribute with 'Variants Creation Mode' set to
'Dynamically' with a few values
- Inventory -> Products -> Products -> New
- Set the new dynamic attribute to the product and save
- If you try to set a barcode, the field will empty itself at each save

When a product is created with 'Dynamic' attributes, the variants will
only be created once the combination of attributes is used. So initially
there is no variant, hence nowhere to set the barcode.
So we avoid letting the attribute being set when there is still no
variant.

Part of task-3218314

Part-of: odoo/odoo#119381
This commit is contained in:
clesgow
2023-05-09 21:04:03 +02:00
parent 0332afc3f5
commit 459760c422
@@ -16,7 +16,7 @@
<field name="name" string="Product Name"/>
<field name="default_code" optional="show"/>
<field name="product_tag_ids" widget="many2many_tags" options="{'color_field': 'color'}" optional="show"/>
<field name="barcode" optional="hide" attrs="{'readonly': [('product_variant_count', '>', 1)]}"/>
<field name="barcode" optional="hide" attrs="{'readonly': [('product_variant_count', '!=', 1)]}"/>
<field name="company_id" options="{'no_create': True}"
groups="base.group_multi_company" optional="hide"/>
<field name="list_price" string="Sales Price" widget='monetary' options="{'currency_field': 'currency_id'}" optional="show" decoration-muted="not sale_ok"/>
@@ -43,7 +43,7 @@
</xpath>
<field name="categ_id" position="after">
<field name="default_code" attrs="{'invisible': [('product_variant_count', '>', 1)]}"/>
<field name="barcode" attrs="{'invisible': [('product_variant_count', '>', 1)]}"/>
<field name="barcode" attrs="{'invisible': ['|', ('product_variant_count', '>', 1), ('product_variant_count', '=', 0)]}"/>
</field>
<div name="button_box" position="inside">