From 3ea3b6a9a1d8be4f37d82efe6da889c3a399a71c Mon Sep 17 00:00:00 2001 From: clesgow Date: Thu, 24 Feb 2022 09:50:11 +0000 Subject: [PATCH] [FIX] stock_picking_batch: Fix batched pickings validation If a picking is in a batch, the point is to process it as a whole. Yet, it is possible to validate a single picking (putting it in a 'done' state), inside of an 'in_progress' batch. This raises inconsistencies between the state of the batch as a whole and the state of some of it pickings. Therefore, when a single batched picking is validated in a batch that still contains other non-done pickings, the picking is removed from the batch. closes odoo/odoo#85324 X-original-commit: e9602d6b28331f68a83b5ce8a06a2ffc8ac3453d Signed-off-by: Arnold Moyaux Signed-off-by: Quentin Wolfs (quwo) --- addons/stock_picking_batch/models/stock_picking.py | 8 ++++++++ addons/stock_picking_batch/tests/test_batch_picking.py | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/addons/stock_picking_batch/models/stock_picking.py b/addons/stock_picking_batch/models/stock_picking.py index 67f9551d8ac..be8f0ffeb27 100644 --- a/addons/stock_picking_batch/models/stock_picking.py +++ b/addons/stock_picking_batch/models/stock_picking.py @@ -119,6 +119,14 @@ class StockPicking(models.Model): picking._find_auto_batch() return res + def _action_done(self): + res = super()._action_done() + for picking in self: + if picking.batch_id and any(picking.state != 'done' for picking in picking.batch_id.picking_ids): + picking.batch_id = None + + return res + def _should_show_transfers(self): if len(self.batch_id) == 1 and self == self.batch_id.picking_ids: return False diff --git a/addons/stock_picking_batch/tests/test_batch_picking.py b/addons/stock_picking_batch/tests/test_batch_picking.py index 5943e65e1d2..54d932ed231 100644 --- a/addons/stock_picking_batch/tests/test_batch_picking.py +++ b/addons/stock_picking_batch/tests/test_batch_picking.py @@ -449,3 +449,8 @@ class TestBatchPicking(TransactionCase): self.assertTrue(picking_out_3.batch_id) self.assertEqual(picking_out_1.batch_id.id, picking_out_3.batch_id.id) self.assertFalse(picking_out_2.batch_id) + # If Picking 1 is validated without Picking 3, Picking 1 should be removed from the batch + picking_out_1.move_ids.quantity_done = 10 + picking_out_1.button_validate() + self.assertFalse(picking_out_1.batch_id) + self.assertEqual(len(picking_out_3.batch_id.picking_ids), 1)