[FIX] stock_barcode: set procurement group on new moves

Steps to reproduce:
- Confirm an SO with a storable product
- in barcode app open the created picking
- Scan a different product confirm the picking and create a backorder

Bug:
the new product is not added to the SO and the original picking isn't
linked the SO anymore

Root cause:
when new moves are created in the inventory app default_picking_id
is set in the context and is used in _default_group_id to set the group

Fix:
explicitly set the group_id when creating the move instead of relying
on the defaults from the context when possible
test: https://github.com/odoo/enterprise/pull/57408

opw-3644773

closes odoo/odoo#160812

X-original-commit: adb072ce198454801d306df90f30a14a79e3dd3d
Related: odoo/enterprise#60200
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
Walid
2024-04-08 14:37:53 +00:00
parent 82bf645341
commit eb4f5fc929
+7
View File
@@ -607,6 +607,9 @@ Please change the quantity done or the rounding precision of your unit of measur
for vals in vals_list:
if (vals.get('quantity') or vals.get('move_line_ids')) and 'lot_ids' in vals:
vals.pop('lot_ids')
picking_id = self.env['stock.picking'].browse(vals.get('picking_id'))
if picking_id.group_id and 'group_id' not in vals:
vals['group_id'] = picking_id.group_id.id
return super().create(vals_list)
def write(self, vals):
@@ -648,6 +651,10 @@ Please change the quantity done or the rounding precision of your unit of measur
move_to_recompute_state |= self.filtered(lambda m: m.state not in ['draft', 'cancel', 'done'])
if 'location_dest_id' in vals:
move_to_check_dest_location = self.filtered(lambda m: m.location_dest_id.id != vals.get('location_dest_id'))
if 'picking_id' in vals and 'group_id' not in vals:
picking = self.env['stock.picking'].browse(vals['picking_id'])
if picking.group_id:
vals['group_id'] = picking.group_id.id
res = super(StockMove, self).write(vals)
if move_to_recompute_state:
move_to_recompute_state._recompute_state()