-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA#72146 [16.0][MIG] product_category_safe_change (#206)
Co-authored-by: Lanto R. <[email protected]> Co-authored-by: Majda EL MARIOULI <[email protected]>
- Loading branch information
1 parent
e3bc283
commit 92ea8ce
Showing
18 changed files
with
434 additions
and
5 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
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
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
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 Safe Change | ||
============================ | ||
This module allows to restrict the modification of a product category if the product linked to it has already some stock move | ||
associated to it. | ||
|
||
Usage | ||
----- | ||
* Restricting the modification of a category on product | ||
|
||
As a user who can edit a product, I go to a product which had already some stock move. | ||
I edit the product and change the category of the product. | ||
I click on the `Save` button. | ||
I get the following blocking error message: | ||
|
||
.. image:: https://raw.githubusercontent.com/Numigi/odoo-stock-addons/16.0/product_category_safe_change/static/description/product_variant_category.png | ||
|
||
.. image:: https://raw.githubusercontent.com/Numigi/odoo-stock-addons/16.0/product_category_safe_change/static/description/product_variant_new_category.png | ||
|
||
.. image:: https://raw.githubusercontent.com/Numigi/odoo-stock-addons/16.0/product_category_safe_change/static/description/product_variant_category_validate_error.png | ||
|
||
|
||
* Restricting Inventory Properties Setup Changes | ||
|
||
As a user in the `Inventory/Manager` group, I go to an product category (on `Inventory>Configuration`). | ||
I have access to modify a category. | ||
I try to modify one of the following fields (only available on view when `Inventory Valuation` value is ``Automated``(real_time)): | ||
-Stock Input Account | ||
-Stock Output Account | ||
-Stock Valuation Account | ||
-Stock Journal | ||
And then click on the `Save` button. | ||
If I have products with this category that have stock move, I get the following blocking error message: | ||
.. image:: https://raw.githubusercontent.com/Numigi/odoo-stock-addons/16.0/product_category_safe_change/static/description/product_category_account_updated.png | ||
Multi company contrainsts | ||
------------------------- | ||
Examples : in the context of a multi-company database, with shared articles: | ||
The data is as follows: | ||
Companies: Company A, Company B | ||
Category: Category 1 | ||
Product: Product 1 (case where I only have this product in the database) | ||
On the database, I have the following stock moves: | ||
* Case 1: | ||
+-----------------+--------------------+-----------+-----------------------+ | ||
| Stock move name | Stock move Company | Product | Constraint applied to | | ||
+=================+====================+===========+=======================+ | ||
| BL001 | Company A | Product 1 | Company A only | | ||
+-----------------+--------------------+-----------+-----------------------+ | ||
Expected result: I can modify the category settings under Company B. I cannot modify the product category since it is common to all companies. | ||
* Case 2: | ||
+-----------------+--------------------+-----------+-------------------------+ | ||
| Stock move name | Stock move Company | Product | Constraint applied to | | ||
+=================+====================+===========+=========================+ | ||
| BL001 | Company A | Product 1 | Company A and company B | | ||
| BL002 | Company B | Product 1 | Company A and company B | | ||
+-----------------+--------------------+-----------+-------------------------+ | ||
Expected result: I cannot change the category settings under any of the companies (A and B). I cannot modify the category of the product since it is common to all companies. | ||
* Case 3: | ||
+-----------------+--------------------+-----------+-----------------------+ | ||
| Stock move name | Stock move Company | Product | Constraint applied to | | ||
+=================+====================+===========+=======================+ | ||
| BL001 | Company B | Product 1 | Company B only | | ||
+-----------------+--------------------+-----------+-----------------------+ | ||
Expected result: I can modify the category settings under Company A. I cannot modify the item category since it is common to all companies. | ||
NOTICE : | ||
This behavior is applied in the same way when I have several articles in the database: | ||
1. If the user tries to modify the parameters of a category under a company for which there is no stock.move associated via the products, the constraint is not applied. | ||
2. If the user tries to modify the category of an article, while there is a stock movement associated with the article in the database (all companies combined), then the constraint applies. | ||
Contributors | ||
------------ | ||
* Numigi (tm) and all its contributors (https://bit.ly/numigiens) |
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 @@ | ||
# Copyright 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
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,17 @@ | ||
# Copyright 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Product Category Safe Change", | ||
"version": "16.0.1.0.0", | ||
"author": "Numigi", | ||
"maintainer": "Numigi", | ||
"website": "https://bit.ly/numigi-com", | ||
"license": "AGPL-3", | ||
"category": "Stock", | ||
"depends": ["stock_account"], | ||
"summary": "Add some restriction to the product category of articles", | ||
"data": [], | ||
"installable": True, | ||
"auto_install": True, | ||
} |
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,60 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * product_category_safe_change | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2025-01-31 12:20+0000\n" | ||
"PO-Revision-Date: 2025-01-31 12:20+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_safe_change | ||
#. odoo-python | ||
#: code:addons/product_category_safe_change/models/product_category.py:0 | ||
#, python-format | ||
msgid "" | ||
"\n" | ||
" You cannot modify Stock Properties Parameters when\n" | ||
" related Products have existing Stock Moves.\n" | ||
"\n" | ||
" Stock moves exist for the following products:\n" | ||
" - " | ||
msgstr "" | ||
"\n" | ||
" Vous ne pouvez pas modifier le paramétrage des propriétés de stock \n" | ||
" si un des articles de la catégorie a des mouvements de stock associés.\n" | ||
"\n" | ||
" Des mouvements de stock sont existants pour les articles suivants:\n" | ||
" - " | ||
|
||
#. module: product_category_safe_change | ||
#: model:ir.model,name:product_category_safe_change.model_product_template | ||
msgid "Product" | ||
msgstr "Produit" | ||
|
||
#. module: product_category_safe_change | ||
#: model:ir.model,name:product_category_safe_change.model_product_category | ||
msgid "Product Category" | ||
msgstr "Catégorie de produit" | ||
|
||
#. module: product_category_safe_change | ||
#: model:ir.model,name:product_category_safe_change.model_product_product | ||
msgid "Product Variant" | ||
msgstr "Variante de produit" | ||
|
||
#. module: product_category_safe_change | ||
#. odoo-python | ||
#: code:addons/product_category_safe_change/models/product.py:0 | ||
#: code:addons/product_category_safe_change/models/product_template.py:0 | ||
#, python-format | ||
msgid "You cannot modify the category of a Product with Stock Moves." | ||
msgstr "" | ||
"Vous ne pouvez pas modifier la catégorie d’un article ayant des mouvements " | ||
"de stocks associés." |
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,6 @@ | ||
# Copyright 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import product | ||
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,25 @@ | ||
# Copyright 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class Product(models.Model): | ||
_inherit = "product.product" | ||
|
||
@api.constrains("categ_id") | ||
def _check_category_stock_move(self): | ||
for product in self: | ||
if product.type != "service": | ||
existing_move_lines = ( | ||
self.env["stock.move.line"] | ||
.sudo() | ||
.search([("product_id", "=", product.id)]) | ||
) | ||
if existing_move_lines: | ||
raise UserError( | ||
_( | ||
"You cannot modify the category of a Product with Stock Moves." | ||
) | ||
) |
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,41 @@ | ||
# Copyright 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class ProductCategory(models.Model): | ||
_inherit = "product.category" | ||
|
||
@api.constrains( | ||
"property_stock_account_input_categ_id", | ||
"property_stock_account_output_categ_id", | ||
"property_stock_valuation_account_id", | ||
"property_stock_journal", | ||
) | ||
def _check_category_stock_move(self): | ||
for category in self: | ||
domain = [ | ||
("product_id.categ_id", "=", category.id), | ||
("company_id", "=", self.env.company.id), | ||
] | ||
existing_move_lines = self.env["stock.move.line"].sudo().search(domain) | ||
|
||
if existing_move_lines: | ||
# Select only three first products found on move lines | ||
# if there is more than 3 | ||
product_lists = existing_move_lines.mapped("product_id.name") | ||
product_lists = ( | ||
product_lists[:3] if len(product_lists) > 3 else product_lists | ||
) | ||
products = "\n- ".join(product_lists) | ||
|
||
message = _( | ||
""" | ||
You cannot modify Stock Properties Parameters when | ||
related Products have existing Stock Moves.\n | ||
Stock moves exist for the following products: | ||
- """ | ||
) | ||
raise UserError(message + products) |
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,25 @@ | ||
# Copyright 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
@api.constrains("categ_id") | ||
def _check_category_stock_move(self): | ||
for product in self: | ||
if product.type != "service": | ||
existing_move_lines = ( | ||
self.env["stock.move.line"] | ||
.sudo() | ||
.search([("product_id.product_tmpl_id", "=", product.id)]) | ||
) | ||
if existing_move_lines: | ||
raise UserError( | ||
_( | ||
"You cannot modify the category of a Product with Stock Moves." | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+115 KB
...ct_category_safe_change/static/description/product_category_account_updated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+116 KB
product_category_safe_change/static/description/product_variant_category.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+90.8 KB
...gory_safe_change/static/description/product_variant_category_validate_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+125 KB
product_category_safe_change/static/description/product_variant_new_category.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
# Copyright 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_product_category |
Oops, something went wrong.