diff --git a/setup/shopfloor_location_product_restriction/odoo/addons/shopfloor_location_product_restriction b/setup/shopfloor_location_product_restriction/odoo/addons/shopfloor_location_product_restriction new file mode 120000 index 00000000000..02ac201459c --- /dev/null +++ b/setup/shopfloor_location_product_restriction/odoo/addons/shopfloor_location_product_restriction @@ -0,0 +1 @@ +../../../../shopfloor_location_product_restriction \ No newline at end of file diff --git a/setup/shopfloor_location_product_restriction/setup.py b/setup/shopfloor_location_product_restriction/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/shopfloor_location_product_restriction/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/shopfloor_location_product_restriction/README.rst b/shopfloor_location_product_restriction/README.rst new file mode 100644 index 00000000000..40c63102627 --- /dev/null +++ b/shopfloor_location_product_restriction/README.rst @@ -0,0 +1,98 @@ +====================================== +Shopfloor Location Product Restriction +====================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6df96d9c5d54ab6d5f716fba6e9f6845cec34af57c993be24f5eb03c01e8f70c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fwms-lightgray.png?logo=github + :target: https://github.com/OCA/wms/tree/16.0/shopfloor_location_product_restriction + :alt: OCA/wms +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/wms-16-0/wms-16-0-shopfloor_location_product_restriction + :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/wms&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to display an error to the operator as soon as +destination is filled in in scenarios if a location product restriction +is defined on the scanned destination location. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +When operators use scenarios that does not validate the movement at the +end of the flow, but allows to validate the picking later (e.g.: +receptions), the user won't have an error before. + +Configuration +============= + +See ``stock_location_product_restriction`` module. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Denis Roussel denis.roussel@acsone.eu + +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-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px + :target: https://github.com/rousseldenis + :alt: rousseldenis + +Current `maintainer `__: + +|maintainer-rousseldenis| + +This module is part of the `OCA/wms `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/shopfloor_location_product_restriction/__init__.py b/shopfloor_location_product_restriction/__init__.py new file mode 100644 index 00000000000..99464a7510b --- /dev/null +++ b/shopfloor_location_product_restriction/__init__.py @@ -0,0 +1 @@ +from . import services diff --git a/shopfloor_location_product_restriction/__manifest__.py b/shopfloor_location_product_restriction/__manifest__.py new file mode 100644 index 00000000000..be10a6773de --- /dev/null +++ b/shopfloor_location_product_restriction/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopfloor Location Product Restriction", + "summary": """This module allows to check location product + restriction in shopfloor flows""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "maintainers": ["rousseldenis"], + "website": "https://github.com/OCA/wms", + "depends": [ + "shopfloor", + "stock_location_product_restriction", + ], +} diff --git a/shopfloor_location_product_restriction/readme/CONFIGURE.md b/shopfloor_location_product_restriction/readme/CONFIGURE.md new file mode 100644 index 00000000000..674410423bb --- /dev/null +++ b/shopfloor_location_product_restriction/readme/CONFIGURE.md @@ -0,0 +1 @@ +See `stock_location_product_restriction` module. diff --git a/shopfloor_location_product_restriction/readme/CONTEXT.md b/shopfloor_location_product_restriction/readme/CONTEXT.md new file mode 100644 index 00000000000..1f18cd027f7 --- /dev/null +++ b/shopfloor_location_product_restriction/readme/CONTEXT.md @@ -0,0 +1,3 @@ +When operators use scenarios that does not validate the movement at the end of the flow, +but allows to validate the picking later (e.g.: receptions), the user won't have +an error before. diff --git a/shopfloor_location_product_restriction/readme/CONTRIBUTORS.md b/shopfloor_location_product_restriction/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..4e7e6847269 --- /dev/null +++ b/shopfloor_location_product_restriction/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Denis Roussel diff --git a/shopfloor_location_product_restriction/readme/DESCRIPTION.md b/shopfloor_location_product_restriction/readme/DESCRIPTION.md new file mode 100644 index 00000000000..5474f489b4c --- /dev/null +++ b/shopfloor_location_product_restriction/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module allows to display an error to the operator as soon as destination +is filled in in scenarios if a location product restriction is defined on the +scanned destination location. diff --git a/shopfloor_location_product_restriction/services/__init__.py b/shopfloor_location_product_restriction/services/__init__.py new file mode 100644 index 00000000000..72d6086eee6 --- /dev/null +++ b/shopfloor_location_product_restriction/services/__init__.py @@ -0,0 +1 @@ +from . import service diff --git a/shopfloor_location_product_restriction/services/service.py b/shopfloor_location_product_restriction/services/service.py new file mode 100644 index 00000000000..66be59d4ac9 --- /dev/null +++ b/shopfloor_location_product_restriction/services/service.py @@ -0,0 +1,20 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.component.core import AbstractComponent + + +class BaseShopfloorProcess(AbstractComponent): + _inherit = "base.shopfloor.process" + + def is_dest_location_valid(self, moves, location, pick_type=False): + """ + Check if destination location is restricted for + current moves + """ + result = super().is_dest_location_valid(moves, location, pick_type=pick_type) + for move in moves: + if location._check_has_location_product_restriction(move.product_id): + return bool(False and result) + + return result diff --git a/shopfloor_location_product_restriction/static/description/icon.png b/shopfloor_location_product_restriction/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/shopfloor_location_product_restriction/static/description/icon.png differ diff --git a/shopfloor_location_product_restriction/static/description/index.html b/shopfloor_location_product_restriction/static/description/index.html new file mode 100644 index 00000000000..0dcb1fb2878 --- /dev/null +++ b/shopfloor_location_product_restriction/static/description/index.html @@ -0,0 +1,439 @@ + + + + + +Shopfloor Location Product Restriction + + + +
+

Shopfloor Location Product Restriction

+ + +

Beta License: AGPL-3 OCA/wms Translate me on Weblate Try me on Runboat

+

This module allows to display an error to the operator as soon as +destination is filled in in scenarios if a location product restriction +is defined on the scanned destination location.

+

Table of contents

+ +
+

Use Cases / Context

+

When operators use scenarios that does not validate the movement at the +end of the flow, but allows to validate the picking later (e.g.: +receptions), the user won’t have an error before.

+
+
+

Configuration

+

See stock_location_product_restriction module.

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

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:

+

rousseldenis

+

This module is part of the OCA/wms project on GitHub.

+

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

+
+
+
+ + diff --git a/shopfloor_location_product_restriction/tests/__init__.py b/shopfloor_location_product_restriction/tests/__init__.py new file mode 100644 index 00000000000..ef2ff366dfb --- /dev/null +++ b/shopfloor_location_product_restriction/tests/__init__.py @@ -0,0 +1 @@ +from . import test_shopfloor_product_restriction diff --git a/shopfloor_location_product_restriction/tests/test_shopfloor_product_restriction.py b/shopfloor_location_product_restriction/tests/test_shopfloor_product_restriction.py new file mode 100644 index 00000000000..1e0b91e0ea5 --- /dev/null +++ b/shopfloor_location_product_restriction/tests/test_shopfloor_product_restriction.py @@ -0,0 +1,164 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.addons.shopfloor_base.tests.common import CommonCase + + +class TestStockLocation(CommonCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.StockLocation = cls.env["stock.location"] + + cls.menu = cls.env.ref( + "shopfloor.shopfloor_menu_demo_location_content_transfer" + ) + cls.profile = cls.env.ref("shopfloor_base.profile_demo_1") + cls.picking_type = cls.menu.sudo().picking_type_ids + cls.wh = cls.picking_type.warehouse_id + cls.StockLocation = cls.StockLocation.sudo() + cls.move_obj = cls.env["stock.move"] + cls.StockLocation._parent_store_compute() + cls.loc_lvl = cls.env.ref("stock.stock_location_locations") + cls.loc_lvl_1 = cls.StockLocation.create( + {"name": "level_1", "location_id": cls.loc_lvl.id} + ) + cls.loc_lvl_1_1 = cls.StockLocation.create( + {"name": "level_1_1", "location_id": cls.loc_lvl_1.id} + ) + + cls.loc_lvl_1_1_1 = cls.StockLocation.create( + {"name": "level_1_1_1", "location_id": cls.loc_lvl_1_1.id} + ) + cls.loc_lvl_1_1_2 = cls.StockLocation.create( + {"name": "level_1_1_1", "location_id": cls.loc_lvl_1_1.id} + ) + cls.default_product_restriction = "any" + + # products + Product = cls.env["product.product"].sudo() + cls.uom_unit = cls.env.ref("uom.product_uom_unit") + cls.product_1 = Product.create( + {"name": "Wood", "type": "product", "uom_id": cls.uom_unit.id} + ) + cls.product_2 = Product.create( + {"name": "Stone", "type": "product", "uom_id": cls.uom_unit.id} + ) + + # # quants + # StockQuant = cls.env["stock.quant"].sudo() + # cls.quant_1_lvl_1_1_1 = StockQuant.create( + # { + # "product_id": cls.product_1.id, + # "location_id": cls.loc_lvl_1_1_1.id, + # "quantity": 10.0, + # "owner_id": cls.env.user.id, + # } + # ) + # cls.quant_2_lvl_1_1_1 = StockQuant.create( + # { + # "product_id": cls.product_2.id, + # "location_id": cls.loc_lvl_1_1_1.id, + # "quantity": 10.0, + # "owner_id": cls.env.user.id, + # } + # ) + # cls.quant_1_lvl_1_1_2 = StockQuant.create( + # { + # "product_id": cls.product_1.id, + # "location_id": cls.loc_lvl_1_1_2.id, + # "quantity": 10.0, + # "owner_id": cls.env.user.id, + # } + # ) + # cls.quant_2_lvl_1_1_2 = StockQuant.create( + # { + # "product_id": cls.product_2.id, + # "location_id": cls.loc_lvl_1_1_2.id, + # "quantity": 10.0, + # "owner_id": cls.env.user.id, + # } + # ) + + def setUp(self): + super().setUp() + self.service = self.get_service( + "location_content_transfer", menu=self.menu, profile=self.profile + ) + self.stock_action = self.service._actions_for("stock") + + def test_set_destination(self): + # Put product 1 in location 1-1-2 + # Put product 2 in location 1-1-1 + + # Enable restriction on 1-1-2 + # Try to transfer location 1-1-1 to 1-1-2 + manager = ( + self.env["res.users"] + .sudo() + .create({"name": "Manager", "login": "stock_manager"}) + ) + manager.groups_id |= self.env.ref("stock.group_stock_manager") + self.env.user.groups_id |= self.env.ref("stock.group_stock_user") + self.env["stock.quant"].with_user(manager).with_context( + inventory_mode=True + ).create( + { + "product_id": self.product_2.id, + "inventory_quantity": 10.0, + "location_id": self.loc_lvl_1_1_1.id, + } + )._apply_inventory() + self.env["stock.quant"].with_user(manager).with_context( + inventory_mode=True + ).create( + { + "product_id": self.product_1.id, + "inventory_quantity": 10.0, + "location_id": self.loc_lvl_1_1_2.id, + } + )._apply_inventory() + self.loc_lvl_1_1_2.barcode = "LVL_1_1_2" + self.loc_lvl_1_1_1.barcode = "LVL_1_1_1" + self.move = self.move_obj.create( + { + "name": "Level 1-1-1 -> Level 1-1-2", + "location_id": self.loc_lvl_1_1_2.id, + "location_dest_id": self.loc_lvl_1_1_1.id, + "product_id": self.product_1.id, + "product_uom": self.product_1.uom_id.id, + "product_uom_qty": 5.0, + "picking_type_id": self.env.ref("stock.picking_type_internal").id, + } + ) + + self.move._action_confirm() + self.move._action_assign() + self.move._assign_picking() + + # Assign user to move + self.move.move_line_ids.qty_done = 5.0 + self.move.picking_id.user_id = self.env.user + + self.loc_lvl_1_1_1.product_restriction = "same" + response = self.service.dispatch( + "set_destination_all", + params={ + "location_id": self.loc_lvl_1_1_2.id, + "barcode": self.loc_lvl_1_1_1.barcode, + }, + ) + + self.assertEqual( + "You cannot place it here", response.get("message").get("body") + ) + self.loc_lvl_1_1_1.product_restriction = "any" + self.loc_lvl_1_1_1.invalidate_recordset() + response = self.service.dispatch( + "set_destination_all", + params={ + "location_id": self.loc_lvl_1_1_2.id, + "barcode": self.loc_lvl_1_1_1.barcode, + }, + ) + + self.assertEqual("scan_location", response.get("next_state")) diff --git a/test-requirements.txt b/test-requirements.txt index 689482e20df..d0cc876eaf7 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,2 +1,5 @@ vcrpy-unittest odoo_test_helper + +odoo-addon-shopfloor @ git+https://github.com/OCA/wms@refs/pull/1097/head#subdirectory=setup/shopfloor +odoo-addon-stock-location-product-restriction @ git+https://github.com/OCA/stock-logistics-warehouse@refs/pull/2342/head#subdirectory=setup/stock_location_product_restriction