From 7c9b6bc3a8da71ee7d372f160d96625f66d60dc0 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 27 May 2021 10:50:42 +0200 Subject: [PATCH] [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 --- rma/__manifest__.py | 2 +- rma_sale/models/sale.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/rma/__manifest__.py b/rma/__manifest__.py index 33e9ed8a..33f038fd 100644 --- a/rma/__manifest__.py +++ b/rma/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Return Merchandise Authorization Management", "summary": "Return Merchandise Authorization (RMA)", - "version": "13.0.1.2.0", + "version": "13.0.1.2.1", "development_status": "Production/Stable", "category": "RMA", "website": "https://github.com/OCA/rma", diff --git a/rma_sale/models/sale.py b/rma_sale/models/sale.py index 7e341e9c..5d52a417 100644 --- a/rma_sale/models/sale.py +++ b/rma_sale/models/sale.py @@ -130,12 +130,19 @@ class SaleOrderLine(models.Model): qty = move.product_uom_qty qty_returned = 0 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: 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: + visited_moves += move_dest 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 qty = max(0, sum((qty, qty_returned))) data.append(