[FIX] stock: fix batch transfer validation

Steps to reproduce the bug:
- Go to inventory > operation > batch Transfer > new:
    - Select 2 picking out
- Confirm
- Try to validate

Problem:
A traceback is triggered:
ValueError: Expected singleton: stock.picking(7, 2)

“self.hide_picking_type = self.state != "draft" and self.ids and
'default_picking_type_id' in self.env.context “

opw-3583908

closes odoo/odoo#141975

Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Djamel Touati
2023-11-14 13:49:30 +00:00
parent 5094cdcc9d
commit 1b1d2d110e
2 changed files with 30 additions and 1 deletions
+2 -1
View File
@@ -546,7 +546,8 @@ class Picking(models.Model):
@api.depends('state')
def _compute_hide_picking_type(self):
self.hide_picking_type = self.state != "draft" and self.ids and 'default_picking_type_id' in self.env.context
for picking in self:
picking.hide_picking_type = picking.state != "draft" and picking.ids and 'default_picking_type_id' in picking.env.context
@api.depends('move_ids.delay_alert_date')
def _compute_delay_alert_date(self):
+28
View File
@@ -1606,3 +1606,31 @@ class TestPacking(TestPackingCommon):
})
picking_03.action_confirm()
self.assertEqual(move_03.move_line_ids.result_package_id, pack_2)
def test_compute_hide_picking_type_multiple_records(self):
"""
Create two pickings and compute their respective hide picking types together.
"""
picking1 = self.env['stock.picking'].create({
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
'picking_type_id': self.env.ref('stock.picking_type_out').id,
})
self.env['stock.move'].create({
'name': self.productA.name,
'product_id': self.productA.id,
'product_uom_qty': 10,
'product_uom': self.productA.uom_id.id,
'picking_id': picking1.id,
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
})
picking1.action_confirm()
picking2 = self.env['stock.picking'].create({
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
'picking_type_id': self.env.ref('stock.picking_type_out').id,
})
(picking1 | picking2).with_context(default_picking_type_id=self.ref('stock.picking_type_out'))._compute_hide_picking_type()
self.assertTrue(picking1.hide_picking_type)
self.assertFalse(picking2.hide_picking_type)