From eb4f5fc929217dea7d97a66b6aeeaa8b0bd1e3f1 Mon Sep 17 00:00:00 2001 From: Walid Date: Sun, 7 Apr 2024 13:13:19 +0200 Subject: [PATCH] [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) Signed-off-by: Walid Hanniche (waha) --- addons/stock/models/stock_move.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 5a9bf1f94bc..e44b8a35a7e 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -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()