[FIX] sale: correct disabling of attr. for archived variants

Current behaviour:
In the context that a variant is being archived after the removal of
one of it's attribute lines, on the e-commerce product's page of
said product some of the attribute values are disabled because they
were part of the archived variant.

Expected behaviour:
Archiving a variant due to removal of an attribute line shouldn't
disable the selection of the other attributes on the e-commerce
product's page of the product, since the variant can never be
reconstituted (the current selection of attributes lines is `X-1`,
where `X` is the number of attribute lines of the archived variant).

Steps to reproduce:
- Install eCommerce,
- Create a product with 2 attribute lines and add values A1,A2 and
  B1,B2 respectively, 4 variants should be created (cross-product).
- Go on the e-commerce product's page of the product, add the
  variant A2,B1 to the cart
- Go in the backend, delete attribute line (B1,B2), from the product
  template
- Go back on the e-commerce product's page, the option with A2 is
  disabled.

Reason for the problem:
When deleting an attribute line from a `product.template`, if one of
the variant is being used somewhere (in our case as a `sale.order.
line` of the cart), it is archived instead of deleted. This means
that when loading the page of the product with send the attribute
values of the archived products, so we can disable the selection of
the attributes that would make the archived variant. Since A2 is
part of the variant A2,B1 that was archived, we disable the
selection for A2, without taking into account that we don't have the
same number of attributes than the archived variant and it is
impossible to make the archived variant from the e-commerce
product's page.

Fix:
Restrain the condition that checks for which attributes to disable.
We make sure that we have *any* common part of the selection to the
archived variant, and we also make sure the count of the attributes
for the product is the same as the archived variant we are checking
against.

Affected versions:
- 16.0
- saas-16.1
- saas-16.2
- saas-16.3
- master

opw-3329225

closes odoo/odoo#124536

X-original-commit: 411441861a3242fddce5ffd02b09cbc5556aef90
Signed-off-by: Piryns Victor (pivi) <pivi@odoo.com>
This commit is contained in:
Victor Piryns (pivi)
2023-06-12 08:16:30 +02:00
parent c6079e8946
commit 3d01757aba
@@ -408,7 +408,11 @@ var VariantMixin = {
if (combinationData.archived_combinations) {
combinationData.archived_combinations.forEach((excludedCombination) => {
const ptavCommon = excludedCombination.filter((ptav) => combination.includes(ptav));
if (ptavCommon.length === combination.length) {
if (
!!ptavCommon
&& (combination.length === excludedCombination.length)
&& (ptavCommon.length === combination.length)
) {
// Selected combination is archived, all attributes must be disabled from each other
combination.forEach((ptav) => {
combination.forEach((ptavOther) => {
@@ -423,7 +427,11 @@ var VariantMixin = {
);
})
})
} else if (ptavCommon.length === (combination.length - 1)) {
} else if (
!!ptavCommon
&& (combination.length === excludedCombination.length)
&& (ptavCommon.length === (combination.length - 1))
) {
// In this case we only need to disable the remaining ptav
const disabledPtav = excludedCombination.find((ptav) => !combination.includes(ptav));
excludedCombination.forEach((ptav) => {