Skip to content

Commit

Permalink
[FIX] website_sale_product_assortment: dont restrict other assortment…
Browse files Browse the repository at this point in the history
… products

* Methods that calculate product availability based on e-commerce assortments are being corrected to make them compatible.
  • Loading branch information
Pablocce committed Oct 28, 2024
1 parent 0041f97 commit a249a20
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 8 additions & 1 deletion website_sale_product_assortment/controllers/website_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ def _get_products_allowed(self):
.search(
[
("is_assortment", "=", True),
("website_availability", "=", "no_show"),
"|",
("website_ids", "=", False),
("website_ids", "=", website_id),
]
)
)
no_restriction_assortments = any(
assortment.website_availability == "no_show" for assortment in assortments
)

assortment_restriction = False
allowed_product_ids = set()

if not no_restriction_assortments:
return allowed_product_ids, assortment_restriction

for assortment in assortments:
if (
# Set active_test to False to allow filtering by partners
Expand Down
17 changes: 12 additions & 5 deletions website_sale_product_assortment/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@ def get_product_assortment_restriction_info(self, product_ids):
.search(
[
("is_assortment", "=", True),
("website_availability", "in", ["no_purchase", "no_show"]),
"|",
("website_ids", "=", website.id),
("website_ids", "=", False),
]
)
)
assortment_dict = {}
partner_assortments = self.env["ir.filters"].sudo()

allowed_product_ids = set()
for assortment in assortments:
if partner & assortment.with_context(active_test=False).all_partner_ids:
allowed_product_ids = assortment.all_product_ids.ids
for product in product_ids:
if product not in allowed_product_ids:
if assortment.website_availability != "no_restriction":
partner_assortments |= assortment
allowed_product_ids.update(assortment.all_product_ids.ids)

assortment_dict = {}
for product in product_ids:
if product not in allowed_product_ids:
for assortment in partner_assortments:
if product not in assortment.all_product_ids.ids:
assortment_dict.setdefault(product, self.env["ir.filters"])
assortment_dict[product] |= assortment
return assortment_dict
Expand Down

0 comments on commit a249a20

Please sign in to comment.