From 93b827f4077e811a2ceb42b1ea2ca418baf264a4 Mon Sep 17 00:00:00 2001 From: AlexPForgeFlow Date: Fri, 13 Sep 2024 11:51:23 +0200 Subject: [PATCH] [FIX] rma_sale: fix _get_price_unit to handle dropship cases Take negative valuation layers, as are to customers, and we handle dropship cases where will have negative and positive layers --- rma_sale/models/rma_order_line.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index 86c9aff4..323acb0d 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -232,7 +232,13 @@ class RmaOrderLine(models.Model): and x.location_dest_id.usage == "customer" ) if moves: - layers = moves.sudo().mapped("stock_valuation_layer_ids") + # We take negative valuation layers, as are to customers, + # and we handle dropship cases where will have negative and positive layers + layers = ( + moves.sudo() + .mapped("stock_valuation_layer_ids") + .filtered(lambda layer: layer.quantity < 0 and layer.value < 0) + ) if layers: price_unit = sum(layers.mapped("value")) / sum( layers.mapped("quantity")