[FIX] stock: avoid putaway rules application with extra-SM
When receiving more than expected, we try to redirect the SM thanks to
the putaway rules. This can lead to undesirable behaviors.
To reproduce the issue:
1. In Settings, enable 'Storage Locations'
2. Create a storable product P
3. Edit the operation type "Receipt":
- Show Detailed Operations: True
4. Create and confirm a planned receipt for 1 x P
5. In the Detailed Operations:
- Set the done quantity to 3
- Set the destination location to Shelf 1
6. Validate the receipt
Error: The destination location of the SML has changed: Stock. It should
still be Shelf 1
When validating the SM, because the done quantity is more than the
demand, an exra-move is created. During such a process, the extra move
is confirmed and assigned, so it leads to the destination redirection
thanks to the putaway rules (that's the reason why the destination Stock
will be selected and defined on the SML).
In such situation, we should not try to apply the putaway rules.
OPW-2900283
closes odoo/odoo#96124
X-original-commit: 0183298293192538a801f52262c047ea34a1b76a
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
@@ -1641,7 +1641,7 @@ class StockMove(models.Model):
|
||||
precision_rounding=rounding,
|
||||
rounding_method='HALF-UP')
|
||||
extra_move_vals = self._prepare_extra_move_vals(extra_move_quantity)
|
||||
extra_move = self.copy(default=extra_move_vals)
|
||||
extra_move = self.copy(default=extra_move_vals).with_context(avoid_putaway_rules=True)
|
||||
|
||||
merge_into_self = all(self[field] == extra_move[field] for field in self._prepare_merge_moves_distinct_fields())
|
||||
|
||||
|
||||
@@ -226,6 +226,8 @@ class StockMoveLine(models.Model):
|
||||
packaging=self.move_id.product_packaging_id)
|
||||
|
||||
def _apply_putaway_strategy(self):
|
||||
if self._context.get('avoid_putaway_rules'):
|
||||
return
|
||||
self = self.with_context(do_not_unreserve=True)
|
||||
for package, smls in groupby(self, lambda sml: sml.result_package_id):
|
||||
smls = self.env['stock.move.line'].concat(*smls)
|
||||
|
||||
@@ -5771,3 +5771,26 @@ class StockMove(TransactionCase):
|
||||
})
|
||||
self.assertEqual(move.move_line_ids.location_id, self.stock_location)
|
||||
self.assertEqual(move.move_line_ids.location_dest_id, self.customer_location)
|
||||
|
||||
def test_receive_more_and_in_child_location(self):
|
||||
"""
|
||||
Ensure that, when receiving more than expected, and when the destination
|
||||
location of the SML is different from the SM one, the SM validation will
|
||||
not change the destination location of the SML
|
||||
"""
|
||||
move = self.env['stock.move'].create({
|
||||
'name': self.product.name,
|
||||
'location_id': self.supplier_location.id,
|
||||
'location_dest_id': self.stock_location.id,
|
||||
'product_id': self.product.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 1.0,
|
||||
})
|
||||
move._action_confirm()
|
||||
move.move_line_ids.write({
|
||||
'location_dest_id': self.stock_location.child_ids[0].id,
|
||||
'qty_done': 3,
|
||||
})
|
||||
move._action_done()
|
||||
self.assertEqual(move.move_line_ids.qty_done, 3)
|
||||
self.assertEqual(move.move_line_ids.location_dest_id, self.stock_location.child_ids[0])
|
||||
|
||||
Reference in New Issue
Block a user