[FIX] sale_product_configurator: do not show unavailable values

Values removed from the product should be hidden instead of being shown
as forbidden values.

opw-3434706

closes odoo/odoo#131145

X-original-commit: 9a581c46dca46ad44957cf1a47748f0c56ad07ca
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2023-08-08 20:07:22 +02:00
parent be20951c05
commit 58b90963ba
3 changed files with 59 additions and 9 deletions
@@ -267,15 +267,18 @@ class ProductConfiguratorController(Controller):
attribute_lines=[dict(
id=ptal.id,
attribute=dict(**ptal.attribute_id.read(['id', 'name', 'display_type'])[0]),
attribute_values=[dict(
**ptav.read(['name', 'html_color', 'is_custom'])[0],
price_extra=ptav.currency_id._convert(
ptav.price_extra,
currency,
request.env.company,
datetime.fromisoformat(so_date).date(),
),
) for ptav in ptal.product_template_value_ids],
attribute_values=[
dict(
**ptav.read(['name', 'html_color', 'is_custom'])[0],
price_extra=ptav.currency_id._convert(
ptav.price_extra,
currency,
request.env.company,
datetime.fromisoformat(so_date).date(),
),
) for ptav in ptal.product_template_value_ids
if ptav.ptav_active
],
selected_attribute_value_id=combination.filtered(
lambda c: ptal in c.attribute_line_id
).id,
@@ -0,0 +1 @@
from . import test_product_configurator_data
@@ -0,0 +1,46 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.fields import Command
from odoo.tests import HttpCase, tagged
from odoo.addons.product.tests.common import ProductVariantsCommon
from odoo.addons.sale.tests.common import SaleCommon
@tagged('post_install', '-at_install')
class TestProductConfiguratorData(HttpCase, ProductVariantsCommon, SaleCommon):
def test_dropped_attribute_isnt_shown(self):
self.assertEqual(len(self.product_template_sofa.product_variant_ids), 3)
self.empty_order.order_line = [
Command.create({
'product_id': product.id
})
for product in self.product_template_sofa.product_variant_ids
]
self.empty_order.action_confirm()
self.product_template_sofa.attribute_line_ids.value_ids -= self.color_attribute_red
self.assertEqual(len(self.product_template_sofa.product_variant_ids.filtered('active')), 2)
self.authenticate('demo', 'demo')
base_url = self.product_template_sofa.get_base_url()
response = self.opener.post(
url=base_url + '/sale_product_configurator/get_values',
json={
'params': dict(
product_template_id=self.product_template_sofa.id,
quantity=1.0,
currency_id=1,
so_date=str(self.env.cr.now()),
product_uom_id=None,
company_id=None,
pricelist_id=None,
ptav_ids=None,
only_main_product=False,
),
}
)
result = response.json()['result']
# Make sure the inactive ptav was removed from the loaded attributes
self.assertEqual(len(result['products'][0]['attribute_lines'][0]['attribute_values']), 2)