diff options
| author | Sébastien Theys <seb@odoo.com> | 2019-08-26 08:38:56 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2019-08-26 13:01:13 +0000 |
| commit | 22a11a6f4d0b08a56712fafd0f87a2e7bb5b00ec (patch) | |
| tree | bb88f34b8bc298c31aa3af5c83f1f393a7f108bc /addons/product/views | |
| parent | 191213bca2582ed60c92769a8aa8a17cca0432e6 (diff) | |
[REF] product, *: save product.template.attribute.value on variants
* account, hr_expense, mrp, sale, sale_product_configurator, stock_account,
website_sale, website_sale_comparison
Before this commit, the `product.attribute.value` were stored on the variants.
This required filtering of attribute lines to find the appropriate matching
`product.template.attribute.value` that were used in most of the business code,
such as when computing the `price_extra`.
This also prevented to have multiple attribute lines for the same attribute,
which is needed to handle use cases such as grape varieties for wine products.
This will be done in the following commit.
After this commit, the combination of `product.template.attribute.value` will be
directly stored on the product variant.
Other changes
=============
Add `combination_indices` on product, which allows to quickly find a variant
matching a combination (1 simple indexed equality query as opposed to 1 query
with as many joins as there are attribute lines), and to add an easy
SQL constraint to ensure active combination uniqueness.
Add active field on `product.template.attribute.line` and
`product.template.attribute.value`, with the same behavior as variants:
They become archived if they can't be unlinked. This allows to keep the database
consistent, such as archived variants correctly keeping all their values, sales
order lines keeping their custom and no_variant. This is done with the help of
`ondelete=restrict` on the corresponding m2m fields, and the `unlink` methods
falling back to archiving when `unlink` is restricted.
Part of task-1912579
PR: #32946
Diffstat (limited to 'addons/product/views')
| -rw-r--r-- | addons/product/views/product_attribute_views.xml | 37 | ||||
| -rw-r--r-- | addons/product/views/product_views.xml | 10 |
2 files changed, 31 insertions, 16 deletions
diff --git a/addons/product/views/product_attribute_views.xml b/addons/product/views/product_attribute_views.xml index 3832b95e38e..01a4f6b0dcb 100644 --- a/addons/product/views/product_attribute_views.xml +++ b/addons/product/views/product_attribute_views.xml @@ -103,6 +103,7 @@ <tree string="Attributes" create="0" delete="0"> <field name="attribute_id"/> <field name="name"/> + <field name="ptav_active" optional="hide"/> <field name="price_extra"/> </tree> </field> @@ -114,20 +115,33 @@ <field name="type">form</field> <field name="arch" type="xml"> <form string="Product Attribute" create="0" delete="0"> - <group> - <field name="name" /> - <field name="price_extra" /> - <field name="exclude_for" widget="one2many" mode="tree"> - <tree editable="top"> - <field name="product_tmpl_id" /> - <field name="value_ids" widget="many2many_tags" options="{'no_create': true}" /> - </tree> - </field> - </group> + <sheet> + <group> + <field name="ptav_active" readonly="1" attrs="{'invisible': [('ptav_active', '=', True)]}"/> + <field name="name"/> + <field name="price_extra" /> + <field name="exclude_for" widget="one2many" mode="tree"> + <tree editable="bottom"> + <field name="product_tmpl_id" /> + <field name="value_ids" widget="many2many_tags" options="{'no_create': true}" /> + </tree> + </field> + </group> + </sheet> </form> </field> </record> + <record id="product_template_attribute_value_view_search" model="ir.ui.view"> + <field name="model">product.template.attribute.value</field> + <field name="arch" type="xml"> + <search> + <filter string="Active" name="active" domain="[('ptav_active', '=', True)]"/> + <filter string="Inactive" name="inactive" domain="[('ptav_active', '=', False)]"/> + </search> + </field> + </record> + <record id="product_attribute_value_action" model="ir.actions.act_window"> <field name="name">Product Variant Values</field> <field name="res_model">product.template.attribute.value</field> @@ -138,7 +152,8 @@ (0, 0, {'view_mode': 'tree', 'view_id': ref('product.product_template_attribute_value_view_tree')}), (0, 0, {'view_mode': 'form', 'view_id': ref('product.product_template_attribute_value_view_form')})]" /> <field name="context">{ - 'default_product_tmpl_id': active_id + 'default_product_tmpl_id': active_id, + 'search_default_active': 1, }</field> </record> diff --git a/addons/product/views/product_views.xml b/addons/product/views/product_views.xml index fcd295e328b..525424c79c6 100644 --- a/addons/product/views/product_views.xml +++ b/addons/product/views/product_views.xml @@ -184,7 +184,7 @@ <field name="name" string="Product" filter_domain="['|', '|', ('default_code', 'ilike', self), ('name', 'ilike', self), ('barcode', 'ilike', self)]"/> </field> <field name="attribute_line_ids" position="replace"> - <field name="attribute_value_ids" groups="product.group_product_variant"/> + <field name="product_template_attribute_value_ids" groups="product.group_product_variant"/> <field name="product_tmpl_id" string="Product Template"/> </field> </field> @@ -222,7 +222,7 @@ <div class="oe_title"> <label class="oe_edit_only" for="name" string="Product Name"/> <h1><field name="name" readonly="1" placeholder="e.g. Odoo Enterprise Subscription"/></h1> - <field name="attribute_value_ids" widget="many2many_tags" readonly="1"/> + <field name="product_template_attribute_value_ids" widget="many2many_tags" readonly="1"/> <p> <span>All general settings about this product are managed on</span> <button name="open_product_template" type="object" string="the product template." class="oe_link oe_link_product pl-0 ml-1 mb-1"/> @@ -300,7 +300,7 @@ <field name="default_code" optional="show"/> <field name="barcode" optional="hide"/> <field name="name"/> - <field name="attribute_value_ids" widget="many2many_tags" groups="product.group_product_variant"/> + <field name="product_template_attribute_value_ids" widget="many2many_tags" groups="product.group_product_variant"/> <field name="company_id" groups="base.group_multi_company" optional="hide"/> <field name="lst_price" optional="show" string="Sales Price"/> <field name="standard_price" optional="show"/> @@ -342,7 +342,7 @@ <field name="product_tmpl_id" class="oe_inline" readonly="1" invisible="1" attrs="{'required': [('id', '!=', False)]}"/> </field> <xpath expr="//div[hasclass('oe_title')]" position="inside"> - <field name="attribute_value_ids" widget="many2many_tags" readonly="1" + <field name="product_template_attribute_value_ids" widget="many2many_tags" readonly="1" groups="product.group_product_variant"/> </xpath> </field> @@ -369,7 +369,7 @@ <small t-if="record.default_code.value">[<field name="default_code"/>]</small> </strong> <div class="o_kanban_tags_section"> - <field name="attribute_value_ids" groups="product.group_product_variant"/> + <field name="product_template_attribute_value_ids" groups="product.group_product_variant"/> </div> <ul> <li><strong>Price: <field name="lst_price"></field></strong></li> |
