diff --git a/website_sale_hide_empty_category/README.rst b/website_sale_hide_empty_category/README.rst new file mode 100644 index 0000000000..5c447ad192 --- /dev/null +++ b/website_sale_hide_empty_category/README.rst @@ -0,0 +1,106 @@ +==================================== +Website Sale - Hide Empty Categories +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d10828f104845b192f732918c09e56ca4f937bdf26b3cbec8ffec7a10267befb + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |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_hide_empty_category + :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_hide_empty_category + :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| + +Removes any category links from the Shop which have no products +associated to them. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +When the module is installed, by default the options to hide empty +categories are active. + +These options can be configured in the web editor. To do this, go to +‘/shop’ and activate or deactivate the options to hide empty categories +from the web editor in the ‘Customize’ tab. + +There are two options: + +- Hide Empty Category Filmstrip: to hide/show empty categories in the + top category bar. +- Hide Empty Category list: to hide/show empty categories in the left + category list. + +Usage +===== + +Once this module is installed and configured, go to ‘/shop’. Empty +categories will not be show. + +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 +------- + +* LasLabs + +Contributors +------------ + +- Ted Salmon +- `Tecnativa `__: + + - Carlos Roca + - Pilar Vargas + +- Radovan Skolnik + +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_hide_empty_category/__init__.py b/website_sale_hide_empty_category/__init__.py new file mode 100644 index 0000000000..1ada0880cc --- /dev/null +++ b/website_sale_hide_empty_category/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +from . import models diff --git a/website_sale_hide_empty_category/__manifest__.py b/website_sale_hide_empty_category/__manifest__.py new file mode 100644 index 0000000000..18c01c5b63 --- /dev/null +++ b/website_sale_hide_empty_category/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +{ + "name": "Website Sale - Hide Empty Categories", + "summary": "Hide any Product Categories that are empty", + "version": "18.0.1.0.0", + "category": "Website", + "website": "https://github.com/OCA/e-commerce", + "author": "LasLabs, Odoo Community Association (OCA)", + "license": "LGPL-3", + "application": False, + "installable": True, + "depends": ["website_sale"], + "data": ["views/website_sale_templates.xml"], + "assets": { + "web.assets_tests": [ + "/website_sale_hide_empty_category/static/src/js/tour.esm.js" + ], + }, +} diff --git a/website_sale_hide_empty_category/i18n/ca.po b/website_sale_hide_empty_category/i18n/ca.po new file mode 100644 index 0000000000..605d195584 --- /dev/null +++ b/website_sale_hide_empty_category/i18n/ca.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_hide_empty_category +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-02-25 17:46+0000\n" +"Last-Translator: claudiagn \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" +"X-Generator: Weblate 4.3.2\n" + +#. module: website_sale_hide_empty_category +#: model:ir.model.fields,field_description:website_sale_hide_empty_category.field_product_public_category__has_product_recursive +msgid "This category or one of its children has products" +msgstr "Aquesta categoria o un dels seus fills té productes" + +#. module: website_sale_hide_empty_category +#: model:ir.model,name:website_sale_hide_empty_category.model_product_public_category +msgid "Website Product Category" +msgstr "Categoria de producte del lloc web" diff --git a/website_sale_hide_empty_category/i18n/es.po b/website_sale_hide_empty_category/i18n/es.po new file mode 100644 index 0000000000..10a459b774 --- /dev/null +++ b/website_sale_hide_empty_category/i18n/es.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_hide_empty_category +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2021-02-25 17:45+0000\n" +"Last-Translator: claudiagn \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: website_sale_hide_empty_category +#: model:ir.model.fields,field_description:website_sale_hide_empty_category.field_product_public_category__has_product_recursive +msgid "This category or one of its children has products" +msgstr "Aquesta categoria o un dels seus fills té productes" + +#. module: website_sale_hide_empty_category +#: model:ir.model,name:website_sale_hide_empty_category.model_product_public_category +msgid "Website Product Category" +msgstr "Categoría del Producto" + +#~ msgid "Products" +#~ msgstr "Productos" diff --git a/website_sale_hide_empty_category/i18n/nl.po b/website_sale_hide_empty_category/i18n/nl.po new file mode 100644 index 0000000000..fed460473f --- /dev/null +++ b/website_sale_hide_empty_category/i18n/nl.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_hide_empty_category +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-12-15 13:19+0000\n" +"Last-Translator: Bosd \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" +"X-Generator: Weblate 4.3.2\n" + +#. module: website_sale_hide_empty_category +#: model:ir.model.fields,field_description:website_sale_hide_empty_category.field_product_public_category__has_product_recursive +msgid "This category or one of its children has products" +msgstr "Deze categorie of een van de subcategorieen bevat geen producten" + +#. module: website_sale_hide_empty_category +#: model:ir.model,name:website_sale_hide_empty_category.model_product_public_category +msgid "Website Product Category" +msgstr "Website Product Categorie" diff --git a/website_sale_hide_empty_category/i18n/website_sale_hide_empty_category.pot b/website_sale_hide_empty_category/i18n/website_sale_hide_empty_category.pot new file mode 100644 index 0000000000..93694cce6e --- /dev/null +++ b/website_sale_hide_empty_category/i18n/website_sale_hide_empty_category.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_hide_empty_category +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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" + +#. module: website_sale_hide_empty_category +#: model:ir.model.fields,field_description:website_sale_hide_empty_category.field_product_public_category__has_product_recursive +msgid "This category or one of its children has products" +msgstr "" + +#. module: website_sale_hide_empty_category +#: model:ir.model,name:website_sale_hide_empty_category.model_product_public_category +msgid "Website Product Category" +msgstr "" diff --git a/website_sale_hide_empty_category/models/__init__.py b/website_sale_hide_empty_category/models/__init__.py new file mode 100644 index 0000000000..c926ff6f0c --- /dev/null +++ b/website_sale_hide_empty_category/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import product_public_category diff --git a/website_sale_hide_empty_category/models/product_public_category.py b/website_sale_hide_empty_category/models/product_public_category.py new file mode 100644 index 0000000000..279715b389 --- /dev/null +++ b/website_sale_hide_empty_category/models/product_public_category.py @@ -0,0 +1,22 @@ +# Copyright 2017 LasLabs Inc. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class ProductPublicCategory(models.Model): + _inherit = "product.public.category" + + has_product_recursive = fields.Boolean( + string="This category or one of its children has products", + compute="_compute_has_product_recursive", + recursive=True, + ) + + @api.depends("product_tmpl_ids", "child_id.has_product_recursive") + def _compute_has_product_recursive(self): + for category in self: + category.has_product_recursive = bool( + category.product_tmpl_ids + or any(child.has_product_recursive for child in category.child_id) + ) diff --git a/website_sale_hide_empty_category/pyproject.toml b/website_sale_hide_empty_category/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_sale_hide_empty_category/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_sale_hide_empty_category/readme/CONFIGURE.md b/website_sale_hide_empty_category/readme/CONFIGURE.md new file mode 100644 index 0000000000..3460499f8d --- /dev/null +++ b/website_sale_hide_empty_category/readme/CONFIGURE.md @@ -0,0 +1,9 @@ +When the module is installed, by default the options to hide empty categories are active. + +These options can be configured in the web editor. To do this, go to ‘/shop’ and activate +or deactivate the options to hide empty categories from the web editor in the ‘Customize’ tab. + +There are two options: + +- Hide Empty Category Filmstrip: to hide/show empty categories in the top category bar. +- Hide Empty Category list: to hide/show empty categories in the left category list. diff --git a/website_sale_hide_empty_category/readme/CONTRIBUTORS.md b/website_sale_hide_empty_category/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..894791435b --- /dev/null +++ b/website_sale_hide_empty_category/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- Ted Salmon \<\> +- [Tecnativa](https://www.tecnativa.com): + - Carlos Roca + - Pilar Vargas +- Radovan Skolnik \<\> diff --git a/website_sale_hide_empty_category/readme/DESCRIPTION.md b/website_sale_hide_empty_category/readme/DESCRIPTION.md new file mode 100644 index 0000000000..67a00ead92 --- /dev/null +++ b/website_sale_hide_empty_category/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +Removes any category links from the Shop which have no products +associated to them. diff --git a/website_sale_hide_empty_category/readme/USAGE.md b/website_sale_hide_empty_category/readme/USAGE.md new file mode 100644 index 0000000000..c812fbf327 --- /dev/null +++ b/website_sale_hide_empty_category/readme/USAGE.md @@ -0,0 +1 @@ +Once this module is installed and configured, go to ‘/shop’. Empty categories will not be show. diff --git a/website_sale_hide_empty_category/static/description/icon.png b/website_sale_hide_empty_category/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_sale_hide_empty_category/static/description/icon.png differ diff --git a/website_sale_hide_empty_category/static/description/index.html b/website_sale_hide_empty_category/static/description/index.html new file mode 100644 index 0000000000..11e00473cb --- /dev/null +++ b/website_sale_hide_empty_category/static/description/index.html @@ -0,0 +1,452 @@ + + + + + +Website Sale - Hide Empty Categories + + + +
+

Website Sale - Hide Empty Categories

+ + +

Beta License: LGPL-3 OCA/e-commerce Translate me on Weblate Try me on Runboat

+

Removes any category links from the Shop which have no products +associated to them.

+

Table of contents

+ +
+

Configuration

+

When the module is installed, by default the options to hide empty +categories are active.

+

These options can be configured in the web editor. To do this, go to +‘/shop’ and activate or deactivate the options to hide empty categories +from the web editor in the ‘Customize’ tab.

+

There are two options:

+
    +
  • Hide Empty Category Filmstrip: to hide/show empty categories in the +top category bar.
  • +
  • Hide Empty Category list: to hide/show empty categories in the left +category list.
  • +
+
+
+

Usage

+

Once this module is installed and configured, go to ‘/shop’. Empty +categories will not be show.

+
+
+

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

+
    +
  • LasLabs
  • +
+
+
+

Contributors

+ +
+
+

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_hide_empty_category/static/src/js/tour.esm.js b/website_sale_hide_empty_category/static/src/js/tour.esm.js new file mode 100644 index 0000000000..9db8afc04a --- /dev/null +++ b/website_sale_hide_empty_category/static/src/js/tour.esm.js @@ -0,0 +1,26 @@ +/* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ +import {registry} from "@web/core/registry"; + +registry.category("web_tour.tours").add("website_sale_hide_empty_category", { + test: true, + url: "/shop", + steps: () => [ + { + trigger: "#products_grid_before a:contains('Category Test Posted')", + }, + { + trigger: + "#products_grid_before:not(:has(a:contains('Category Test Not Posted')))", + }, + { + trigger: "a[href='/shop']", + }, + { + trigger: ".o_wsale_filmstip_wrapper span:contains('Category Test Posted')", + }, + { + trigger: + ".o_wsale_filmstip_wrapper:not(:has(span:contains('Category Test Not Posted')))", + }, + ], +}); diff --git a/website_sale_hide_empty_category/tests/__init__.py b/website_sale_hide_empty_category/tests/__init__.py new file mode 100644 index 0000000000..259b87b426 --- /dev/null +++ b/website_sale_hide_empty_category/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_ui +from . import test_has_product_recursive diff --git a/website_sale_hide_empty_category/tests/test_has_product_recursive.py b/website_sale_hide_empty_category/tests/test_has_product_recursive.py new file mode 100644 index 0000000000..a382362aed --- /dev/null +++ b/website_sale_hide_empty_category/tests/test_has_product_recursive.py @@ -0,0 +1,35 @@ +from odoo.tests import common + + +class TestPublicCategory(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Remove this variable in v16 and put instead: + # from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + DISABLED_MAIL_CONTEXT = { + "tracking_disable": True, + "mail_create_nolog": True, + "mail_create_nosubscribe": True, + "mail_notrack": True, + "no_reset_password": True, + } + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + + def test_has_product_recursive(self): + category_1 = self.env["product.public.category"].create({"name": "Category 1"}) + + self.assertFalse(category_1.has_product_recursive) + + category_2 = self.env["product.public.category"].create( + {"name": "Category 2", "parent_id": category_1.id} + ) + + self.assertFalse(category_2.has_product_recursive) + + self.env["product.template"].create( + {"name": "Product Test", "public_categ_ids": [(4, category_2.id, None)]} + ) + + self.assertTrue(category_1.has_product_recursive) + self.assertTrue(category_2.has_product_recursive) diff --git a/website_sale_hide_empty_category/tests/test_ui.py b/website_sale_hide_empty_category/tests/test_ui.py new file mode 100644 index 0000000000..e78a4b05e8 --- /dev/null +++ b/website_sale_hide_empty_category/tests/test_ui.py @@ -0,0 +1,40 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import HttpCase, tagged + + +@tagged("post_install", "-at_install") +class UICase(HttpCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Remove this variable in v16 and put instead: + # from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + DISABLED_MAIL_CONTEXT = { + "tracking_disable": True, + "mail_create_nolog": True, + "mail_create_nosubscribe": True, + "mail_notrack": True, + "no_reset_password": True, + } + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + category_posted = cls.env["product.public.category"].create( + {"name": "Category Test Posted", "sequence": 1} + ) + cls.env["product.public.category"].create( + {"name": "Category Test Not Posted", "sequence": 2} + ) + cls.env["product.template"].create( + { + "name": "Test Product 1", + "is_published": True, + "website_sequence": 1, + "type": "consu", + "public_categ_ids": [category_posted.id], + } + ) + cls.env.ref("website_sale.products_categories").active = True + + def test_ui_website(self): + """Test frontend tour.""" + self.start_tour("/shop", "website_sale_hide_empty_category", login="admin") diff --git a/website_sale_hide_empty_category/views/website_sale_templates.xml b/website_sale_hide_empty_category/views/website_sale_templates.xml new file mode 100644 index 0000000000..3655bccbd8 --- /dev/null +++ b/website_sale_hide_empty_category/views/website_sale_templates.xml @@ -0,0 +1,62 @@ + + + + + + + +