Skip to content

Commit

Permalink
[16.0][MIG] website_sale_product_attribute_value_filter_existing: Mig…
Browse files Browse the repository at this point in the history
…ration to 16.0
  • Loading branch information
anothingguy committed Mar 20, 2023
1 parent 7e658f5 commit 9c2b71b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Website Sale Attribute Value Existing",
"summary": "Allow hide attributes values not used in variants",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"development_status": "Production/Stable",
"category": "Website",
"website": "https://github.com/OCA/e-commerce",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo import http
from odoo.http import request
from odoo.tools import lazy

from odoo.addons.website_sale.controllers.main import WebsiteSale


class ProductAttributeValues(WebsiteSale):
def _get_search_domain(
self, search, category, attrib_values, search_in_description=True
):
# Store used domain in context to be reused after
domain = super()._get_search_domain(
search, category, attrib_values, search_in_description=search_in_description
)
new_context = dict(request.env.context, shop_search_domain=domain)
request.context = new_context
return domain

@http.route()
def shop(self, page=0, category=None, search="", ppg=False, **post):
res = super().shop(page=page, category=category, search=search, ppg=ppg, **post)
domain = request.env.context.get("shop_search_domain", [])
# Load all products without limit for the filter check on
# attribute values
templates = request.env["product.template"].search(domain, limit=False)

# getting existing templates by "search_product" in qcontext
# without searching again
templates = res.qcontext["search_product"]
ProductTemplateAttributeLine = request.env["product.template.attribute.line"]
attribute_values = ProductTemplateAttributeLine.search(
[("product_tmpl_id", "in", templates.ids)]
attribute_values = lazy(
lambda: ProductTemplateAttributeLine.search(
[("product_tmpl_id", "in", templates.ids)]
)
)
res.qcontext["attr_values_used"] = attribute_values.mapped("value_ids")
return res
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
* Victor M.M. Torres
* Sergio Teruel
* Carlos Roca

* `Trobz <https://trobz.com>`_:
* Hoang Diep <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 15.0 to 16.0 was financially supported by Camptocamp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright 2019 Tecnativa - Sergio Teruel
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo.tests.common import HttpCase
from odoo.tests.common import HttpCase, tagged


@tagged("post_install", "-at_install")
class WebsiteSaleHttpCase(HttpCase):
def setUp(self):
super().setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<attribute name="t-if">attr_values_used &amp; v</attribute>
</xpath>
<xpath
expr="//t[@t-if=&quot;a.display_type == 'color'&quot;]//t[@t-foreach='a.value_ids']/label"
expr="//div[@t-if=&quot;a.display_type == 'color'&quot;]//t[@t-foreach='a.value_ids']/label"
position="attributes"
>
<attribute name="t-if">attr_values_used &amp; v</attribute>
Expand Down

0 comments on commit 9c2b71b

Please sign in to comment.