Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit a32b71a

Browse files
committed
[FIX]merge 12.0 into 12.0-attribute-value-quantity-bizz-shs
2 parents 1b75c63 + 6bfc8d7 commit a32b71a

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

product_configurator/models/product_attribute.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ def onchange_quantity(self):
105105
attr_product_id = fields.Many2one(
106106
comodel_name="product.product", string="Product"
107107
)
108+
hide = fields.Boolean(
109+
string="Invisible",
110+
help="Set in order to make attribute invisible, "
111+
"when there is no available attribute values, in the configuration "
112+
"interface"
113+
)
114+
108115
# TODO prevent the same attribute from being defined twice on the
109116
# attribute lines
110117

@@ -170,6 +177,7 @@ def onchange_attribute(self):
170177
self.custom = self.attribute_id.val_custom
171178
self.quantity = self.attribute_id.quantity
172179
self.attr_product_id = self.attribute_id.attr_product_id
180+
self.hide = self.attribute_id.hide
173181
# TODO: Remove all dependencies pointed towards the attribute being
174182
# changed
175183

@@ -201,6 +209,12 @@ def onchange_values(self):
201209
search="_search_product_template_value_ids"
202210
)
203211
quantity = fields.Boolean(string="Quantity")
212+
hide = fields.Boolean(
213+
string="Invisible",
214+
help="Set in order to make attribute invisible, "
215+
"when there is no available attribute values, in the configuration "
216+
"interface"
217+
)
204218
# TODO: Constraint not allowing introducing dependencies that do not exist
205219
# on the product.template
206220

product_configurator/views/product_attribute_view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<group>
6767
<group>
6868
<!--<field name="type"/> -->
69+
<field name="hide"/>
6970
<field name="required"/>
7071
<field name="multi" attrs="{'readonly': [('val_custom','=',True)]}" force_save="1"/>
7172
<field name="val_custom" attrs="{'readonly': [('multi', '=', True)]}" force_save="1"/>

product_configurator/views/product_view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
context="{'show_attribute': False}"
6464
options="{'no_create': True, 'no_create_edit': True}"
6565
invisible="not context.get('default_config_ok', False)"/>
66+
<field name="hide" invisible="not context.get('default_config_ok', False)"/>
6667
<field name="required" invisible="not context.get('default_config_ok', False)"/>
6768
<field name="multi" invisible="not context.get('default_config_ok', False)" attrs="{'readonly': [('custom','=',True)]}" force_save="1"/>
6869
<field name="custom" invisible="not context.get('default_config_ok', False)" attrs="{'readonly': [('multi','=',True)]}" force_save="1"/>

product_configurator/wizard/product_configurator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ def add_dynamic_fields(self, res, dynamic_fields, wiz):
657657
attrs['readonly'].append(
658658
(dependee_field, 'not in', list(val_ids)))
659659

660+
if not attr_line.custom and attr_line.hide:
661+
attrs['invisible'].append(
662+
(dependee_field, 'not in', list(val_ids)))
663+
660664
if attr_line.required and not attr_line.custom:
661665
attrs['required'].append(
662666
(dependee_field, 'in', list(val_ids)))

website_product_configurator/data/config_form_templates.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,17 @@
277277
<t t-set="custom_field_prefix" t-value="prefixes.get('custom_field_prefix')"/>
278278
<t t-foreach="cfg_step_attribute_line_ids" t-as="line">
279279
<t t-set="custom_value" t-value="custom_value_ids.filtered(lambda x, line=line: x.attribute_id == line.attribute_id)"/>
280-
<t t-set="available_val" t-value="any(val.id in available_value_ids for val in line.value_ids)"/>
281-
<div t-att-class="'attribute_container'">
280+
<t t-set="available_val" t-value="any(val in available_value_ids for val in (line.value_ids.ids + (line.custom and [custom_val_id.id] or [])))"/>
281+
<div t-att-class="'attribute_container' + ((not available_val and line.hide) and ' d-none' or '')">
282282
<label class="control-label" t-esc="line.attribute_id.name" t-att-data-oe-id="line.attribute_id.id"></label>
283283
<select t-att-id="'%s%s' % (field_prefix, line.attribute_id.id)"
284284
t-att-data-oe-id="line.attribute_id.id"
285285
t-att-data-attr-required="line.required"
286286
t-att-multiple="'multiple' if line.multi else None"
287287
t-att-name="'%s%s' % (field_prefix, line.attribute_id.id)"
288288
t-att-class="'form-control config_attribute' + (' required_config_attrib' if (not available_val and line.required and line.custom) or (available_val and line.required) else '') + (' d-none' if not line.value_ids else '')"
289-
t-att-data-old-val-id="(value_ids &amp; line.value_ids) and (value_ids &amp; line.value_ids).ids[0] or ''">
289+
t-att-data-old-val-id="(value_ids &amp; line.value_ids) and (value_ids &amp; line.value_ids).ids[0] or ''"
290+
t-att-data-attr-hide="line.hide">
290291

291292
<!-- t-att-disabled="'disabled' if not available_val_ids and not line.custom else None" -->
292293
<option name=""/>
@@ -337,16 +338,17 @@
337338
<t t-set="custom_field_prefix" t-value="prefixes.get('custom_field_prefix')"/>
338339
<t t-foreach="cfg_step_attribute_line_ids" t-as="line">
339340
<t t-set="custom_value" t-value="custom_value_ids.filtered(lambda x, line=line: x.attribute_id == line.attribute_id)"/>
340-
<t t-set="available_val" t-value="any(val.id in available_value_ids for val in line.value_ids)"/>
341-
<div t-att-class="'attribute_container'">
341+
<t t-set="available_val" t-value="any(val in available_value_ids for val in (line.value_ids.ids + (line.custom and [custom_val_id.id] or [])))"/>
342+
<div t-att-class="'attribute_container' + ((not available_val and line.hide) and ' d-none' or '')">
342343
<label class="control-label" t-esc="line.attribute_id.name" t-att-data-oe-id="line.attribute_id.id"></label>
343344
<fieldset t-att-id="'%s%s' % (field_prefix, line.attribute_id.id)"
344345
t-att-data-oe-id="line.attribute_id.id"
345346
t-att-data-attr-required="line.required"
346347
t-att-name="'%s%s' % (field_prefix, line.attribute_id.id)"
347348
t-att-class="'form-control config_attribute' + (' required_config_attrib' if (not available_val and line.required and line.custom) or (available_val and line.required) else '') + (' d-none' if not line.value_ids else '')"
348349
style="height: unset;"
349-
t-att-data-old-val-id="(value_ids &amp; line.value_ids) and (value_ids &amp; line.value_ids).ids[0] or ''">
350+
t-att-data-old-val-id="(value_ids &amp; line.value_ids) and (value_ids &amp; line.value_ids).ids[0] or ''"
351+
t-att-data-attr-hide="line.hide">
350352
<t t-foreach="line.value_ids" t-as="value">
351353
<div class="radio-card-container">
352354
<div class="info_config_attr_value_radio">

website_product_configurator/static/src/js/config_form.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ odoo.define('website_product_configurator.config_form', function (require) {
181181
) {
182182
$selection.addClass('required_config_attrib');
183183
}
184+
185+
var attr_box = $selection.closest('.attribute_container');
186+
if (!domain[0][2].length && $selection.attr('data-attr-hide') && !attr_box.hasClass('d-none')) {
187+
attr_box.addClass('d-none');
188+
$selection.removeClass('textbox-border-color');
189+
} else if (domain[0][2].length && attr_box.hasClass('d-none')) {
190+
attr_box.removeClass('d-none');
191+
}
184192
});
185193
},
186194

0 commit comments

Comments
 (0)