diff --git a/setup/stock_archive_constraint/odoo/addons/stock_archive_constraint b/setup/stock_archive_constraint/odoo/addons/stock_archive_constraint new file mode 120000 index 000000000..06320188a --- /dev/null +++ b/setup/stock_archive_constraint/odoo/addons/stock_archive_constraint @@ -0,0 +1 @@ +../../../../stock_archive_constraint \ No newline at end of file diff --git a/setup/stock_archive_constraint/setup.py b/setup/stock_archive_constraint/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_archive_constraint/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_archive_constraint/README.rst b/stock_archive_constraint/README.rst new file mode 100644 index 000000000..eddc13a84 --- /dev/null +++ b/stock_archive_constraint/README.rst @@ -0,0 +1,91 @@ +======================== +Stock archive constraint +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_archive_constraint + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-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/13.0 + :alt: Try me on Runbot + +|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. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. Go to Settings > Users > Edit a user and check the "Manage Multiple Stock Locations" permission +#. Go to Inventory > Settings > Locations and disable one + +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 +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Carlos Daudén + * Víctor Martínez + +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-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_archive_constraint/__init__.py b/stock_archive_constraint/__init__.py new file mode 100644 index 000000000..83e553ac4 --- /dev/null +++ b/stock_archive_constraint/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/stock_archive_constraint/__manifest__.py b/stock_archive_constraint/__manifest__.py new file mode 100644 index 000000000..3bbd429bd --- /dev/null +++ b/stock_archive_constraint/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Stock archive constraint", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "Tecnativa, Odoo Community Association (OCA)", + "development_status": "Production/Stable", + "category": "Warehouse", + "depends": ["stock"], + "installable": True, + "maintainers": ["victoralmau"], +} diff --git a/stock_archive_constraint/i18n/es.po b/stock_archive_constraint/i18n/es.po new file mode 100644 index 000000000..7a95b8cc2 --- /dev/null +++ b/stock_archive_constraint/i18n/es.po @@ -0,0 +1,88 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_archive_constraint +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-01-08 09:03+0000\n" +"PO-Revision-Date: 2021-01-08 10:06+0100\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 2.3\n" + +#. module: stock_archive_constraint +#: model:ir.model,name:stock_archive_constraint.model_stock_location +msgid "Inventory Locations" +msgstr "Ubicaciones de inventario" + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/stock_location.py:41 +#, python-format +msgid "" +"It is not possible to archive location '%s' which has associated picking " +"lines." +msgstr "" +"No es posible archivar la ubicación '%s' que tiene líneas de albaranes " +"asociadas." + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/stock_location.py:24 +#, python-format +msgid "" +"It is not possible to archive location '%s' which has associated stock " +"quantities." +msgstr "" +"No es posible archivar la ubicación '%s' que tiene asociadas cantidades " +"de stock." + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/stock_location.py:58 +#, python-format +msgid "" +"It is not possible to archive location '%s' which has associated stock " +"reservations." +msgstr "" +"No es posible archivar la ubicación '%s' que tiene reservas de stock " +"asociadas." + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/product_product.py:36 +#, python-format +msgid "" +"It is not possible to archive product '%s' which has associated picking " +"lines." +msgstr "" +"No es posible archivar el producto '%s' que tiene líneas de albaranes " +"asociadas." + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/product_product.py:22 +#, python-format +msgid "" +"It is not possible to archive product '%s' which has associated stock " +"quantities." +msgstr "" +"No es posible archivar el producto '%s' que tiene asociadas cantidades " +"de stock." + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/product_product.py:50 +#, python-format +msgid "" +"It is not possible to archive product '%s' which has associated stock " +"reservations." +msgstr "" +"No es posible archivar el producto '%s' que tiene reservas de stock " +"asociadas." + +#. module: stock_archive_constraint +#: model:ir.model,name:stock_archive_constraint.model_product_product +msgid "Product" +msgstr "Producto" diff --git a/stock_archive_constraint/i18n/stock_archive_constraint.pot b/stock_archive_constraint/i18n/stock_archive_constraint.pot new file mode 100644 index 000000000..c3f58e531 --- /dev/null +++ b/stock_archive_constraint/i18n/stock_archive_constraint.pot @@ -0,0 +1,72 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_archive_constraint +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \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: stock_archive_constraint +#: model:ir.model,name:stock_archive_constraint.model_stock_location +msgid "Inventory Locations" +msgstr "" + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/stock_location.py:0 +#, python-format +msgid "" +"It is not possible to archive location '%s' which has associated picking " +"lines." +msgstr "" + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/stock_location.py:0 +#, python-format +msgid "" +"It is not possible to archive location '%s' which has associated stock " +"quantities." +msgstr "" + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/stock_location.py:0 +#, python-format +msgid "" +"It is not possible to archive location '%s' which has associated stock " +"reservations." +msgstr "" + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/product_product.py:0 +#, python-format +msgid "" +"It is not possible to archive product '%s' which has associated picking " +"lines." +msgstr "" + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/product_product.py:0 +#, python-format +msgid "" +"It is not possible to archive product '%s' which has associated stock " +"quantities." +msgstr "" + +#. module: stock_archive_constraint +#: code:addons/stock_archive_constraint/models/product_product.py:0 +#, python-format +msgid "" +"It is not possible to archive product '%s' which has associated stock " +"reservations." +msgstr "" + +#. module: stock_archive_constraint +#: model:ir.model,name:stock_archive_constraint.model_product_product +msgid "Product" +msgstr "" diff --git a/stock_archive_constraint/models/__init__.py b/stock_archive_constraint/models/__init__.py new file mode 100644 index 000000000..1b6574480 --- /dev/null +++ b/stock_archive_constraint/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import product_product +from . import stock_location diff --git a/stock_archive_constraint/models/product_product.py b/stock_archive_constraint/models/product_product.py new file mode 100644 index 000000000..d639e8c5e --- /dev/null +++ b/stock_archive_constraint/models/product_product.py @@ -0,0 +1,61 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class ProductProduct(models.Model): + _inherit = "product.product" + + @api.constrains("active") + def _check_active_stock_archive_constraint_stock_quant(self): + res = self.env["stock.quant"].search( + [ + ("location_id.usage", "in", ("internal", "transit")), + ("product_id", "in", self.filtered(lambda x: not x.active).ids), + ("quantity", "!=", 0.0), + ], + limit=1, + ) + if res: + raise ValidationError( + _( + "It is not possible to archive product '%s' which has " + "associated stock quantities." % res[0].product_id.display_name + ) + ) + + @api.constrains("active") + def _check_active_stock_archive_constraint_stock_move(self): + res = self.env["stock.move"].search( + [ + ("product_id", "in", self.filtered(lambda x: not x.active).ids), + ("state", "not in", ("done", "cancel")), + ], + limit=1, + ) + if res: + raise ValidationError( + _( + "It is not possible to archive product '%s' which has " + "associated picking lines." % res[0].product_id.display_name + ) + ) + + @api.constrains("active") + def _check_active_stock_archive_constraint_stock_move_line(self): + res = self.env["stock.move.line"].search( + [ + ("product_id", "in", self.filtered(lambda x: not x.active).ids), + ("state", "not in", ("done", "cancel")), + ], + limit=1, + ) + if res: + raise ValidationError( + _( + "It is not possible to archive product '%s' which has " + "associated stock reservations." % res[0].product_id.display_name + ) + ) diff --git a/stock_archive_constraint/models/product_template.py b/stock_archive_constraint/models/product_template.py new file mode 100644 index 000000000..d6813c9f4 --- /dev/null +++ b/stock_archive_constraint/models/product_template.py @@ -0,0 +1,12 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + @api.constrains("active") + def _check_active_stock_archive_constraint(self): + self.product_variant_ids._check_active_stock_archive_constraint() diff --git a/stock_archive_constraint/models/stock_location.py b/stock_archive_constraint/models/stock_location.py new file mode 100644 index 000000000..3152db12f --- /dev/null +++ b/stock_archive_constraint/models/stock_location.py @@ -0,0 +1,69 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class StockLocation(models.Model): + _inherit = "stock.location" + + @api.constrains("active") + def _check_active_stock_archive_constraint_stock_quant(self): + res = self.env["stock.quant"].search( + [ + "&", + ("location_id.usage", "in", ("internal", "transit")), + "|", + ("location_id", "in", self.filtered(lambda x: not x.active).ids), + ("location_id", "child_of", self.filtered(lambda x: not x.active).ids), + ], + limit=1, + ) + if res: + raise ValidationError( + _( + "It is not possible to archive location '%s' which has " + "associated stock quantities." % res[0].display_name + ) + ) + + @api.constrains("active") + def _check_active_stock_archive_constraint_stock_move(self): + res = self.env["stock.move"].search( + [ + "&", + ("state", "not in", ("done", "cancel")), + "|", + ("location_id", "in", self.filtered(lambda x: not x.active).ids), + ("location_id", "child_of", self.filtered(lambda x: not x.active).ids), + ], + limit=1, + ) + if res: + raise ValidationError( + _( + "It is not possible to archive location '%s' which has " + "associated picking lines." % res[0].display_name + ) + ) + + @api.constrains("active") + def _check_active_stock_archive_constraint_stock_move_line(self): + res = self.env["stock.move.line"].search( + [ + "&", + ("state", "not in", ("done", "cancel")), + "|", + ("location_id", "in", self.filtered(lambda x: not x.active).ids), + ("location_id", "child_of", self.filtered(lambda x: not x.active).ids), + ], + limit=1, + ) + if res: + raise ValidationError( + _( + "It is not possible to archive location '%s' which has " + "associated stock reservations." % res[0].display_name + ) + ) diff --git a/stock_archive_constraint/readme/CONTRIBUTORS.rst b/stock_archive_constraint/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..48848770a --- /dev/null +++ b/stock_archive_constraint/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Carlos Daudén + * Víctor Martínez diff --git a/stock_archive_constraint/readme/DESCRIPTION.rst b/stock_archive_constraint/readme/DESCRIPTION.rst new file mode 100644 index 000000000..ccdf56f17 --- /dev/null +++ b/stock_archive_constraint/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Allows to block archiving products with associated stock.quant or stock.move. +Allows to block archiving locations with associated stock.quant or stock.move. diff --git a/stock_archive_constraint/readme/USAGE.rst b/stock_archive_constraint/readme/USAGE.rst new file mode 100644 index 000000000..65f800d9d --- /dev/null +++ b/stock_archive_constraint/readme/USAGE.rst @@ -0,0 +1,2 @@ +#. Go to Settings > Users > Edit a user and check the "Manage Multiple Stock Locations" permission +#. Go to Inventory > Settings > Locations and disable one diff --git a/stock_archive_constraint/static/description/icon.png b/stock_archive_constraint/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_archive_constraint/static/description/icon.png differ diff --git a/stock_archive_constraint/static/description/index.html b/stock_archive_constraint/static/description/index.html new file mode 100644 index 000000000..ba4b0f795 --- /dev/null +++ b/stock_archive_constraint/static/description/index.html @@ -0,0 +1,437 @@ + + + + + + +Stock archive constraint + + + +
+

Stock archive constraint

+ + +

Production/Stable License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

Allows to block archiving products with associated stock.quant or stock.move. +Allows to block archiving locations with associated stock.quant or stock.move.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Settings > Users > Edit a user and check the “Manage Multiple Stock Locations” permission
  2. +
  3. Go to Inventory > Settings > Locations and disable one
  4. +
+
+
+

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 +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:

    +
    +
      +
    • Carlos Daudén
    • +
    • Víctor Martínez
    • +
    +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

victoralmau

+

This module is part of the OCA/stock-logistics-warehouse project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_archive_constraint/tests/__init__.py b/stock_archive_constraint/tests/__init__.py new file mode 100644 index 000000000..6712ad66e --- /dev/null +++ b/stock_archive_constraint/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import test_location_archive_constraint diff --git a/stock_archive_constraint/tests/test_location_archive_constraint.py b/stock_archive_constraint/tests/test_location_archive_constraint.py new file mode 100644 index 000000000..9b1f25dbb --- /dev/null +++ b/stock_archive_constraint/tests/test_location_archive_constraint.py @@ -0,0 +1,189 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo.exceptions import ValidationError +from odoo.tests.common import Form, SavepointCase + + +class TestLocationArchiveConstraint(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.env.ref("base.main_company") + cls.product_1 = cls._create_product(cls, "Product 1") + cls.product_2 = cls._create_product(cls, "Product 2") + stock_location_stock = cls.env.ref("stock.stock_location_stock") + cls.stock_location = cls._create_stock_location( + cls, "%s (Copy)" % (stock_location_stock.name) + ) + cls.stock_location_child = cls._create_stock_location( + cls, "%s (Child)" % (cls.stock_location.name) + ) + cls.stock_location_child.location_id = cls.stock_location + + def _create_product(self, name): + product_form = Form(self.env["product.product"]) + product_form.name = name + product_form.type = "product" + return product_form.save() + + def _create_stock_location(self, name): + stock_location_form = Form(self.env["stock.location"]) + stock_location_form.name = name + stock_location_form.usage = self.env.ref("stock.stock_location_stock").usage + return stock_location_form.save() + + def _create_stock_quant(self, location_id, product_id, qty): + self.env["stock.quant"].create( + { + "company_id": self.company.id, + "location_id": location_id.id, + "product_id": product_id.id, + "quantity": qty, + } + ) + + def _create_stock_move(self, location_id, location_dest_id, product_id, qty): + stock_move_form = Form(self.env["stock.move"]) + stock_move_form.name = product_id.display_name + stock_move_form.location_id = location_id + stock_move_form.location_dest_id = location_dest_id + stock_move_form.product_id = product_id + stock_move_form.product_uom_qty = qty + stock_move = stock_move_form.save() + stock_move._action_done() + + def _create_stock_move_line(self, location_id, location_dest_id, product_id, qty): + self.env["stock.move.line"].create( + { + "company_id": self.company.id, + "location_id": location_id.id, + "location_dest_id": location_dest_id.id, + "product_id": product_id.id, + "product_uom_qty": qty, + "product_uom_id": product_id.uom_id.id, + "qty_done": qty, + "state": "done", + } + ) + + def _create_stock_picking(self, location_id, location_dest_id, product_id, qty): + stock_picking_form = Form(self.env["stock.picking"]) + stock_picking_form.picking_type_id = self.env.ref("stock.picking_type_in") + with stock_picking_form.move_ids_without_package.new() as line: + line.product_id = product_id + line.product_uom_qty = qty + stock_picking = stock_picking_form.save() + stock_picking.write( + {"location_id": location_id.id, "location_dest_id": location_dest_id.id} + ) + stock_picking.action_confirm() + for line in stock_picking.move_ids_without_package: + line.quantity_done = line.product_uom_qty + stock_picking.button_validate() + + def test_archive_product_ok(self): + self.product_1.active = False + self.assertFalse(self.product_1.active) + self.product_2.active = False + self.assertFalse(self.product_2.active) + + def test_archive_unarchive_product(self): + self.product_1.active = False + self.assertFalse(self.product_1.active) + self.product_1.active = True + self.assertTrue(self.product_1.active) + + def test_archive_product_with_stock_move_in(self): + self._create_stock_move( + self.env.ref("stock.stock_location_suppliers"), + self.stock_location, + self.product_2, + 20.00, + ) + self.product_1.active = False + self.assertFalse(self.product_1.active) + with self.assertRaises(ValidationError): + self.product_2.active = False + + def test_archive_product_with_stock_move_line_in(self): + self._create_stock_move_line( + self.env.ref("stock.stock_location_suppliers"), + self.stock_location, + self.product_2, + 20.00, + ) + self.product_1.active = False + self.assertFalse(self.product_1.active) + with self.assertRaises(ValidationError): + self.product_2.active = False + + def test_archive_product_with_stock_picking_in(self): + self._create_stock_picking( + self.env.ref("stock.stock_location_suppliers"), + self.stock_location, + self.product_2, + 20.00, + ) + self.product_1.active = False + self.assertFalse(self.product_1.active) + with self.assertRaises(ValidationError): + self.product_2.active = False + + def test_archive_product_with_stock_picking_in_out(self): + self._create_stock_picking( + self.env.ref("stock.stock_location_suppliers"), + self.stock_location, + self.product_2, + 20.00, + ) + self._create_stock_picking( + self.stock_location, + self.env.ref("stock.stock_location_customers"), + self.product_2, + 20.00, + ) + self.product_1.active = False + self.assertFalse(self.product_1.active) + self.product_2.active = False + self.assertFalse(self.product_2.active) + + def test_archive_product_stock_location(self): + self._create_stock_quant(self.stock_location, self.product_2, 20.00) + self.product_1.active = False + self.assertFalse(self.product_1.active) + with self.assertRaises(ValidationError): + self.product_2.active = False + + def test_archive_product_stock_location_child(self): + self._create_stock_quant(self.stock_location_child, self.product_2, 20.00) + self.product_1.active = False + self.assertFalse(self.product_1.active) + with self.assertRaises(ValidationError): + self.product_2.active = False + + def test_archive_unarchive_stock_location(self): + self.stock_location.active = False + self.assertFalse(self.stock_location.active) + self.stock_location.active = True + self.assertTrue(self.stock_location.active) + + def test_archive_stock_location_ok(self): + self.stock_location.active = False + self.assertFalse(self.stock_location.active) + + def test_archive_stock_location(self): + self._create_stock_quant(self.stock_location, self.product_2, 20.00) + with self.assertRaises(ValidationError): + self.stock_location.with_context(do_not_check_quant=True).active = False + + def test_archive_unarchive_stock_location_child(self): + self.stock_location_child.active = False + self.assertFalse(self.stock_location_child.active) + self.stock_location_child.active = True + self.assertTrue(self.stock_location_child.active) + + def test_archive_stock_location_child(self): + self._create_stock_quant(self.stock_location_child, self.product_2, 20.00) + with self.assertRaises(ValidationError): + self.stock_location.with_context(do_not_check_quant=True).active = False