diff --git a/product_category_level/README.rst b/product_category_level/README.rst new file mode 100644 index 00000000000..21bbc860c1a --- /dev/null +++ b/product_category_level/README.rst @@ -0,0 +1,77 @@ +====================== +Product Category Level +====================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/16.0/product_category_level + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_category_level + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/product-attribute&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add a 'Level' field on Product Categories to show +the number of parents a category has (recursively). + +**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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +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. + +.. |maintainer-PierrickBrun| image:: https://github.com/PierrickBrun.png?size=40px + :target: https://github.com/PierrickBrun + :alt: PierrickBrun + +Current `maintainer `__: + +|maintainer-PierrickBrun| + +This module is part of the `OCA/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_category_level/__init__.py b/product_category_level/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/product_category_level/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_category_level/__manifest__.py b/product_category_level/__manifest__.py new file mode 100644 index 00000000000..f48502cb6be --- /dev/null +++ b/product_category_level/__manifest__.py @@ -0,0 +1,20 @@ +{ + "name": "Product Category Level", + "summary": """ + Add Level field on Product Categories + to show the recursion level on the category""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Akretion, Odoo Community Association (OCA)", + "maintainers": ["PierrickBrun"], + "website": "https://github.com/OCA/product-attribute", + "depends": [ + "product", + ], + "data": [ + "views/product_category.xml", + ], + "demo": [ + "demo/product_category.xml", + ], +} diff --git a/product_category_level/demo/product_category.xml b/product_category_level/demo/product_category.xml new file mode 100644 index 00000000000..5df59d1cf6a --- /dev/null +++ b/product_category_level/demo/product_category.xml @@ -0,0 +1,18 @@ + + + + + Demo Parent Category + + + + Demo Category child 1 + + + + + Demo Category child 2 + + + + diff --git a/product_category_level/i18n/fr.po b/product_category_level/i18n/fr.po new file mode 100644 index 00000000000..379e77a37ad --- /dev/null +++ b/product_category_level/i18n/fr.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_category_level +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-02-24 17:00+0000\n" +"PO-Revision-Date: 2023-02-24 18:01+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: fr_FR\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: Poedit 3.1.1\n" + +#. module: product_category_level +#: model:ir.model.fields,field_description:product_category_level.field_product_category__level +msgid "Level" +msgstr "Niveau" + +#. module: product_category_level +#: model:ir.model,name:product_category_level.model_product_category +msgid "Product Category" +msgstr "Catégorie de Produit" + +#. module: product_category_level +#: model:ir.model.fields,help:product_category_level.field_product_category__level +msgid "The number of parents this category has" +msgstr "Le nombre de parents qu'a cette catégorie" diff --git a/product_category_level/i18n/product_category_level.pot b/product_category_level/i18n/product_category_level.pot new file mode 100644 index 00000000000..86794ddc82f --- /dev/null +++ b/product_category_level/i18n/product_category_level.pot @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_category_level +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-02-24 17:00+0000\n" +"PO-Revision-Date: 2023-02-24 17:00+0000\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: product_category_level +#: model:ir.model.fields,field_description:product_category_level.field_product_category__level +msgid "Level" +msgstr "" + +#. module: product_category_level +#: model:ir.model,name:product_category_level.model_product_category +msgid "Product Category" +msgstr "" + +#. module: product_category_level +#: model:ir.model.fields,help:product_category_level.field_product_category__level +msgid "The number of parents this category has" +msgstr "" diff --git a/product_category_level/models/__init__.py b/product_category_level/models/__init__.py new file mode 100644 index 00000000000..53553f3f2de --- /dev/null +++ b/product_category_level/models/__init__.py @@ -0,0 +1 @@ +from . import product_category diff --git a/product_category_level/models/product_category.py b/product_category_level/models/product_category.py new file mode 100644 index 00000000000..0ace9cc1e56 --- /dev/null +++ b/product_category_level/models/product_category.py @@ -0,0 +1,24 @@ +# Copyright 2023 Akretion (https://www.akretion.com). +# @author Pierrick Brun +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ProductCategory(models.Model): + _inherit = "product.category" + + level = fields.Integer( + compute="_compute_level", + store=True, + recursive=True, + help="The number of parents this category has", + ) + + @api.depends("parent_id", "parent_id.level") + def _compute_level(self): + for record in self: + if record.parent_id: + record.level = record.parent_id.level + 1 + else: + record.level = 0 diff --git a/product_category_level/readme/DESCRIPTION.rst b/product_category_level/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..da8291e62ba --- /dev/null +++ b/product_category_level/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Add a 'Level' field on Product Categories to show +the number of parents a category has (recursively). diff --git a/product_category_level/tests/__init__.py b/product_category_level/tests/__init__.py new file mode 100644 index 00000000000..8d7e268babe --- /dev/null +++ b/product_category_level/tests/__init__.py @@ -0,0 +1 @@ +from . import test_category_level diff --git a/product_category_level/tests/test_category_level.py b/product_category_level/tests/test_category_level.py new file mode 100644 index 00000000000..91064f91807 --- /dev/null +++ b/product_category_level/tests/test_category_level.py @@ -0,0 +1,24 @@ +# Copyright 2023 Akretion (https://www.akretion.com). +# @author Pierrick Brun +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestProductCategoryLevel(TransactionCase): + def setUp(self): + super().setUp() + self.print_category_parent = self.env.ref( + "product_category_level.demo_category_parent" + ) + self.print_category_child_1 = self.env.ref( + "product_category_level.demo_category_child_1" + ) + self.print_category_child_2 = self.env.ref( + "product_category_level.demo_category_child_2" + ) + + def test_product_category_level(self): + self.assertEqual(2, self.print_category_child_2.level) + self.assertEqual(0, self.print_category_parent.level) + self.assertEqual(1, self.print_category_child_1.level) diff --git a/product_category_level/views/product_category.xml b/product_category_level/views/product_category.xml new file mode 100644 index 00000000000..2cfdb082ed8 --- /dev/null +++ b/product_category_level/views/product_category.xml @@ -0,0 +1,36 @@ + + + + + + product.category + + + + + + + + + + product.category + + + + + + + + + + product.category + + + + + + + + + diff --git a/setup/product_category_level/odoo/addons/product_category_level b/setup/product_category_level/odoo/addons/product_category_level new file mode 120000 index 00000000000..16d48f5d776 --- /dev/null +++ b/setup/product_category_level/odoo/addons/product_category_level @@ -0,0 +1 @@ +../../../../product_category_level \ No newline at end of file diff --git a/setup/product_category_level/setup.py b/setup/product_category_level/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/product_category_level/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)