From e6a1e240f18bbc95475cd82154bb91a455704b15 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 20 Apr 2020 13:40:48 +0000 Subject: [PATCH] [FIX] purchase_stock: return subcontracted product - Create a product P with a subcontracted BOM - Create a PO for P, 10 units - Receive 10 units - Return 3 units and specify 'To Refund' 13 units are considered received. The reason is that we don't return to a vendor location, but an internal location. We subtract the quantity when the following conditions are met: - we ask for a refund - we return to an internal location - the return location is not in the warehouse of the move The solution is similar to odoo/enterprise#9647 opw-2235157 closes odoo/odoo#50119 X-original-commit: 5fd6c5b65e00dcac77b232b9f47b2292d86c6b0f Signed-off-by: Nicolas Martinelli (nim) --- addons/purchase_stock/models/purchase.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index 4555001fef9ea..cf28c11d27216 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -291,6 +291,15 @@ def _compute_qty_received(self): # receive the product physically in our stock. To avoid counting the # quantity twice, we do nothing. pass + elif ( + move.location_dest_id.usage == "internal" + and move.to_refund + and move.location_dest_id + not in self.env["stock.location"].search( + [("id", "child_of", move.warehouse_id.view_location_id.id)] + ) + ): + total -= move.product_uom._compute_quantity(move.product_uom_qty, line.product_uom) else: total += move.product_uom._compute_quantity(move.product_uom_qty, line.product_uom) line.qty_received = total