From 522fbad912228b89f739f59bf34262b207d1fdd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 12 Apr 2022 10:10:24 +0200 Subject: [PATCH] Add sale_product_quantity and purchase_product_quantity modules issue11127 review378031002 --- purchase_request.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/purchase_request.py b/purchase_request.py index e3fd482ad8..96974c08bf 100644 --- a/purchase_request.py +++ b/purchase_request.py @@ -515,15 +515,27 @@ class CreatePurchase(Wizard): line.unit_price = round_price(Decimal(0)) for f, v in key: setattr(line, f, v) - line.quantity = sum(r.quantity for r in requests) line.purchase = purchase line.on_change_product() + line.quantity = cls.compute_quantity(requests, line, purchase) + if line.unit: + line.quantity = line.unit.ceil(line.quantity) # Set again in case on_change's changed them for f, v in key: setattr(line, f, v) line.on_change_quantity() return line + @classmethod + def compute_quantity(cls, requests, line, purchase): + pool = Pool() + Uom = pool.get('product.uom') + unit = line.unit + compute_qty = Uom.compute_qty + return sum( + compute_qty(r.uom, r.quantity, unit, round=False) + for r in requests) + class HandlePurchaseCancellationException(Wizard): 'Handle Purchase Cancellation Exception'