Skip to content

Commit 9ad7a58

Browse files
eduezerouali-tecnativaAlexgars73
authored andcommitted
[IMP] website_sale_product_brand: merged website_sale_filter_product_brand
1 parent 961d1c2 commit 9ad7a58

59 files changed

Lines changed: 1485 additions & 170 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

website_sale_product_brand/README.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
15
==================================
26
Product Brand Filtering in Website
37
==================================
@@ -7,13 +11,13 @@ Product Brand Filtering in Website
711
!! This file is generated by oca-gen-addon-readme !!
812
!! changes will be overwritten. !!
913
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:b9e4d313bc036276fc48d47dc2feadb3931434c3cf8897951620af315ddeb02e
14+
!! source digest: sha256:2866648306719d101a1a7e53c7797ebb0c3f171e68905bf0f627ed69f5f020f4
1115
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1216
1317
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1418
:target: https://odoo-community.org/page/development-status
1519
:alt: Beta
16-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
1721
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1822
:alt: License: AGPL-3
1923
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github

website_sale_product_brand/__manifest__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"data/website_menu.xml",
1717
"views/product_brand.xml",
1818
"views/product_brand_views.xml",
19+
"views/templates.xml",
1920
],
2021
"demo": [
2122
"demo/product_brand_demo.xml",
@@ -27,6 +28,7 @@
2728
],
2829
"web.assets_tests": [
2930
"/website_sale_product_brand/static/src/js/tour.esm.js",
31+
"/website_sale_product_brand/static/src/js/test_website_sale_filter_brand.esm.js",
3032
],
3133
},
3234
"installable": True,

website_sale_product_brand/controllers/main.py

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,68 @@
99

1010

1111
class WebsiteSale(WebsiteSale):
12+
def _get_shop_domain(
13+
self, search, category, attrib_values, search_in_description=True
14+
):
15+
domain = super()._get_shop_domain(
16+
search=search,
17+
category=category,
18+
attrib_values=attrib_values,
19+
search_in_description=search_in_description,
20+
)
21+
# add selected brands to product search domain
22+
brands_list = self._get_brand_ids(request.httprequest.args)
23+
return self._update_domain(brands_list, domain)
24+
25+
def _update_domain(self, brands_list, domain):
26+
selected_brand_ids = [int(brand) for brand in brands_list]
27+
if brands_list:
28+
for leaf in domain:
29+
if leaf[0] == "product_brand_id":
30+
domain.remove(leaf)
31+
domain += [("product_brand_id", "in", selected_brand_ids)]
32+
return domain
33+
34+
def _get_brand_ids(self, req):
35+
return req.getlist("brand") or req.getlist("brand_ids") or []
36+
37+
def _build_brands_list(
38+
self,
39+
selected_brand_ids,
40+
search=None,
41+
products=None,
42+
search_products=None,
43+
category=None,
44+
):
45+
domain = []
46+
if not products:
47+
domain = [("id", "in", selected_brand_ids)]
48+
elif search or category:
49+
domain = [("product_ids", "in", search_products.ids)]
50+
return (
51+
request.env["product.brand"]
52+
.search(domain)
53+
.filtered(lambda x: x.products_count > 0)
54+
)
55+
56+
def _get_shop_domain_no_brands(
57+
self, search, category, attrib_values, search_in_description
58+
):
59+
domain = super()._get_shop_domain(
60+
search=search,
61+
category=category,
62+
attrib_values=attrib_values,
63+
search_in_description=search_in_description,
64+
)
65+
return domain
66+
67+
def _remove_extra_brands(self, brands, search_products, attrib_values):
68+
if attrib_values:
69+
search_product_brands = search_products.mapped("product_brand_id")
70+
brands = brands.filtered(lambda b: b.id in search_product_brands.ids)
71+
# sort brands by name
72+
return brands.sorted(key=lambda brand: brand.name)
73+
1274
def _get_search_options(
1375
self,
1476
category=None,
@@ -31,10 +93,10 @@ def _get_search_options(
3193
res["brand"] = request.context.get("brand_id")
3294
return res
3395

34-
def _get_search_domain(
96+
def _get_shop_domain(
3597
self, search, category, attrib_values, search_in_description=True
3698
):
37-
domain = super()._get_search_domain(
99+
domain = super()._get_shop_domain(
38100
search, category, attrib_values, search_in_description=search_in_description
39101
)
40102
if "brand_id" in request.context:
@@ -71,7 +133,7 @@ def shop(
71133
context = dict(request.context)
72134
context.setdefault("brand_id", int(brand))
73135
request.update_context(**context)
74-
return super().shop(
136+
res = super().shop(
75137
page=page,
76138
category=category,
77139
search=search,
@@ -81,6 +143,60 @@ def shop(
81143
brand=brand,
82144
**post,
83145
)
146+
# parse selected attributes
147+
attrib_list = request.httprequest.args.getlist("attribute_value")
148+
attrib_values = res.qcontext["attrib_values"]
149+
if attrib_list:
150+
post["attribute_value"] = attrib_list
151+
# get filtered products
152+
products = res.qcontext["products"]
153+
domain = self._get_shop_domain_no_brands(
154+
search, category, attrib_values, search_in_description=False
155+
)
156+
search_products = request.env["product.template"].search(domain)
157+
# build brands list
158+
brands_list = self._get_brand_ids(request.httprequest.args)
159+
selected_brand_ids = [int(brand) for brand in brands_list]
160+
brands = self._build_brands_list(
161+
selected_brand_ids, search, products, search_products, category
162+
)
163+
brands = self._remove_extra_brands(brands, search_products, attrib_values)
164+
# use search() domain instead of mapped() for better performance:
165+
# will basically search for product's related attribute values
166+
attrib_valid_ids = (
167+
request.env["product.attribute.value"]
168+
.search(
169+
[
170+
"&",
171+
(
172+
"pav_attribute_line_ids.product_tmpl_id",
173+
"in",
174+
search_products._ids,
175+
),
176+
("pav_attribute_line_ids.value_ids", "!=", False),
177+
]
178+
)
179+
.ids
180+
)
181+
# keep selected brands in URL
182+
keep = QueryURL(
183+
"/shop",
184+
**self._shop_get_query_url_kwargs(
185+
category and int(category), search, min_price, max_price, **post
186+
),
187+
brand=brands_list,
188+
brand_ids=selected_brand_ids,
189+
)
190+
# assign values for usage in qweb
191+
res.qcontext.update(
192+
{
193+
"brands": brands,
194+
"selected_brand_ids": selected_brand_ids,
195+
"attr_valid": attrib_valid_ids,
196+
"keep": keep,
197+
}
198+
)
199+
return res
84200

85201
# Method to get the brands.
86202
@http.route(["/page/product_brands"], type="http", auth="public", website=True)

website_sale_product_brand/i18n/ar.po

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,41 @@ msgstr ""
99
"Project-Id-Version: Odoo Server 9.0c\n"
1010
"Report-Msgid-Bugs-To: \n"
1111
"POT-Creation-Date: 2016-11-29 01:20+0000\n"
12-
"PO-Revision-Date: 2016-11-29 01:20+0000\n"
13-
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2016\n"
12+
"PO-Revision-Date: 2026-02-25 07:30+0000\n"
13+
"Last-Translator: Anonymous <noreply@weblate.org>\n"
1414
"Language-Team: Arabic (https://www.transifex.com/oca/teams/23907/ar/)\n"
1515
"Language: ar\n"
1616
"MIME-Version: 1.0\n"
1717
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: \n"
1919
"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 "
20-
"&& n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n"
20+
"&& n%100<=10 ? 3 : n%100>=11 ? 4 : 5;\n"
21+
"X-Generator: Weblate 5.15.2\n"
22+
23+
#. module: website_sale_product_brand
24+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
25+
msgid "<b>Brand</b>"
26+
msgstr ""
27+
28+
#. module: website_sale_product_brand
29+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
30+
msgid ""
31+
"<small class=\"mx-auto\">\n"
32+
" <b>Clear Filters</b>\n"
33+
" </small>\n"
34+
" <i class=\"oi oi-close\" role=\"presentation\"/>"
35+
msgstr ""
2136

2237
#. module: website_sale_product_brand
2338
#: model:ir.model.fields,field_description:website_sale_product_brand.field_product_brand__can_publish
2439
msgid "Can Publish"
2540
msgstr ""
2641

42+
#. module: website_sale_product_brand
43+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
44+
msgid "Clear Filters"
45+
msgstr ""
46+
2747
#. module: website_sale_product_brand
2848
#: model:ir.model.fields,field_description:website_sale_product_brand.field_product_brand__is_published
2949
msgid "Is Published"

website_sale_product_brand/i18n/bg.po

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,40 @@ msgstr ""
99
"Project-Id-Version: Odoo Server 9.0c\n"
1010
"Report-Msgid-Bugs-To: \n"
1111
"POT-Creation-Date: 2016-11-29 01:20+0000\n"
12-
"PO-Revision-Date: 2016-11-29 01:20+0000\n"
13-
"Last-Translator: Kaloyan Naumov <kaloyan@lumnus.net>, 2016\n"
12+
"PO-Revision-Date: 2026-02-25 07:28+0000\n"
13+
"Last-Translator: Anonymous <noreply@weblate.org>\n"
1414
"Language-Team: Bulgarian (https://www.transifex.com/oca/teams/23907/bg/)\n"
1515
"Language: bg\n"
1616
"MIME-Version: 1.0\n"
1717
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: \n"
19-
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
19+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
20+
"X-Generator: Weblate 5.15.2\n"
21+
22+
#. module: website_sale_product_brand
23+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
24+
msgid "<b>Brand</b>"
25+
msgstr ""
26+
27+
#. module: website_sale_product_brand
28+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
29+
msgid ""
30+
"<small class=\"mx-auto\">\n"
31+
" <b>Clear Filters</b>\n"
32+
" </small>\n"
33+
" <i class=\"oi oi-close\" role=\"presentation\"/>"
34+
msgstr ""
2035

2136
#. module: website_sale_product_brand
2237
#: model:ir.model.fields,field_description:website_sale_product_brand.field_product_brand__can_publish
2338
msgid "Can Publish"
2439
msgstr ""
2540

41+
#. module: website_sale_product_brand
42+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
43+
msgid "Clear Filters"
44+
msgstr ""
45+
2646
#. module: website_sale_product_brand
2747
#: model:ir.model.fields,field_description:website_sale_product_brand.field_product_brand__is_published
2848
msgid "Is Published"

website_sale_product_brand/i18n/bs.po

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,41 @@ msgstr ""
99
"Project-Id-Version: Odoo Server 9.0c\n"
1010
"Report-Msgid-Bugs-To: \n"
1111
"POT-Creation-Date: 2016-11-29 01:20+0000\n"
12-
"PO-Revision-Date: 2016-11-29 01:20+0000\n"
13-
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2016\n"
12+
"PO-Revision-Date: 2026-02-25 07:27+0000\n"
13+
"Last-Translator: Anonymous <noreply@weblate.org>\n"
1414
"Language-Team: Bosnian (https://www.transifex.com/oca/teams/23907/bs/)\n"
1515
"Language: bs\n"
1616
"MIME-Version: 1.0\n"
1717
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: \n"
19-
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
20-
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
19+
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
20+
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
21+
"X-Generator: Weblate 5.15.2\n"
22+
23+
#. module: website_sale_product_brand
24+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
25+
msgid "<b>Brand</b>"
26+
msgstr ""
27+
28+
#. module: website_sale_product_brand
29+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
30+
msgid ""
31+
"<small class=\"mx-auto\">\n"
32+
" <b>Clear Filters</b>\n"
33+
" </small>\n"
34+
" <i class=\"oi oi-close\" role=\"presentation\"/>"
35+
msgstr ""
2136

2237
#. module: website_sale_product_brand
2338
#: model:ir.model.fields,field_description:website_sale_product_brand.field_product_brand__can_publish
2439
msgid "Can Publish"
2540
msgstr ""
2641

42+
#. module: website_sale_product_brand
43+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
44+
msgid "Clear Filters"
45+
msgstr ""
46+
2747
#. module: website_sale_product_brand
2848
#: model:ir.model.fields,field_description:website_sale_product_brand.field_product_brand__is_published
2949
msgid "Is Published"

website_sale_product_brand/i18n/ca.po

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,40 @@ msgstr ""
1010
"Project-Id-Version: Odoo Server 9.0c\n"
1111
"Report-Msgid-Bugs-To: \n"
1212
"POT-Creation-Date: 2017-06-09 03:07+0000\n"
13-
"PO-Revision-Date: 2021-02-25 17:45+0000\n"
14-
"Last-Translator: claudiagn <claudia.gargallo@qubiq.es>\n"
13+
"PO-Revision-Date: 2026-02-25 07:30+0000\n"
14+
"Last-Translator: Anonymous <noreply@weblate.org>\n"
1515
"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n"
1616
"Language: ca\n"
1717
"MIME-Version: 1.0\n"
1818
"Content-Type: text/plain; charset=UTF-8\n"
1919
"Content-Transfer-Encoding: \n"
2020
"Plural-Forms: nplurals=2; plural=n != 1;\n"
21-
"X-Generator: Weblate 4.3.2\n"
21+
"X-Generator: Weblate 5.15.2\n"
22+
23+
#. module: website_sale_product_brand
24+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
25+
msgid "<b>Brand</b>"
26+
msgstr ""
27+
28+
#. module: website_sale_product_brand
29+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
30+
msgid ""
31+
"<small class=\"mx-auto\">\n"
32+
" <b>Clear Filters</b>\n"
33+
" </small>\n"
34+
" <i class=\"oi oi-close\" role=\"presentation\"/>"
35+
msgstr ""
2236

2337
#. module: website_sale_product_brand
2438
#: model:ir.model.fields,field_description:website_sale_product_brand.field_product_brand__can_publish
2539
msgid "Can Publish"
2640
msgstr ""
2741

42+
#. module: website_sale_product_brand
43+
#: model_terms:ir.ui.view,arch_db:website_sale_product_brand.website_sale_filter_brand_products_brands
44+
msgid "Clear Filters"
45+
msgstr ""
46+
2847
#. module: website_sale_product_brand
2948
#: model:ir.model.fields,field_description:website_sale_product_brand.field_product_brand__is_published
3049
msgid "Is Published"

0 commit comments

Comments
 (0)