From e5f3817f085c2fbedcc2b8bd62bd21a98ea8c2ca Mon Sep 17 00:00:00 2001 From: Murtuza Saleh Date: Thu, 3 Sep 2020 15:12:54 +0530 Subject: [PATCH] [12.0][IMP] Improved _compute_qty code --- stock_request/models/stock_request.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/stock_request/models/stock_request.py b/stock_request/models/stock_request.py index f1c545398..099a0b3c6 100644 --- a/stock_request/models/stock_request.py +++ b/stock_request/models/stock_request.py @@ -171,7 +171,14 @@ class StockRequest(models.Model): ) def _compute_qty(self): for request in self: - done_qty = sum(request.allocation_ids.mapped("allocated_product_qty")) + incoming_qty = 0.0 + other_qty = 0.0 + for allocation in request.allocation_ids: + if allocation.stock_move_id.picking_code == "incoming": + incoming_qty += allocation.allocated_product_qty + else: + other_qty += allocation.allocated_product_qty + done_qty = abs(other_qty - incoming_qty) open_qty = sum(request.allocation_ids.mapped("open_product_qty")) uom = request.product_id.uom_id request.qty_done = uom._compute_quantity(done_qty, request.product_uom_id)