From 82dea8f73450ce9ac98c0a2d878e6cc14558399f Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Tue, 30 Jul 2024 13:41:19 -0500 Subject: [PATCH] [MIG] stock_archive_constraint: Migration to 17.0 --- stock_archive_constraint/README.rst | 4 +++- stock_archive_constraint/__manifest__.py | 2 +- .../models/product_product.py | 9 +++++--- .../models/product_template.py | 12 ---------- .../models/stock_location.py | 9 +++++--- stock_archive_constraint/readme/USAGE.md | 3 ++- .../static/description/index.html | 4 +++- .../tests/test_location_archive_constraint.py | 22 +++++-------------- 8 files changed, 27 insertions(+), 38 deletions(-) delete mode 100644 stock_archive_constraint/models/product_template.py diff --git a/stock_archive_constraint/README.rst b/stock_archive_constraint/README.rst index c5ac3635e..d7278630e 100644 --- a/stock_archive_constraint/README.rst +++ b/stock_archive_constraint/README.rst @@ -42,7 +42,9 @@ Usage 1. Go to Settings > Users > Edit a user and check the "Manage Multiple Stock Locations" permission -2. Go to Inventory > Settings > Locations and disable one +2. Go to Inventory > Settings > Locations and archive one +3. Go to inventory > Products > Products and try to archive one product + associated to stock picking Bug Tracker =========== diff --git a/stock_archive_constraint/__manifest__.py b/stock_archive_constraint/__manifest__.py index 748084902..e787f23d5 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.2", + "version": "17.0.1.0.0", "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 49a488674..2e33b2457 100644 --- a/stock_archive_constraint/models/product_product.py +++ b/stock_archive_constraint/models/product_product.py @@ -29,7 +29,8 @@ class ProductProduct(models.Model): if res: raise ValidationError( _( - "It is not possible to archive product '%(display_name)s' which has " + "It is not possible to archive product " + "'%(display_name)s' which has " "associated stock quantities." ) % {"display_name": res.product_id.display_name} @@ -49,7 +50,8 @@ class ProductProduct(models.Model): if res: raise ValidationError( _( - "It is not possible to archive product '%(display_name)s' which has " + "It is not possible to archive product " + "'%(display_name)s' which has " "associated picking lines." ) % {"display_name": res.product_id.display_name} @@ -69,7 +71,8 @@ class ProductProduct(models.Model): if res: raise ValidationError( _( - "It is not possible to archive product '%(display_name)s' which has " + "It is not possible to archive product " + "'%(display_name)s' which has " "associated stock reservations." ) % {"display_name": res.product_id.display_name} diff --git a/stock_archive_constraint/models/product_template.py b/stock_archive_constraint/models/product_template.py deleted file mode 100644 index d6813c9f4..000000000 --- a/stock_archive_constraint/models/product_template.py +++ /dev/null @@ -1,12 +0,0 @@ -# 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 index 04ae12afe..996c900ce 100644 --- a/stock_archive_constraint/models/stock_location.py +++ b/stock_archive_constraint/models/stock_location.py @@ -31,7 +31,8 @@ class StockLocation(models.Model): if res: raise ValidationError( _( - "It is not possible to archive location '%(display_name)s' which has " + "It is not possible to archive location " + "'%(display_name)s' which has " "associated stock quantities." ) % {"display_name": res.display_name} @@ -54,7 +55,8 @@ class StockLocation(models.Model): if res: raise ValidationError( _( - "It is not possible to archive location '%(display_name)s' which has " + "It is not possible to archive location " + "'%(display_name)s' which has " "associated picking lines." ) % {"display_name": res.display_name} @@ -77,7 +79,8 @@ class StockLocation(models.Model): if res: raise ValidationError( _( - "It is not possible to archive location '%(display_name)s' which has " + "It is not possible to archive location " + "'%(display_name)s' which has " "associated stock reservations." ) % {"display_name": res.display_name} diff --git a/stock_archive_constraint/readme/USAGE.md b/stock_archive_constraint/readme/USAGE.md index b7ad3ecb8..19c317593 100644 --- a/stock_archive_constraint/readme/USAGE.md +++ b/stock_archive_constraint/readme/USAGE.md @@ -1,3 +1,4 @@ 1. Go to Settings \> Users \> Edit a user and check the "Manage Multiple Stock Locations" permission -2. Go to Inventory \> Settings \> Locations and disable one +2. Go to Inventory \> Settings \> Locations and archive one +3. Go to inventory \> Products \> Products and try to archive one product associated to stock picking diff --git a/stock_archive_constraint/static/description/index.html b/stock_archive_constraint/static/description/index.html index f9a40a6d9..7485a1f44 100644 --- a/stock_archive_constraint/static/description/index.html +++ b/stock_archive_constraint/static/description/index.html @@ -391,7 +391,9 @@ stock.quant or stock.move.

  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. +
  5. Go to Inventory > Settings > Locations and archive one
  6. +
  7. Go to inventory > Products > Products and try to archive one product +associated to stock picking
diff --git a/stock_archive_constraint/tests/test_location_archive_constraint.py b/stock_archive_constraint/tests/test_location_archive_constraint.py index 35cac97d0..151d39834 100644 --- a/stock_archive_constraint/tests/test_location_archive_constraint.py +++ b/stock_archive_constraint/tests/test_location_archive_constraint.py @@ -2,23 +2,15 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo.exceptions import ValidationError -from odoo.tests.common import Form, TransactionCase +from odoo.tests.common import Form + +from odoo.addons.base.tests.common import BaseCommon -class TestLocationArchiveConstraint(TransactionCase): +class TestLocationArchiveConstraint(BaseCommon): @classmethod def setUpClass(cls): super().setUpClass() - # Remove this variable in v16 and put instead: - # from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT - DISABLED_MAIL_CONTEXT = { - "tracking_disable": True, - "mail_create_nolog": True, - "mail_create_nosubscribe": True, - "mail_notrack": True, - "no_reset_password": True, - } - cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) cls.env = cls.env( context=dict(cls.env.context, test_stock_archive_constraint=True) ) @@ -58,7 +50,6 @@ class TestLocationArchiveConstraint(TransactionCase): 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 @@ -73,9 +64,8 @@ class TestLocationArchiveConstraint(TransactionCase): "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, + "quantity": qty, "state": "done", } ) @@ -92,7 +82,7 @@ class TestLocationArchiveConstraint(TransactionCase): ) stock_picking.action_confirm() for line in stock_picking.move_ids_without_package: - line.quantity_done = line.product_uom_qty + line.quantity = line.product_uom_qty stock_picking.button_validate() def test_archive_product_ok(self):