From e310d92958ab63501b134d7b2db2d5035cbf7975 Mon Sep 17 00:00:00 2001 From: yhu-odoo Date: Mon, 22 Mar 2021 10:37:59 +0000 Subject: [PATCH] [IMP] stock_picking_batch: cancel empty batch picking As pickings can be moved from a batch into an another one, a batch can suddenly be emptied or having no more active pickings.In such case, we cancel it. This way, empty batches won't be displayed by default as there is a default filter showing only draft or in progress batches. If we manually remove all pickings from a batch or create a empty batch, we consider it intentional, and won't cancel it automatically. Task-2464457 PR #66600 Signed-off-by: Arnold Moyaux --- .../data/stock_picking_batch_demo.xml | 26 +++++++++---------- .../models/stock_picking.py | 2 ++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/stock_picking_batch/data/stock_picking_batch_demo.xml b/addons/stock_picking_batch/data/stock_picking_batch_demo.xml index 4cce07a501a..308639bc0e7 100644 --- a/addons/stock_picking_batch/data/stock_picking_batch_demo.xml +++ b/addons/stock_picking_batch/data/stock_picking_batch_demo.xml @@ -1,15 +1,5 @@ - - - - - - - - - - @@ -40,7 +30,6 @@ 1 - @@ -50,7 +39,6 @@ 0 - @@ -60,7 +48,6 @@ 0 - @@ -70,12 +57,23 @@ 1 - + + + + + + + + + + + + A first stock move diff --git a/addons/stock_picking_batch/models/stock_picking.py b/addons/stock_picking_batch/models/stock_picking.py index be5bb59f290..52d994787ed 100644 --- a/addons/stock_picking_batch/models/stock_picking.py +++ b/addons/stock_picking_batch/models/stock_picking.py @@ -21,8 +21,10 @@ class StockPicking(models.Model): return res def write(self, vals): + batches = self.batch_id res = super().write(vals) if vals.get('batch_id'): + batches.filtered(lambda b: not b.picking_ids).state = 'cancel' if not self.batch_id.picking_type_id: self.batch_id.picking_type_id = self.picking_type_id[0] self.batch_id._sanity_check()