[FIX] stock: skip putaway rule if dest loc set by user

To reproduce the issue:
1. In Settings, enable:
   - Storage Locations
   - Storage Categories
2. Create and confirm a receipt with one product
3. Open the detailed operation
4. Add a line
   - To: WH/Stock/Shelf 1
   - Done: 1

Error: Once the user sets the done quantity to 1, the destination
location will be automatically set to WH/Stock

Since the Storage Locations option is enabled, when updating the
done quantity of the SML, it triggers an onchange in charge of
applying the putaway rules. Since the Storage Categories option is
enabled, the putaway process starts from the SM's location (i.e.
WH/Stock). Then, since there isn't any putaway rule, the process
will simply return the initial location (WH/Stock) and we will use
it as new destination location of the SML.

Since the destination location has already been set by the user, we
should avoid overriding it, otherwise he will have to set the
location again.

OPW-3511560
OPW-3549579

closes odoo/odoo#141252

X-original-commit: ce9a1437de0093dd3c66152148d4c973915d00f4
Signed-off-by: Quentin Wolfs (quwo) <quwo@odoo.com>
Signed-off-by: Adrien Widart (awt) <awt@odoo.com>
This commit is contained in:
Adrien Widart (awt)
2023-11-06 16:55:48 +00:00
parent 861290ce40
commit b7335cb75d
2 changed files with 42 additions and 2 deletions
+3 -2
View File
@@ -228,8 +228,9 @@ class StockMoveLine(models.Model):
@api.onchange('result_package_id', 'product_id', 'product_uom_id', 'quantity')
def _onchange_putaway_location(self):
if not self.id and self.user_has_groups('stock.group_stock_multi_locations') and self.product_id and self.quantity_product_uom:
default_dest_location = self._get_default_dest_location()
default_dest_location = self._get_default_dest_location()
if not self.id and self.user_has_groups('stock.group_stock_multi_locations') and self.product_id and self.quantity_product_uom \
and self.location_dest_id == default_dest_location:
quantity = self.quantity_product_uom
self.location_dest_id = default_dest_location.with_context(exclude_sml_ids=self.ids)._get_putaway_strategy(
self.product_id, quantity=quantity, package=self.result_package_id,
+39
View File
@@ -6157,3 +6157,42 @@ class StockMove(TransactionCase):
self.assertEqual(receipt.state, 'done')
self.assertEqual(len(receipt.move_line_ids), 1)
self.assertEqual(receipt.move_line_ids.quantity, 1)
def test_skip_putaway_if_dest_loc_set_by_user(self):
"""
Suppose the putaway rules and storage categories enabled. On the
detailed operations, the user adds a new line, set a specific
destination location and then the done quantity. In such cases, since
the user has defined himself the destination location, we should not try
to apply any putaway rule that would override his choice.
"""
self.env.user.write({'groups_id': [(4, self.env.ref('stock.group_stock_storage_categories').id)]})
child_location = self.stock_location.child_ids[0]
in_type = self.env.ref('stock.picking_type_in')
in_type.show_operations = True
receipt = self.env['stock.picking'].create({
'location_id': self.customer_location.id,
'location_dest_id': self.stock_location.id,
'picking_type_id': in_type.id,
'move_ids': [(0, 0, {
'name': self.product.name,
'location_id': self.customer_location.id,
'location_dest_id': self.stock_location.id,
'product_id': self.product.id,
'product_uom': self.product.uom_id.id,
'product_uom_qty': 2.0,
})],
})
receipt.action_confirm()
with Form(receipt.move_ids, view='stock.view_stock_move_operations') as move_form:
with move_form.move_line_ids.edit(0) as line:
line.location_dest_id = child_location
line.quantity = 2
self.assertRecordValues(receipt.move_ids.move_line_ids[-1], [
{'location_dest_id': child_location.id, 'product_id': self.product.id, 'quantity': 2},
])