diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 8a439245a97..73d6300cd9c 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -208,6 +208,8 @@ class StockMoveLine(models.Model): packaging=self.move_id.product_packaging_id, additional_qty=additional_qty) def _get_default_dest_location(self): + if not self.user_has_groups('stock.group_stock_storage_categories'): + return self.location_dest_id[:1] if self.env.context.get('default_location_dest_id'): return self.env['stock.location'].browse([self.env.context.get('default_location_dest_id')]) return (self.move_id.location_dest_id or self.picking_id.location_dest_id or self.location_dest_id)[0] diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 24e686c8a07..a552e06891b 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -5476,3 +5476,40 @@ class StockMove(TransactionCase): self.assertEqual(move.reserved_availability, 2) # check forecast_availability expressed in product base uom self.assertEqual(move.forecast_availability, 24) + + def test_SML_location_selection(self): + """ + Suppose the setting 'Storage Categories' disabled and the option 'Show Detailed Operations' + for operation 'Internal Transfer' enabled. + A user creates an internal transfer from F to T, confirms it then adds a SML and selects + another destination location L (with L a child of T). When the user completes the field + `qty_done`, the onchange should n't change the destination location L + """ + + self.env.user.write({'groups_id': [(3, self.env.ref('stock.group_stock_storage_categories').id)]}) + internal_transfer = self.env.ref('stock.picking_type_internal') + internal_transfer.show_operations = True + + picking = self.env['stock.picking'].create({ + 'picking_type_id': internal_transfer.id, + 'location_id': self.stock_location.id, + 'location_dest_id': self.customer_location.id, + }) + self.env['stock.move'].create({ + 'name': self.product_consu.name, + 'product_id': self.product_consu.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 2.0, + 'picking_id': picking.id, + 'location_id': picking.location_id.id, + 'location_dest_id': picking.location_dest_id.id, + }) + + picking.action_confirm() + + with Form(picking) as form: + with form.move_line_ids_without_package.edit(0) as line: + line.location_dest_id = self.stock_location.child_ids[0] + line.qty_done = 1 + + self.assertEqual(picking.move_line_ids_without_package.location_dest_id, self.stock_location.child_ids[0])