-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c3c655
commit bda23d4
Showing
17 changed files
with
731 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
product_pack_category_restriction/models/product_category.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
[("categ_id", "in", categs.ids), ("pack_ok", "=", True)] | ||
) | ||
if products: | ||
raise ValidationError( | ||
_("Non-pack Category can't contain pack products.") | ||
) |
22 changes: 22 additions & 0 deletions
22
product_pack_category_restriction/models/product_product.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
if self.categ_id: | ||
self.pack_ok = self.categ_id.pack_ok | ||
return res | ||
|
||
@api.onchange("pack_ok") | ||
def _onchange_pack_ok(self): | ||
if self.pack_ok: | ||
return {"domain": {"categ_id": [("pack_ok", "=", True)]}} | ||
else: | ||
return {"domain": {"categ_id": []}} | ||
29 changes: 29 additions & 0 deletions
29
product_pack_category_restriction/models/product_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.")) | ||
|
||
@api.onchange("categ_id") | ||
def _onchange_categ_id(self): | ||
res = super()._onchange_categ_id() | ||
if self.categ_id: | ||
self.pack_ok = self.categ_id.pack_ok | ||
return res | ||
|
||
@api.onchange("pack_ok") | ||
def _onchange_pack_ok(self): | ||
if self.pack_ok: | ||
return {"domain": {"categ_id": [("pack_ok", "=", True)]}} | ||
else: | ||
return {"domain": {"categ_id": []}} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `ForgeFlow <https://www.forgeflow.com>`_: | ||
|
||
* Jordi Masvidal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.