[FIX] rma_sale: chained returns

Using move_dest_ids we can easily end in an infinite loop situation as
the return of the return of the return ends with some original moves on
in move_dest_ids. We must ensure to drop them to avoid the infinite
loop.

TT29886
This commit is contained in:
david
2021-05-27 10:50:42 +02:00
committed by Pedro M. Baeza
parent 0f6d1ed01e
commit 7c9b6bc3a8
2 changed files with 10 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
{ {
"name": "Return Merchandise Authorization Management", "name": "Return Merchandise Authorization Management",
"summary": "Return Merchandise Authorization (RMA)", "summary": "Return Merchandise Authorization (RMA)",
"version": "13.0.1.2.0", "version": "13.0.1.2.1",
"development_status": "Production/Stable", "development_status": "Production/Stable",
"category": "RMA", "category": "RMA",
"website": "https://github.com/OCA/rma", "website": "https://github.com/OCA/rma",

View File

@@ -130,12 +130,19 @@ class SaleOrderLine(models.Model):
qty = move.product_uom_qty qty = move.product_uom_qty
qty_returned = 0 qty_returned = 0
move_dest = destination_moves(move) move_dest = destination_moves(move)
# With the return of the return of the return we could have an
# infinite loop, so we should avoid it dropping already explored
# move_dest_ids
visited_moves = move + move_dest
while move_dest: while move_dest:
qty_returned -= sum(move_dest.mapped("product_uom_qty")) qty_returned -= sum(move_dest.mapped("product_uom_qty"))
move_dest = destination_moves(move_dest) move_dest = destination_moves(move_dest) - visited_moves
if move_dest: if move_dest:
visited_moves += move_dest
qty += sum(move_dest.mapped("product_uom_qty")) qty += sum(move_dest.mapped("product_uom_qty"))
move_dest = destination_moves(move_dest) move_dest = (
destination_moves(move_dest) - visited_moves
)
# If by chance we get a negative qty we should ignore it # If by chance we get a negative qty we should ignore it
qty = max(0, sum((qty, qty_returned))) qty = max(0, sum((qty, qty_returned)))
data.append( data.append(