changeset ecdd9bda292e in modules/purchase_request:default
details: 
https://hg.tryton.org/modules/purchase_request?cmd=changeset&node=ecdd9bda292e
description:
        Add sale_product_quantity and purchase_product_quantity modules

        issue11127
        review378031002
diffstat:

 purchase_request.py |  14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diffs (32 lines):

diff -r ce48725207d7 -r ecdd9bda292e purchase_request.py
--- a/purchase_request.py       Mon Apr 11 21:24:28 2022 +0200
+++ b/purchase_request.py       Tue Apr 12 10:10:24 2022 +0200
@@ -515,15 +515,27 @@
         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'

Reply via email to