-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by JordiBForgeFlow
- Loading branch information
Showing
15 changed files
with
786 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,83 @@ | ||
============================== | ||
Product Category multi-company | ||
============================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:0241276720f7ff767f8269555c794a9b84abe2cfa2781fa8d178799311887742 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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%2Fmulti--company-lightgray.png?logo=github | ||
:target: https://github.com/OCA/multi-company/tree/15.0/product_category_multi_company | ||
:alt: OCA/multi-company | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/multi-company-15-0/multi-company-15-0-product_category_multi_company | ||
: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/multi-company&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module add multi-company management to product categories. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
* Go to *Inventory* | ||
* Go to *Configuration > Product Categories* | ||
* Open a category and set the desired companies | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/multi-company/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 <https://github.com/OCA/multi-company/issues/new?body=module:%20product_category_multi_company%0Aversion:%2015.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 S.L. | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Arnau Cruz <[email protected]> | ||
|
||
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/multi-company <https://github.com/OCA/multi-company/tree/15.0/product_category_multi_company>`_ 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 @@ | ||
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,20 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Product Category multi-company", | ||
"summary": "", | ||
"author": "ForgeFlow S.L.,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/multi-company", | ||
"category": "Product Management", | ||
"version": "15.0.1.0.0", | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"base_multi_company", | ||
"product_category_inter_company", | ||
"product_multi_company", | ||
], | ||
"data": [ | ||
"views/product_category.xml", | ||
], | ||
} |
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 @@ | ||
from . import product_category | ||
from . import product_template |
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,71 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = ["multi.company.abstract", "product.category"] | ||
_name = "product.category" | ||
_description = "Product Category (Multi-Company)" | ||
|
||
@api.constrains("company_ids") | ||
def _check_product_companies_in_category(self): | ||
for category in self: | ||
if not category.company_ids: | ||
continue | ||
products = ( | ||
self.env["product.template"] | ||
.sudo() | ||
.search([("categ_id", "=", category.id)]) | ||
) | ||
for product in products: | ||
product_company_ids = product.company_ids | ||
if not all( | ||
company in category.company_ids for company in product_company_ids | ||
): | ||
raise ValidationError( | ||
_( | ||
"The category's companies cannot be changed because some products " | ||
"have companies not in the new set of category companies." | ||
) | ||
) | ||
|
||
@api.constrains("parent_id", "company_ids") | ||
def check_company_restriction(self): | ||
for record in self: | ||
parent_company_ids = record.parent_id.company_ids | ||
record_company_ids = record.company_ids | ||
|
||
if parent_company_ids and not all( | ||
company_id in parent_company_ids for company_id in record_company_ids | ||
): | ||
raise ValidationError( | ||
_( | ||
"The parent category %(parent)s and your category %(child)s " | ||
"must share the same companies." | ||
) | ||
% {"parent": record.parent_id.name, "child": record.name} | ||
) | ||
|
||
for child in record.child_id: | ||
child_company_ids = child.company_ids | ||
if record_company_ids and not all( | ||
company_id in record_company_ids for company_id in child_company_ids | ||
): | ||
if child_company_ids: | ||
msg = _( | ||
"The category %(parent)s must be shared as the " | ||
"child %(child)s belongs to companies %(companies)s." | ||
) % { | ||
"parent": record.name, | ||
"child": child.name, | ||
"companies": ", ".join(child_company_ids.mapped("name")), | ||
} | ||
else: | ||
msg = _( | ||
"The category %(parent)s must be shared as the " | ||
"child %(child)s is shared." | ||
) % {"parent": record.name, "child": child.name} | ||
raise ValidationError(msg) |
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,23 @@ | ||
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
@api.constrains("company_ids", "categ_id") | ||
def _check_company_ids_in_category(self): | ||
for product in self: | ||
product_company_ids = product.company_ids | ||
category_company_ids = product.categ_id.company_ids | ||
if category_company_ids and not all( | ||
company in category_company_ids for company in product_company_ids | ||
): | ||
raise ValidationError( | ||
_( | ||
"The product's companies must be a subset of the category's companies." | ||
) | ||
) |
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 @@ | ||
* Arnau Cruz <[email protected]> |
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 add multi-company management to 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,3 @@ | ||
* Go to *Inventory* | ||
* Go to *Configuration > Product Categories* | ||
* Open a category and set the desired companies |
Oops, something went wrong.