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..65b0dc89b3 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/README.rst @@ -0,0 +1,92 @@ +===================================== +Website Sale Attribute Value Existing +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:562d481510f7e83bd8c15d55c7f9172d725d25625cb64dd622c91f2c0ba4c17a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.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-18-0/e-commerce-18-0-website_sale_product_attribute_value_filter_existing + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&target_branch=18.0 + :alt: Try me on Runboat + +|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: + +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 to smash 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 + - Pilar Vargas + +- `Trobz `__: + + - Hoang Diep + +Other credits +------------- + +The migration of this module from 15.0 to 16.0 was financially supported +by Camptocamp + +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..6cc51637fc --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/__manifest__.py @@ -0,0 +1,24 @@ +# 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": "18.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.esm.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..8b9ae51821 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/controllers/main.py @@ -0,0 +1,42 @@ +# 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.tools import lazy + +from odoo.addons.website_sale.controllers.main import WebsiteSale + + +class ProductAttributeValues(WebsiteSale): + @http.route() + def shop( + self, + page=0, + category=None, + search="", + min_price=0.0, + max_price=0.0, + ppg=False, + **post, + ): + res = super().shop( + page=page, + category=category, + search=search, + min_price=min_price, + max_price=max_price, + ppg=ppg, + **post, + ) + + # 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 = lazy( + lambda: 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..e69de29bb2 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..e69de29bb2 diff --git a/website_sale_product_attribute_value_filter_existing/i18n/it.po b/website_sale_product_attribute_value_filter_existing/i18n/it.po new file mode 100644 index 0000000000..73388557f6 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/i18n/it.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 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: it\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..e69de29bb2 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..78d58d53fe --- /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 16.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/pyproject.toml b/website_sale_product_attribute_value_filter_existing/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_sale_product_attribute_value_filter_existing/readme/CONFIGURATION.rst b/website_sale_product_attribute_value_filter_existing/readme/CONFIGURATION.rst new file mode 100644 index 0000000000..94088c3c78 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/readme/CONFIGURATION.rst @@ -0,0 +1,5 @@ +* Go to Website Shop +* Active product attributes filter on theme panel option of shopping page + - Click edit button on shopping page (or directly go url: http://{your-domain}/@/shop) + - On tab `Customize`, enable attributes filter to show attribute values left of the layout. +* System only display the attribute values if used. diff --git a/website_sale_product_attribute_value_filter_existing/readme/CONTRIBUTORS.md b/website_sale_product_attribute_value_filter_existing/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..95b02b4a3c --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/readme/CONTRIBUTORS.md @@ -0,0 +1,8 @@ +- [Tecnativa](https://www.tecnativa.com): + - Victor M.M. Torres + - Sergio Teruel + - Carlos Roca + - Pilar Vargas + +- [Trobz](https://trobz.com): + - Hoang Diep \<\> diff --git a/website_sale_product_attribute_value_filter_existing/readme/CREDITS.md b/website_sale_product_attribute_value_filter_existing/readme/CREDITS.md new file mode 100644 index 0000000000..291e14c81e --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/readme/CREDITS.md @@ -0,0 +1,2 @@ +The migration of this module from 15.0 to 16.0 was financially supported +by Camptocamp diff --git a/website_sale_product_attribute_value_filter_existing/readme/DESCRIPTION.md b/website_sale_product_attribute_value_filter_existing/readme/DESCRIPTION.md new file mode 100644 index 0000000000..f9f440b191 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/readme/DESCRIPTION.md @@ -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/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..d31bc0c927 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +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 Runboat

+

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

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 15.0 to 16.0 was financially supported +by Camptocamp

+
+
+

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.esm.js b/website_sale_product_attribute_value_filter_existing/static/src/js/website_sale_product_attribute_value_filter_existing_tour.esm.js new file mode 100644 index 0000000000..55351955cd --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/static/src/js/website_sale_product_attribute_value_filter_existing_tour.esm.js @@ -0,0 +1,33 @@ +/** @odoo-module **/ + +import {registry} from "@web/core/registry"; +import * as tourUtils from "@website_sale/js/tours/tour_utils"; + +registry + .category("web_tour.tours") + .add("website_sale_product_attribute_value_filter_existing", { + url: "/shop", + steps: () => [ + // No product has the yellow colour attribute defined. + // When enter to "/shop" the attribute "test yellow" should not appear in the list of filters by attribute. + // For the following steps it is checked that the attribute "test yellow" is + // not present in the list but the attributes "test red", "test blue" and + // "test green" must be present. + { + content: + "Ensure 'test red', 'test blue' and 'test green' attributes are present while 'Test yellow' is not.", + trigger: + ".js_attributes:not(:contains('Test yellow')):has(label:contains('Test red')), .js_attributes:not(:contains('Test yellow')):has(label:contains('Test blue')), .js_attributes:not(:contains('Test yellow')):has(label:contains('Test green'))", + }, + ...tourUtils.searchProduct("customizable"), + // After searching, the attributes "test red" and "test green" must be present. + // "Test yelow" should not be present as it is not used in any product and + // "test blue" should not be present as it is not used in the products shown. + { + content: + "Ensure 'test red' and 'test green' attributes are present while 'Test yellow' and 'test blue' are not.", + trigger: + ".js_attributes:not(:contains('Test blue'), :contains('Test yellow')):has(label:contains('Test green')), .js_attributes:not(:contains('Test blue'), :contains('Test yellow')):has(label:contains('Test red'))", + }, + ], + }); 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..5b6eed1fc9 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/tests/test_website_sale_product_attribute_value_filter_existing.py @@ -0,0 +1,108 @@ +# Copyright 2019 Tecnativa - Sergio Teruel +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +from odoo.tests.common import HttpCase, tagged + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +@tagged("post_install", "-at_install") +class WebsiteSaleHttpCase(HttpCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + # Models + ProductAttribute = cls.env["product.attribute"] + ProductAttributeValue = cls.env["product.attribute.value"] + ProductAttributeLine = cls.env["product.template.attribute.line"] + cls.product_attribute = ProductAttribute.create( + { + "name": "Test Special Color", + "display_type": "color", + "create_variant": "no_variant", + } + ) + cls.product_attribute_value_red = ProductAttributeValue.create( + { + "name": "Test red", + "attribute_id": cls.product_attribute.id, + "html_color": "#ff0000", + } + ) + cls.product_attribute_value_green = ProductAttributeValue.create( + { + "name": "Test green", + "attribute_id": cls.product_attribute.id, + "html_color": "#1dff00", + } + ) + cls.product_attribute_value_blue = ProductAttributeValue.create( + { + "name": "Test blue", + "attribute_id": cls.product_attribute.id, + "html_color": "#0000ff", + } + ) + cls.product_attribute_value_yellow = ProductAttributeValue.create( + { + "name": "Test yellow", + "attribute_id": cls.product_attribute.id, + "html_color": "#0000ff", + } + ) + cls.product_template = cls.env.ref("product.product_product_4_product_template") + cls.product_attribute_line = ProductAttributeLine.create( + { + "product_tmpl_id": cls.product_template.id, + "attribute_id": cls.product_attribute.id, + "value_ids": [ + ( + 6, + 0, + [ + cls.product_attribute_value_red.id, + cls.product_attribute_value_green.id, + ], + ) + ], + } + ) + cls.product_template.write( + {"attribute_line_ids": [(4, cls.product_attribute_line.id)]} + ) + cls.product_template_11 = cls.env.ref( + "product.product_product_11_product_template" + ) + cls.product_attribute_line_11 = ProductAttributeLine.create( + { + "product_tmpl_id": cls.product_template_11.id, + "attribute_id": cls.product_attribute.id, + "value_ids": [ + ( + 6, + 0, + [ + cls.product_attribute_value_red.id, + cls.product_attribute_value_blue.id, + ], + ) + ], + } + ) + cls.product_template_11.write( + {"attribute_line_ids": [(4, cls.product_attribute_line_11.id)]} + ) + # Active attribute's filter in /shop. By default it's disabled. + cls.env.ref("website_sale.products_attributes").active = True + + def test_ui_website(self): + """Test frontend tour.""" + + self.start_tour( + "/", + "website_sale_product_attribute_value_filter_existing", + login="admin", + # deplay step here to ensure the tests pass + step_delay=100, + ) 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..e92a74ed57 --- /dev/null +++ b/website_sale_product_attribute_value_filter_existing/views/templates.xml @@ -0,0 +1,35 @@ + + + + + + +