diff --git a/stock_archive_constraint/README.rst b/stock_archive_constraint/README.rst index ddf4ba45b..8ec807930 100644 --- a/stock_archive_constraint/README.rst +++ b/stock_archive_constraint/README.rst @@ -2,10 +2,13 @@ Stock archive constraint ======================== -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5eb5e8d43aa1267d1be15f4d09a53a775c2fef3234784461f39c4b4c806c90cd + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png :target: https://odoo-community.org/page/development-status @@ -19,11 +22,11 @@ Stock archive constraint .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-15-0/stock-logistics-warehouse-15-0-stock_archive_constraint :alt: Translate me on Weblate -.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/153/15.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=15.0 + :alt: Try me on Runboat -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| Allows to block archiving products with associated stock.quant or stock.move. Allows to block archiving locations with associated stock.quant or stock.move. @@ -44,7 +47,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 +If you spotted it first, help us to smash it by providing a detailed and welcomed `feedback `_. Do not contact contributors directly about support or help with technical issues. diff --git a/stock_archive_constraint/__manifest__.py b/stock_archive_constraint/__manifest__.py index 2760b5fd6..9c85eca64 100644 --- a/stock_archive_constraint/__manifest__.py +++ b/stock_archive_constraint/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Stock archive constraint", - "version": "15.0.1.0.0", + "version": "15.0.1.0.1", "license": "AGPL-3", "website": "https://github.com/OCA/stock-logistics-warehouse", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/stock_archive_constraint/models/product_product.py b/stock_archive_constraint/models/product_product.py index 7453754e1..49a488674 100644 --- a/stock_archive_constraint/models/product_product.py +++ b/stock_archive_constraint/models/product_product.py @@ -3,13 +3,21 @@ from odoo import _, api, models from odoo.exceptions import ValidationError +from odoo.tools import config class ProductProduct(models.Model): _inherit = "product.product" + def _skip_check_archive_constraint_condition(self): + return config["test_enable"] and not self.env.context.get( + "test_stock_archive_constraint" + ) + @api.constrains("active") def _check_active_stock_archive_constraint_stock_quant(self): + if self._skip_check_archive_constraint_condition(): + return res = self.env["stock.quant"].search( [ ("location_id.usage", "in", ("internal", "transit")), @@ -29,6 +37,8 @@ class ProductProduct(models.Model): @api.constrains("active") def _check_active_stock_archive_constraint_stock_move(self): + if self._skip_check_archive_constraint_condition(): + return res = self.env["stock.move"].search( [ ("product_id", "in", self.filtered(lambda x: not x.active).ids), @@ -47,6 +57,8 @@ class ProductProduct(models.Model): @api.constrains("active") def _check_active_stock_archive_constraint_stock_move_line(self): + if self._skip_check_archive_constraint_condition(): + return res = self.env["stock.move.line"].search( [ ("product_id", "in", self.filtered(lambda x: not x.active).ids), diff --git a/stock_archive_constraint/models/stock_location.py b/stock_archive_constraint/models/stock_location.py index d78a9a18e..04ae12afe 100644 --- a/stock_archive_constraint/models/stock_location.py +++ b/stock_archive_constraint/models/stock_location.py @@ -3,13 +3,21 @@ from odoo import _, api, models from odoo.exceptions import ValidationError +from odoo.tools import config class StockLocation(models.Model): _inherit = "stock.location" + def _skip_check_archive_constraint_condition(self): + return config["test_enable"] and not self.env.context.get( + "test_stock_archive_constraint" + ) + @api.constrains("active") def _check_active_stock_archive_constraint_stock_quant(self): + if self._skip_check_archive_constraint_condition(): + return res = self.env["stock.quant"].search( [ "&", @@ -31,6 +39,8 @@ class StockLocation(models.Model): @api.constrains("active") def _check_active_stock_archive_constraint_stock_move(self): + if self._skip_check_archive_constraint_condition(): + return res = self.env["stock.move"].search( [ "&", @@ -52,6 +62,8 @@ class StockLocation(models.Model): @api.constrains("active") def _check_active_stock_archive_constraint_stock_move_line(self): + if self._skip_check_archive_constraint_condition(): + return res = self.env["stock.move.line"].search( [ "&", diff --git a/stock_archive_constraint/static/description/index.html b/stock_archive_constraint/static/description/index.html index 6f370933f..f5d387b5f 100644 --- a/stock_archive_constraint/static/description/index.html +++ b/stock_archive_constraint/static/description/index.html @@ -1,20 +1,20 @@ - + - + Stock archive constraint