From 56719fc3801796e73e9f8b0214db8a4f8ea5495c Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Thu, 10 Feb 2022 13:25:20 +0000 Subject: [PATCH] [FIX] stock: select dest location of a SML On a SML, when setting the done quantity, the onchange may change the destination location selected by the user To reproduce the issue: 1. In Settings: - Enable "Storage Locations" - (Then, ensure "Storage Categories" is disabled) 2. Inventory > Operations Types, edit "Internal Transfers": - Enable "Show Detailed Operations" 3. Create an internal transfer IT: - From: WH/Stock - To: WH/Stock 4. Add a detailed operations to IT: - Product: anyone - To: WH/Stock/Shelf 1 - Done: 1 Error: One the field "Done" is modified, the "To" changes and becomes "WH/Stock". This location should not change (it should be "WH/Stock/Shelf 1") When setting the done quantity, an onchange recomputes the destination location of the SML. To do so, it uses a initial location and searches among its children. Here is the issue: when "Storage Categories" is disabled, this initial location should be the one selected by the user. OPW-2704665 closes odoo/odoo#85151 X-original-commit: 4202e46a8313fa9f1487d372ef0cb771f769be8d Signed-off-by: Arnold Moyaux Signed-off-by: Adrien Widart --- addons/stock/models/stock_move_line.py | 2 ++ addons/stock/tests/test_move.py | 37 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) 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])