Skip to content
Snippets Groups Projects
Commit c1d63fc5 authored by Julien Castiaux's avatar Julien Castiaux
Browse files

[FIX] stock: scrap from current picking


Steps to reproduce:

1) Make sure you don't have any piece of the product you're about to
sell on hand.
2) Create two sale order, each with 10 pieces of the product and
validate them
3) Do a RFQ and buy 15 pieces.
4) On the earliest sale order, check the availability, it should
autofill the desired quantity with 10
5) Do the same on the second, it autofills 5.
6) On the later delivery, scrap one.
=> The product is scrapped from the early picking.

Sort the candidates so the current picking is on top, this ensure the
current picking is the first scraped.

opw-2036381

closes odoo/odoo#35021

Signed-off-by: default avatarArnold Moyaux <amoyaux@users.noreply.github.com>
parent 088edee2
No related branches found
No related tags found
No related merge requests found
......@@ -487,7 +487,7 @@ class StockMoveLine(models.Model):
if quantity > available_quantity:
# We now have to find the move lines that reserved our now unavailable quantity. We
# take care to exclude ourselves and the move lines were work had already been done.
oudated_move_lines_domain = [
outdated_move_lines_domain = [
('move_id.state', 'not in', ['done', 'cancel']),
('product_id', '=', product_id.id),
('lot_id', '=', lot_id.id if lot_id else False),
......@@ -497,14 +497,15 @@ class StockMoveLine(models.Model):
('product_qty', '>', 0.0),
('id', 'not in', ml_to_ignore.ids),
]
oudated_candidates = self.env['stock.move.line'].search(oudated_move_lines_domain)
current_picking_first = lambda cand: cand.picking_id != self.move_id.picking_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
# recompute the moves which we adapted their lines.
move_to_recompute_state = self.env['stock.move']
rounding = self.product_uom_id.rounding
for candidate in oudated_candidates:
for candidate in outdated_candidates:
if float_compare(candidate.product_qty, quantity, precision_rounding=rounding) <= 0:
quantity -= candidate.product_qty
move_to_recompute_state |= candidate.move_id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment