diff --git a/setup/website_sale_product_attribute_value_filter_existing/odoo/addons/website_sale_product_attribute_value_filter_existing b/setup/website_sale_product_attribute_value_filter_existing/odoo/addons/website_sale_product_attribute_value_filter_existing new file mode 120000 index 0000000000..7bd3d67aeb --- /dev/null +++ b/setup/website_sale_product_attribute_value_filter_existing/odoo/addons/website_sale_product_attribute_value_filter_existing @@ -0,0 +1 @@ +../../../../website_sale_product_attribute_value_filter_existing \ No newline at end of file diff --git a/setup/website_sale_product_attribute_value_filter_existing/setup.py b/setup/website_sale_product_attribute_value_filter_existing/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_sale_product_attribute_value_filter_existing/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_sale_product_attribute_value_filter_existing/README.rst b/website_sale_product_attribute_value_filter_existing/README.rst new file mode 100644 index 0000000000..6291155351 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/README.rst @@ -0,0 +1,85 @@ +===================================== +Website Sale Attribute Value Existing +===================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github + :target: https://github.com/OCA/e-commerce/tree/14.0/website_sale_product_attribute_value_filter_existing + :alt: OCA/e-commerce +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/e-commerce-14-0/e-commerce-14-0-website_sale_product_attribute_value_filter_existing + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/113/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of website sale module to allow hide +product attributes values which exist but not used on any variants. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Go to Website Shop +* Active product attributes filter +* System only display the attribute values if used. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Victor M.M. Torres + * Sergio Teruel + * Carlos Roca + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/e-commerce `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_product_attribute_value_filter_existing/__init__.py b/website_sale_product_attribute_value_filter_existing/__init__.py new file mode 100644 index 0000000000..4d53772e85 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/__init__.py @@ -0,0 +1,2 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from . import controllers diff --git a/website_sale_product_attribute_value_filter_existing/__manifest__.py b/website_sale_product_attribute_value_filter_existing/__manifest__.py new file mode 100644 index 0000000000..f4a6943093 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2019 Tecnativa - Victor M.M. Torres +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +{ + "name": "Website Sale Attribute Value Existing", + "summary": "Allow hide attributes values not used in variants", + "version": "15.0.1.0.0", + "development_status": "Production/Stable", + "category": "Website", + "website": "https://github.com/OCA/e-commerce", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "LGPL-3", + "application": False, + "installable": True, + "depends": ["website_sale"], + "data": ["views/templates.xml"], + "assets": { + "web.assets_tests": [ + "/website_sale_product_attribute_value_filter_existing/static/src/js/" + "website_sale_product_attribute_value_filter_existing_tour.js", + ] + }, +} diff --git a/website_sale_product_attribute_value_filter_existing/controllers/__init__.py b/website_sale_product_attribute_value_filter_existing/controllers/__init__.py new file mode 100644 index 0000000000..edc60fa860 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/controllers/__init__.py @@ -0,0 +1,2 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from . import main diff --git a/website_sale_product_attribute_value_filter_existing/controllers/main.py b/website_sale_product_attribute_value_filter_existing/controllers/main.py new file mode 100644 index 0000000000..3317b9c6c6 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/controllers/main.py @@ -0,0 +1,33 @@ +# Copyright 2019 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from odoo import http +from odoo.http import request + +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) + ProductTemplateAttributeLine = request.env["product.template.attribute.line"] + attribute_values = ProductTemplateAttributeLine.search( + [("product_tmpl_id", "in", templates.ids)] + ) + res.qcontext["attr_values_used"] = attribute_values.mapped("value_ids") + return res diff --git a/website_sale_product_attribute_value_filter_existing/i18n/ca.po b/website_sale_product_attribute_value_filter_existing/i18n/ca.po new file mode 100644 index 0000000000..4d6a6788a4 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/i18n/ca.po @@ -0,0 +1,14 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: ca\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" diff --git a/website_sale_product_attribute_value_filter_existing/i18n/es.po b/website_sale_product_attribute_value_filter_existing/i18n/es.po new file mode 100644 index 0000000000..cdd0dca4a8 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/i18n/es.po @@ -0,0 +1,14 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" diff --git a/website_sale_product_attribute_value_filter_existing/i18n/nl.po b/website_sale_product_attribute_value_filter_existing/i18n/nl.po new file mode 100644 index 0000000000..d61a759d36 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/i18n/nl.po @@ -0,0 +1,14 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: nl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" diff --git a/website_sale_product_attribute_value_filter_existing/i18n/website_sale_product_attribute_value_filter_existing.pot b/website_sale_product_attribute_value_filter_existing/i18n/website_sale_product_attribute_value_filter_existing.pot new file mode 100644 index 0000000000..4d8b20f912 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/i18n/website_sale_product_attribute_value_filter_existing.pot @@ -0,0 +1,13 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" diff --git a/website_sale_product_attribute_value_filter_existing/readme/CONTRIBUTORS.rst b/website_sale_product_attribute_value_filter_existing/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..7bbc1ee8e7 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `Tecnativa `_: + + * Victor M.M. Torres + * Sergio Teruel + * Carlos Roca diff --git a/website_sale_product_attribute_value_filter_existing/readme/DESCRIPTION.rst b/website_sale_product_attribute_value_filter_existing/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..21a2d80b14 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the functionality of website sale module to allow hide +product attributes values which exist but not used on any variants. diff --git a/website_sale_product_attribute_value_filter_existing/readme/USAGE.rst b/website_sale_product_attribute_value_filter_existing/readme/USAGE.rst new file mode 100644 index 0000000000..599a0dda08 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/readme/USAGE.rst @@ -0,0 +1,3 @@ +* Go to Website Shop +* Active product attributes filter +* System only display the attribute values if used. diff --git a/website_sale_product_attribute_value_filter_existing/static/description/icon.png b/website_sale_product_attribute_value_filter_existing/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_sale_product_attribute_value_filter_existing/static/description/icon.png differ diff --git a/website_sale_product_attribute_value_filter_existing/static/description/index.html b/website_sale_product_attribute_value_filter_existing/static/description/index.html new file mode 100644 index 0000000000..948a4e493a --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/static/description/index.html @@ -0,0 +1,434 @@ + + + + + + +Website Sale Attribute Value Existing + + + +
+

Website Sale Attribute Value Existing

+ + +

Production/Stable License: LGPL-3 OCA/e-commerce Translate me on Weblate Try me on Runbot

+

This module extends the functionality of website sale module to allow hide +product attributes values which exist but not used on any variants.

+

Table of contents

+ +
+

Usage

+
    +
  • Go to Website Shop
  • +
  • Active product attributes filter
  • +
  • System only display the attribute values if used.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Victor M.M. Torres
    • +
    • Sergio Teruel
    • +
    • Carlos Roca
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/e-commerce project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/website_sale_product_attribute_value_filter_existing/static/src/js/website_sale_product_attribute_value_filter_existing_tour.js b/website_sale_product_attribute_value_filter_existing/static/src/js/website_sale_product_attribute_value_filter_existing_tour.js new file mode 100644 index 0000000000..fb67e3c901 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/static/src/js/website_sale_product_attribute_value_filter_existing_tour.js @@ -0,0 +1,43 @@ +/* Copyright 2019 Sergio Teruel + * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ + +odoo.define( + "website_sale_product_attribute_value_filter_existing.tour", + function (require) { + "use strict"; + + var tour = require("web_tour.tour"); + var base = require("web_editor.base"); + + var steps = [ + { + trigger: "a[href='/shop']", + }, + { + trigger: "input[name=search]", + run: "text Ipod", + extra_trigger: ".js_attributes:has(label:contains('Test blue'))", + }, + { + trigger: ".oe_search_button", + extra_trigger: ".js_attributes:has(label:contains('Test blue'))", + }, + { + trigger: "a[href='/shop']", + extra_trigger: ".js_attributes:not(:has(label:contains('Test blue')))", + }, + ]; + tour.register( + "website_sale_product_attribute_value_filter_existing", + { + url: "/shop", + test: true, + wait_for: base.ready(), + }, + steps + ); + return { + steps: steps, + }; + } +); diff --git a/website_sale_product_attribute_value_filter_existing/tests/__init__.py b/website_sale_product_attribute_value_filter_existing/tests/__init__.py new file mode 100644 index 0000000000..7c9f488772 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/tests/__init__.py @@ -0,0 +1,2 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from . import test_website_sale_product_attribute_value_filter_existing diff --git a/website_sale_product_attribute_value_filter_existing/tests/test_website_sale_product_attribute_value_filter_existing.py b/website_sale_product_attribute_value_filter_existing/tests/test_website_sale_product_attribute_value_filter_existing.py new file mode 100644 index 0000000000..3e76ef5376 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/tests/test_website_sale_product_attribute_value_filter_existing.py @@ -0,0 +1,83 @@ +# Copyright 2019 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from odoo.tests.common import HttpCase + + +class WebsiteSaleHttpCase(HttpCase): + def setUp(self): + super().setUp() + # Models + ProductAttribute = self.env["product.attribute"] + ProductAttributeValue = self.env["product.attribute.value"] + ProductAttributeLine = self.env["product.template.attribute.line"] + self.product_attribute = ProductAttribute.create( + {"name": "Test Special Color", "create_variant": "no_variant"} + ) + self.product_attribute_value_red = ProductAttributeValue.create( + {"name": "Test red", "attribute_id": self.product_attribute.id} + ) + self.product_attribute_value_green = ProductAttributeValue.create( + {"name": "Test green", "attribute_id": self.product_attribute.id} + ) + self.product_attribute_value_blue = ProductAttributeValue.create( + {"name": "Test blue", "attribute_id": self.product_attribute.id} + ) + self.product_template = self.env.ref( + "product.product_product_4_product_template" + ) + self.product_attribute_line = ProductAttributeLine.create( + { + "product_tmpl_id": self.product_template.id, + "attribute_id": self.product_attribute.id, + "value_ids": [ + ( + 6, + 0, + [ + self.product_attribute_value_red.id, + self.product_attribute_value_green.id, + ], + ) + ], + } + ) + self.product_template.write( + {"attribute_line_ids": [(4, self.product_attribute_line.id)]} + ) + self.product_template_27 = self.env.ref( + "product.product_product_27_product_template" + ) + self.product_attribute_line_27 = ProductAttributeLine.create( + { + "product_tmpl_id": self.product_template_27.id, + "attribute_id": self.product_attribute.id, + "value_ids": [ + ( + 6, + 0, + [ + self.product_attribute_value_red.id, + self.product_attribute_value_blue.id, + ], + ) + ], + } + ) + self.product_template_27.write( + {"attribute_line_ids": [(4, self.product_attribute_line_27.id)]} + ) + # Active attribute's filter in /shop. By default it's disabled. + self.env.ref("website_sale.products_attributes").active = True + + def test_ui_website(self): + """Test frontend tour.""" + tour = ( + "odoo.__DEBUG__.services['web_tour.tour']", + "website_sale_product_attribute_value_filter_existing", + ) + self.browser_js( + url_path="/", + code="%s.run('%s')" % tour, + ready="%s.tours['%s'].ready" % tour, + login="admin", + ) diff --git a/website_sale_product_attribute_value_filter_existing/views/templates.xml b/website_sale_product_attribute_value_filter_existing/views/templates.xml new file mode 100644 index 0000000000..7f89c04ba1 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/views/templates.xml @@ -0,0 +1,25 @@ + + + + +