diff --git a/stock_restrict_lot/README.rst b/stock_restrict_lot/README.rst index e2933078ad57..8730f1040f62 100644 --- a/stock_restrict_lot/README.rst +++ b/stock_restrict_lot/README.rst @@ -7,7 +7,7 @@ Stock Restrict Lot !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:eda908988d0c0cca699354725723eb9100a2f990718c4961eb3713121f51da5d + !! source digest: sha256:f758aba4cb49703bdebb2d5df39af78820093588d52f5b031e7c721c32a65b8b !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -62,6 +62,12 @@ Contributors * Florian da Costa * Michael Tietz (MT Software) +* Ooops404 + +* PyTech SRL + + * Alessandro Uffreduzzi + Maintainers ~~~~~~~~~~~ diff --git a/stock_restrict_lot/models/stock_move.py b/stock_restrict_lot/models/stock_move.py index 51e1e786cc1b..5bd92407e64b 100644 --- a/stock_restrict_lot/models/stock_move.py +++ b/stock_restrict_lot/models/stock_move.py @@ -1,6 +1,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import _, api, exceptions, fields, models +from odoo.exceptions import UserError class StockMove(models.Model): @@ -92,3 +93,26 @@ def _split(self, qty, restrict_partner_id=False): if vals_list and self.restrict_lot_id: vals_list[0]["restrict_lot_id"] = self.restrict_lot_id.id return vals_list + + def _action_done(self, cancel_backorder=False): + res = super()._action_done(cancel_backorder=cancel_backorder) + self._check_lot_consistent_with_restriction() + return res + + def _check_lot_consistent_with_restriction(self): + """ + Check that the lot set on move lines + is the same as the restricted lot set on the move + """ + for move in self.filtered(lambda x: x.restrict_lot_id and x.move_line_ids): + move_line_lot = move.mapped("move_line_ids.lot_id") + if move.restrict_lot_id != move_line_lot: + raise UserError( + _( + "The lot(s) %(move_line_lot)s being moved is " + "inconsistent with the restriction on " + "lot %(move_restrict_lot)s set on the move", + move_line_lot=", ".join(x.display_name for x in move_line_lot), + move_restrict_lot=move.restrict_lot_id.display_name, + ) + ) diff --git a/stock_restrict_lot/readme/CONTRIBUTORS.rst b/stock_restrict_lot/readme/CONTRIBUTORS.rst index 415bc8135b33..8c36602d20ec 100644 --- a/stock_restrict_lot/readme/CONTRIBUTORS.rst +++ b/stock_restrict_lot/readme/CONTRIBUTORS.rst @@ -1,2 +1,8 @@ * Florian da Costa * Michael Tietz (MT Software) + +* Ooops404 + +* PyTech SRL + + * Alessandro Uffreduzzi diff --git a/stock_restrict_lot/static/description/index.html b/stock_restrict_lot/static/description/index.html index 85d55cea2ef4..f558c40d0391 100644 --- a/stock_restrict_lot/static/description/index.html +++ b/stock_restrict_lot/static/description/index.html @@ -367,7 +367,7 @@

Stock Restrict Lot

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:eda908988d0c0cca699354725723eb9100a2f990718c4961eb3713121f51da5d +!! source digest: sha256:f758aba4cb49703bdebb2d5df39af78820093588d52f5b031e7c721c32a65b8b !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/stock-logistics-workflow Translate me on Weblate Try me on Runboat

This module add a field to restrict a stock move to a specific lot. @@ -407,6 +407,11 @@

Contributors

diff --git a/stock_restrict_lot/tests/test_restrict_lot.py b/stock_restrict_lot/tests/test_restrict_lot.py index afd1e96ec556..b1a22d50d9b5 100644 --- a/stock_restrict_lot/tests/test_restrict_lot.py +++ b/stock_restrict_lot/tests/test_restrict_lot.py @@ -1,5 +1,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.exceptions import UserError from odoo.tests.common import SavepointCase @@ -271,3 +272,40 @@ def test_compute_quantites(self): product.invalidate_cache() product = product.with_context(lot_id=lot2.id) self.assertEqual(product.outgoing_qty, 1) + + def test_move_validation_inconsistent_lot(self): + lot2 = self.env["stock.production.lot"].create( + { + "name": "lot2", + "product_id": self.product.id, + "company_id": self.warehouse.company_id.id, + } + ) + self._update_product_stock(1, lot2.id) + + move = self.env["stock.move"].create( + { + "product_id": self.product.id, + "location_id": self.warehouse.lot_stock_id.id, + "location_dest_id": self.customer_loc.id, + "product_uom_qty": 1, + "product_uom": self.product.uom_id.id, + "name": "test", + "warehouse_id": self.warehouse.id, + "restrict_lot_id": self.lot.id, + } + ) + move_line = self.env["stock.move.line"].create( + { + "move_id": move.id, + "product_id": move.product_id.id, + "qty_done": 1, + "product_uom_id": move.product_uom.id, + "location_id": move.location_id.id, + "location_dest_id": move.location_dest_id.id, + "lot_id": lot2.id, + } + ) + self.assertRaises(UserError, move._action_done) + move_line.lot_id = self.lot + move._action_done()