Skip to content

Commit

Permalink
[ADD] product_pack_product_category
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiMForgeFlow committed Jun 30, 2023
1 parent 5c3c655 commit bda23d4
Show file tree
Hide file tree
Showing 17 changed files with 731 additions and 0 deletions.
92 changes: 92 additions & 0 deletions product_pack_category_restriction/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
=================================
Product Pack Category Restriction
=================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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--pack-lightgray.png?logo=github
:target: https://github.com/OCA/product-pack/tree/13.0/product_pack_category_restriction
:alt: OCA/product-pack
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-pack-13-0/product-pack-13-0-product_pack_category_restriction
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/286/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to restrict pack products to specific Product Categories.

**Table of contents**

.. contents::
:local:

Usage
=====

A new checkbox 'Is Pack Category?' is available in the configuration of each
Product Category.

Pack Products will only be able to be assigned to Product Categories where
the checkbox is marked.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-pack/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-pack/issues/new?body=module:%20product_pack_category_restriction%0Aversion:%2013.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
~~~~~~~

* ForgeFlow

Contributors
~~~~~~~~~~~~

* `ForgeFlow <https://www.forgeflow.com>`_:

* Jordi Masvidal

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-JordiMForgeFlow| image:: https://github.com/JordiMForgeFlow.png?size=40px
:target: https://github.com/JordiMForgeFlow
:alt: JordiMForgeFlow

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-JordiMForgeFlow|

This module is part of the `OCA/product-pack <https://github.com/OCA/product-pack/tree/13.0/product_pack_category_restriction>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions product_pack_category_restriction/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
19 changes: 19 additions & 0 deletions product_pack_category_restriction/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Product Pack Category Restriction",
"version": "13.0.1.0.0",
"category": "Product",
"summary": """
This module allows you to restrict pack products to specific Product
Categories.
""",
"website": "https://github.com/OCA/product-pack",
"author": "ForgeFlow,Odoo Community Association (OCA)",
"maintainers": ["JordiMForgeFlow"],
"license": "AGPL-3",
"depends": ["product_pack"],
"data": ["views/product_category_views.xml"],
"installable": True,
"application": False,
}
4 changes: 4 additions & 0 deletions product_pack_category_restriction/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import product_category
from . import product_template
from . import product_product
24 changes: 24 additions & 0 deletions product_pack_category_restriction/models/product_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class ProductCategory(models.Model):
_inherit = "product.category"

pack_ok = fields.Boolean(string="Is Pack Category?", default=True)

@api.constrains("pack_ok")
def _check_pack_ok(self):
"""Check pack products are only on pack categories"""
categs = self.filtered(lambda c: not c.pack_ok)
if categs:
products = self.env["product.template"].search(

Check warning on line 18 in product_pack_category_restriction/models/product_category.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_category.py#L18

Added line #L18 was not covered by tests
[("categ_id", "in", categs.ids), ("pack_ok", "=", True)]
)
if products:
raise ValidationError(

Check warning on line 22 in product_pack_category_restriction/models/product_category.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_category.py#L22

Added line #L22 was not covered by tests
_("Non-pack Category can't contain pack products.")
)
22 changes: 22 additions & 0 deletions product_pack_category_restriction/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class ProductProduct(models.Model):
_inherit = "product.product"

@api.onchange("categ_id")
def _onchange_categ_id(self):
res = super()._onchange_categ_id()

Check warning on line 12 in product_pack_category_restriction/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_product.py#L12

Added line #L12 was not covered by tests
if self.categ_id:
self.pack_ok = self.categ_id.pack_ok
return res

Check warning on line 15 in product_pack_category_restriction/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_product.py#L14-L15

Added lines #L14 - L15 were not covered by tests

@api.onchange("pack_ok")
def _onchange_pack_ok(self):
if self.pack_ok:
return {"domain": {"categ_id": [("pack_ok", "=", True)]}}

Check warning on line 20 in product_pack_category_restriction/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_product.py#L20

Added line #L20 was not covered by tests
else:
return {"domain": {"categ_id": []}}

Check warning on line 22 in product_pack_category_restriction/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_product.py#L22

Added line #L22 was not covered by tests
29 changes: 29 additions & 0 deletions product_pack_category_restriction/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, models
from odoo.exceptions import ValidationError


class ProductTemplate(models.Model):
_inherit = "product.template"

@api.constrains("pack_ok")
def _check_pack_ok(self):
products = self.filtered(lambda p: p.pack_ok)
if products and any(not p.categ_id.pack_ok for p in products):
raise ValidationError(_("Pack Products must be part of a Pack Category."))

Check warning on line 15 in product_pack_category_restriction/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_template.py#L15

Added line #L15 was not covered by tests

@api.onchange("categ_id")
def _onchange_categ_id(self):
res = super()._onchange_categ_id()

Check warning on line 19 in product_pack_category_restriction/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_template.py#L19

Added line #L19 was not covered by tests
if self.categ_id:
self.pack_ok = self.categ_id.pack_ok
return res

Check warning on line 22 in product_pack_category_restriction/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_template.py#L21-L22

Added lines #L21 - L22 were not covered by tests

@api.onchange("pack_ok")
def _onchange_pack_ok(self):
if self.pack_ok:
return {"domain": {"categ_id": [("pack_ok", "=", True)]}}

Check warning on line 27 in product_pack_category_restriction/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_template.py#L27

Added line #L27 was not covered by tests
else:
return {"domain": {"categ_id": []}}

Check warning on line 29 in product_pack_category_restriction/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_pack_category_restriction/models/product_template.py#L29

Added line #L29 was not covered by tests
3 changes: 3 additions & 0 deletions product_pack_category_restriction/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `ForgeFlow <https://www.forgeflow.com>`_:

* Jordi Masvidal
1 change: 1 addition & 0 deletions product_pack_category_restriction/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows you to restrict pack products to specific Product Categories.
5 changes: 5 additions & 0 deletions product_pack_category_restriction/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A new checkbox 'Is Pack Category?' is available in the configuration of each
Product Category.

Pack Products will only be able to be assigned to Product Categories where
the checkbox is marked.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit bda23d4

Please sign in to comment.