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

Commit 46cda27

Browse files
committed
[FIX]add field invisible to hide attribute when boolean ticked and no value is available
1 parent 9ea1166 commit 46cda27

File tree

7 files changed

+56
-5
lines changed

7 files changed

+56
-5
lines changed

website_product_configurator/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'data/config_form_templates.xml',
1616
'data/cron.xml',
1717
'views/assets.xml',
18+
"views/product_attribute_view.xml",
1819
'views/product_view.xml',
1920
'views/templates.xml',
2021
'views/res_config_settings_view.xml',

website_product_configurator/data/config_form_templates.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,16 @@
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)"/>
280280
<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 ' d-none' or '')">
281+
<div t-att-class="'attribute_container' + ((not available_val and line.invisible) 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-invisible="line.invisible">
290291

291292
<!-- t-att-disabled="'disabled' if not available_val_ids and not line.custom else None" -->
292293
<option name=""/>
@@ -338,15 +339,16 @@
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)"/>
340341
<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 [])))"/>
341-
<div t-att-class="'attribute_container' + ((not available_val) and ' d-none' or '')">
342+
<div t-att-class="'attribute_container' + ((not available_val and line.invisible) 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-invisible="line.invisible">
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/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from . import res_config_settings
33
from . import sale_order
44
from . import product_template
5+
from . import product_attribute
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from odoo import api, fields, models
2+
3+
4+
class ProductAttribute(models.Model):
5+
_inherit = 'product.attribute'
6+
7+
invisible = fields.Boolean(
8+
string="Invisible",
9+
help="Set in order to make attribute invisible, "
10+
"when there is no available attribute values, in the configuration "
11+
"interface"
12+
)
13+
14+
15+
class ProductAttributeLine(models.Model):
16+
_inherit = "product.template.attribute.line"
17+
18+
invisible = fields.Boolean(
19+
string="Invisible",
20+
help="Set in order to make attribute invisible, "
21+
"when there is no available attribute values, in the configuration "
22+
"interface"
23+
)
24+
25+
@api.onchange("attribute_id")
26+
def onchange_attribute(self):
27+
res = super(ProductAttributeLine, self).onchange_attribute()
28+
self.invisible = self.attribute_id.invisible
29+
return res

website_product_configurator/static/src/js/config_form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ odoo.define('website_product_configurator.config_form', function (require) {
183183
}
184184

185185
var attr_box = $selection.closest('.attribute_container');
186-
if (!domain[0][2].length && !attr_box.hasClass('d-none')) {
186+
if (!domain[0][2].length && $selection.attr('data-attr-invisible') && !attr_box.hasClass('d-none')) {
187187
attr_box.addClass('d-none');
188188
$selection.removeClass('textbox-border-color');
189189
} else if (domain[0][2].length && attr_box.hasClass('d-none')) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<record model="ir.ui.view" id="product_attribute_form_view_configurator">
5+
<field name="name">product.attribute.form.view.configurator</field>
6+
<field name="model">product.attribute</field>
7+
<field name="inherit_id" ref="product_configurator.product_attribute_form_view"/>
8+
<field name="arch" type="xml">
9+
<xpath expr="//field[@name='required']" position="before">
10+
<field name="invisible"/>
11+
</xpath>
12+
</field>
13+
</record>
14+
15+
</odoo>

website_product_configurator/views/product_view.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<xpath expr="//notebook/page[@name='configurator']//field[@name='config_step_line_ids']//tree//field[@name='attribute_line_ids']" position="after">
1111
<field name="website_tmpl_id"/>
1212
</xpath>
13+
<xpath expr="//field[@name='attribute_line_ids']//tree//field[@name='required']" position="before">
14+
<field name="invisible" invisible="not context.get('default_config_ok', False)"/>
15+
</xpath>
1316
</field>
1417
</record>
1518

0 commit comments

Comments
 (0)