From cc9ad04326a1d229aa8c05cb05ff41879fffa2b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 6 Oct 2014 22:16:14 +0200 Subject: [PATCH] Wrong computation of delta to find shortages On the first loop, get_shortage adds a second times the delta of moves at current date. issue4215 review9751002 --- purchase_request.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/purchase_request.py b/purchase_request.py index e46e858aab..2da0fb09ca 100644 --- a/purchase_request.py +++ b/purchase_request.py @@ -447,16 +447,19 @@ class PurchaseRequest(ModelSQL, ModelView): if (not res_qty) or (current_qty < res_qty): res_qties[product_id] = current_qty - with Transaction().set_context(stock_date_start=current_date, + if current_date == datetime.date.max: + break + current_date += datetime.timedelta(1) + + # Update current quantities with next moves + with Transaction().set_context(forecast=True, + stock_date_start=current_date, stock_date_end=current_date): pbl = Product.products_by_location([location_id], product_ids, with_childs=True) for key, qty in pbl.iteritems(): _, product_id = key current_qties[product_id] += qty - if current_date == datetime.date.max: - break - current_date += datetime.timedelta(1) return dict((x, (res_dates.get(x), res_qties.get(x))) for x in product_ids)