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

Commit 6bfc8d7

Browse files
committed
Merge branch '12.0-hide-attribute-no-available-value' into '12.0'
hide attribute if no value is available See merge request pledra/odoo-product-configurator!91
2 parents 9bde9af + 1540d9b commit 6bfc8d7

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

product_configurator/models/product_attribute.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ def onchange_val_custom_field(self):
9595
string='Unit of Measure'
9696
)
9797
image = fields.Binary(string='Image')
98+
hide = fields.Boolean(
99+
string="Invisible",
100+
help="Set in order to make attribute invisible, "
101+
"when there is no available attribute values, in the configuration "
102+
"interface"
103+
)
98104

99105
# TODO prevent the same attribute from being defined twice on the
100106
# attribute lines
@@ -159,6 +165,7 @@ def onchange_attribute(self):
159165
self.required = self.attribute_id.required
160166
self.multi = self.attribute_id.multi
161167
self.custom = self.attribute_id.val_custom
168+
self.hide = self.attribute_id.hide
162169
# TODO: Remove all dependencies pointed towards the attribute being
163170
# changed
164171

@@ -189,6 +196,12 @@ def onchange_values(self):
189196
comodel_name='product.template.attribute.value',
190197
search="_search_product_template_value_ids"
191198
)
199+
hide = fields.Boolean(
200+
string="Invisible",
201+
help="Set in order to make attribute invisible, "
202+
"when there is no available attribute values, in the configuration "
203+
"interface"
204+
)
192205
# TODO: Constraint not allowing introducing dependencies that do not exist
193206
# on the product.template
194207

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)