[FIX] stock_picking_batch: cancel confirmed batches without transfers

Steps to reproduce the bug:
- Create a batch transfer with several pickings
- Confirm it
- Delete all the pickings > save

Problem:
The batch does not cancel as it should’ve been
A batch without transfers cannot be confirmed, so it makes no sense to leave a confirmed batch without transfers

opw-2792471

closes odoo/odoo#90104

X-original-commit: dcbf08edbb3a1ec49e84f0828b8f49ac4f836c25
Signed-off-by: Steve Van Essche <svs@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2022-04-29 13:13:15 +02:00
parent 2eb23cccfb
commit b2f1d28b39
2 changed files with 11 additions and 0 deletions
@@ -167,6 +167,8 @@ class StockPickingBatch(models.Model):
def write(self, vals):
res = super().write(vals)
if not self.picking_ids and self.state == 'in_progress':
self.action_cancel()
if vals.get('picking_type_id'):
self._sanity_check()
if vals.get('picking_ids'):
@@ -454,3 +454,12 @@ class TestBatchPicking(TransactionCase):
picking_out_1.button_validate()
self.assertFalse(picking_out_1.batch_id)
self.assertEqual(len(picking_out_3.batch_id.picking_ids), 1)
def test_remove_all_transfers_from_confirmed_batch(self):
"""
Check that the batch is canceled when all transfers are deleted
"""
self.batch.action_confirm()
self.assertEqual(self.batch.state, 'in_progress', 'Batch Transfers should be in progress.')
self.batch.write({'picking_ids': [[5, 0, 0]]})
self.assertEqual(self.batch.state, 'cancel', 'Batch Transfers should be cancelled when there are no transfers.')