Skip to content

Commit

Permalink
Merge PR #1277 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Apr 16, 2024
2 parents 9bbf6ce + c70171c commit 3580777
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 0 deletions.
77 changes: 77 additions & 0 deletions product_category_level/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/product-attribute/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 <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_category_level%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-PierrickBrun|

This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_category_level>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_category_level/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions product_category_level/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
],
}
18 changes: 18 additions & 0 deletions product_category_level/demo/product_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record model="product.category" id="demo_category_parent">
<field name="name">Demo Parent Category</field>
</record>

<record model="product.category" id="demo_category_child_1">
<field name="name">Demo Category child 1</field>
<field name="parent_id" ref="demo_category_parent" />
</record>

<record model="product.category" id="demo_category_child_2">
<field name="name">Demo Category child 2</field>
<field name="parent_id" ref="demo_category_child_1" />
</record>

</odoo>
33 changes: 33 additions & 0 deletions product_category_level/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -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"
31 changes: 31 additions & 0 deletions product_category_level/i18n/product_category_level.pot
Original file line number Diff line number Diff line change
@@ -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 ""
1 change: 1 addition & 0 deletions product_category_level/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_category
24 changes: 24 additions & 0 deletions product_category_level/models/product_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Pierrick Brun <[email protected]>
# 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
2 changes: 2 additions & 0 deletions product_category_level/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add a 'Level' field on Product Categories to show
the number of parents a category has (recursively).
1 change: 1 addition & 0 deletions product_category_level/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_category_level
24 changes: 24 additions & 0 deletions product_category_level/tests/test_category_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Pierrick Brun <[email protected]>
# 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)
36 changes: 36 additions & 0 deletions product_category_level/views/product_category.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="view_product_category_search">
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_search_view" />
<field name="arch" type="xml">
<field name="parent_id" position="after">
<field name="level" />
</field>
</field>
</record>

<record model="ir.ui.view" id="view_product_category_tree">
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_list_view" />
<field name="arch" type="xml">
<field name="display_name" position="after">
<field name="level" />
</field>
</field>
</record>

<record model="ir.ui.view" id="view_product_category_form">
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view" />
<field name="arch" type="xml">
<field name="parent_id" position="before">
<field name="level" class="oe_inline" />
</field>
</field>
</record>

</odoo>
6 changes: 6 additions & 0 deletions setup/product_category_level/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 3580777

Please sign in to comment.