summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2020-04-20 09:04:58 +0000
committerNicolas Martinelli <nim@odoo.com>2020-04-21 08:23:30 +0000
commitcf078da86e2f0e5dd6b02ccbe91b7be2062c7559 (patch)
tree47d4132c5a143a9c4139b9b69228342079a52fab
parent9d312ac85b0f27c8946ca41b2acc2f7db0eb86d0 (diff)
[FIX] stock: unreserve picking with latest scheduled date
- Create a product P with 10 units on hand - Create a SO with 5 units, validate - Create another SO with 5 units, validate - Update the quantity on hand to 8 The picking linked to the first SO as 2 units unreserved, while one would expect the unreservation on the second picking. When unreserving, sort the move lines according to the picking scheduled date. The latest schedule date comes first. opw-2233331 closes odoo/odoo#49830 X-original-commit: 41c05cbfb015407dbbf7100233999ecd154267dc Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
-rw-r--r--addons/stock/models/stock_move_line.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py
index 86e33b9cadc..8abf7a9e55f 100644
--- a/addons/stock/models/stock_move_line.py
+++ b/addons/stock/models/stock_move_line.py
@@ -563,7 +563,13 @@ class StockMoveLine(models.Model):
('product_qty', '>', 0.0),
('id', 'not in', ml_to_ignore.ids),
]
- current_picking_first = lambda cand: cand.picking_id != self.move_id.picking_id
+ # We take the current picking first, then the pickings with the latest scheduled date
+ current_picking_first = lambda cand: (
+ cand.picking_id != self.move_id.picking_id,
+ -(cand.picking_id.scheduled_date or cand.move_id.date_expected).timestamp()
+ if cand.picking_id or cand.move_id
+ else -cand.id,
+ )
outdated_candidates = self.env['stock.move.line'].search(outdated_move_lines_domain).sorted(current_picking_first)
# As the move's state is not computed over the move lines, we'll have to manually