diff --git a/addons/stock_picking_batch/models/stock_picking.py b/addons/stock_picking_batch/models/stock_picking.py index b05e945cea1..dbeb3ef1852 100644 --- a/addons/stock_picking_batch/models/stock_picking.py +++ b/addons/stock_picking_batch/models/stock_picking.py @@ -117,8 +117,10 @@ class StockPicking(models.Model): picking._find_auto_batch() return res - def _action_done(self): - res = super()._action_done() + def button_validate(self): + res = super().button_validate() + if res is not True: + return res to_assign_ids = set() if self and self.env.context.get('pickings_to_detach'): self.env['stock.picking'].browse(self.env.context['pickings_to_detach']).batch_id = False diff --git a/addons/stock_picking_batch/tests/test_batch_picking.py b/addons/stock_picking_batch/tests/test_batch_picking.py index 844692fb053..e83afa6a953 100644 --- a/addons/stock_picking_batch/tests/test_batch_picking.py +++ b/addons/stock_picking_batch/tests/test_batch_picking.py @@ -621,6 +621,33 @@ class TestBatchPicking(TransactionCase): self.batch.write({'picking_ids': [[5, 0, 0]]}) self.assertEqual(self.batch.state, 'cancel', 'Batch Transfers should be cancelled when there are no transfers.') + def test_backorder_on_one_picking(self): + """ + Two pickings. The first only is fully done. The second one is not. The + user validates the batch without any backorder. Both pickings should be + done and still part of the batch + """ + self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 10.0) + self.env['stock.quant']._update_available_quantity(self.productB, self.stock_location, 8.0) + + self.batch.action_confirm() + + self.batch.action_assign() + self.picking_client_1.move_ids.quantity_done = 10 + self.picking_client_2.move_ids.quantity_done = 7 + + action = self.batch.action_done() + wizard = Form(self.env[action['res_model']].with_context(action['context'])).save() + wizard.process_cancel_backorder() + + self.assertEqual(self.picking_client_1.state, 'done') + self.assertEqual(self.picking_client_2.state, 'done') + self.assertEqual(self.batch.picking_ids, self.picking_client_1 | self.picking_client_2) + self.assertRecordValues(self.batch.move_ids.sorted('id'), [ + {'product_id': self.productA.id, 'product_uom_qty': 10.0, 'quantity_done': 10.0, 'state': 'done'}, + {'product_id': self.productB.id, 'product_uom_qty': 7.0, 'quantity_done': 7.0, 'state': 'done'}, + {'product_id': self.productB.id, 'product_uom_qty': 3.0, 'quantity_done': 0.0, 'state': 'cancel'}, + ]) @tagged('-at_install', 'post_install') class TestBatchPicking02(TransactionCase):