From f913eac3121855b772a597eeda1a1f02236fb150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Tue, 26 May 2026 08:59:39 +0200 Subject: [PATCH] [IMP] nfu_ecommerce: Make attribute selection an AND-filter --- nfu_ecommerce/README.rst | 1 + nfu_ecommerce/__manifest__.py | 2 +- nfu_ecommerce/controllers/main.py | 13 +++++++++++++ nfu_ecommerce/models/product_template.py | 9 ++++++++- nfu_ecommerce/readme/HISTORY.rst | 3 ++- nfu_ecommerce/static/description/index.html | 1 + 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/nfu_ecommerce/README.rst b/nfu_ecommerce/README.rst index b39981f..becc0dc 100644 --- a/nfu_ecommerce/README.rst +++ b/nfu_ecommerce/README.rst @@ -57,6 +57,7 @@ Changelog - 16.0.1.4.3: Drop session if SO belongs to another website (Odoo 16 bug) - 16.0.1.4.3: Remove is_published filtering and use job manager only on more than one - 16.0.1.4.5: Make open Packagings more visible +- 16.0.1.5.0: Make attribute selection an AND-filter Bug Tracker =========== diff --git a/nfu_ecommerce/__manifest__.py b/nfu_ecommerce/__manifest__.py index 84d75c4..b0eb085 100644 --- a/nfu_ecommerce/__manifest__.py +++ b/nfu_ecommerce/__manifest__.py @@ -4,7 +4,7 @@ "author": "BAKEUP", "website": "https://www.bakeup.org", "category": "website", - "version": "16.0.1.4.5", + "version": "16.0.1.5.0", "depends": [ "sale_product_configurator", "website_sale", diff --git a/nfu_ecommerce/controllers/main.py b/nfu_ecommerce/controllers/main.py index 10abf6e..6c7cd3b 100644 --- a/nfu_ecommerce/controllers/main.py +++ b/nfu_ecommerce/controllers/main.py @@ -1,5 +1,6 @@ from odoo import fields, http from odoo.http import request +from odoo.osv import expression from odoo.tools import lazy from odoo.addons.website_sale.controllers.main import WebsiteSale @@ -73,6 +74,18 @@ class WebsiteSale(WebsiteSale): new_values["packaging_info"] = packaging_info return new_values + def _get_search_domain( + self, search, category, attrib_values, search_in_description=True + ): + # AND across all selected attribute values instead of OR within same attribute + domain = super()._get_search_domain(search, category, [], search_in_description) + if attrib_values: + attr_domains = [ + [("attribute_line_ids.value_ids", "in", [v[1]])] for v in attrib_values + ] + domain = expression.AND([domain] + attr_domains) + return domain + def _get_search_order(self, post): # is_published is company_dependent and has no DB column, so it cannot # be used in ORDER BY. The shop domain already filters published products, diff --git a/nfu_ecommerce/models/product_template.py b/nfu_ecommerce/models/product_template.py index 52c0789..3934e94 100644 --- a/nfu_ecommerce/models/product_template.py +++ b/nfu_ecommerce/models/product_template.py @@ -20,9 +20,16 @@ class ProductTemplate(models.Model): product.is_published = False def _search_get_detail(self, website, order, options): - search_details = super()._search_get_detail(website, order, options) + # Pass attrib_values as empty so the parent builds no attribute filter, + # then add one condition per value to enforce AND semantics. + attrib_values = options.get("attrib_values") + patched_options = dict(options, attrib_values=[]) if attrib_values else options + search_details = super()._search_get_detail(website, order, patched_options) open_product_ids = options.get("open_product_ids") domain = search_details["base_domain"] if open_product_ids is not None: domain.append([("id", "in", tuple(open_product_ids))]) + if attrib_values: + for value in attrib_values: + domain.append([("attribute_line_ids.value_ids", "in", [value[1]])]) return search_details diff --git a/nfu_ecommerce/readme/HISTORY.rst b/nfu_ecommerce/readme/HISTORY.rst index 0bb71ac..717f7a1 100644 --- a/nfu_ecommerce/readme/HISTORY.rst +++ b/nfu_ecommerce/readme/HISTORY.rst @@ -12,4 +12,5 @@ - 16.0.1.4.2: Catch unescaped float values - 16.0.1.4.3: Drop session if SO belongs to another website (Odoo 16 bug) - 16.0.1.4.3: Remove is_published filtering and use job manager only on more than one -- 16.0.1.4.5: Make open Packagings more visible \ No newline at end of file +- 16.0.1.4.5: Make open Packagings more visible +- 16.0.1.5.0: Make attribute selection an AND-filter \ No newline at end of file diff --git a/nfu_ecommerce/static/description/index.html b/nfu_ecommerce/static/description/index.html index 43bb089..e67deb4 100644 --- a/nfu_ecommerce/static/description/index.html +++ b/nfu_ecommerce/static/description/index.html @@ -413,6 +413,7 @@ adjustes the uom quantitiy
  • 16.0.1.4.3: Drop session if SO belongs to another website (Odoo 16 bug)
  • 16.0.1.4.3: Remove is_published filtering and use job manager only on more than one
  • 16.0.1.4.5: Make open Packagings more visible
  • +
  • 16.0.1.5.0: Make attribute selection an AND-filter