changeset 00702ac99acc in modules/purchase:default
details: https://hg.tryton.org/modules/purchase?cmd=changeset&node=00702ac99acc
description:
        Support empty list price on product

        issue10244
        review350341002
diffstat:

 product.py  |  17 +++++++++--------
 purchase.py |   2 +-
 2 files changed, 10 insertions(+), 9 deletions(-)

diffs (50 lines):

diff -r 1e2f5cb3760f -r 00702ac99acc product.py
--- a/product.py        Thu Sep 02 23:19:36 2021 +0200
+++ b/product.py        Mon Sep 13 23:29:56 2021 +0200
@@ -185,8 +185,7 @@
         user = User(Transaction().user)
 
         for product in products:
-            prices[product.id] = product._get_purchase_unit_price(
-                quantity=quantity)
+            unit_price = product._get_purchase_unit_price(quantity=quantity)
             default_uom = product.default_uom
             default_currency = (user.company.currency if user.company
                 else None)
@@ -204,16 +203,18 @@
                 pattern = ProductSupplierPrice.get_pattern()
                 for price in product_supplier.prices:
                     if price.match(quantity, product_uom, pattern):
-                        prices[product.id] = price.unit_price
+                        unit_price = price.unit_price
                         default_uom = product_supplier.uom
                         default_currency = product_supplier.currency
-            prices[product.id] = Uom.compute_price(
-                default_uom, prices[product.id], product_uom)
-            if currency and default_currency:
+            if unit_price is not None:
+                unit_price = Uom.compute_price(
+                    default_uom, unit_price, product_uom)
+            if currency and default_currency and unit_price is not None:
                 date = context.get('purchase_date') or today
                 with Transaction().set_context(date=date):
-                    prices[product.id] = Currency.compute(default_currency,
-                        prices[product.id], currency, round=False)
+                    unit_price = Currency.compute(
+                        default_currency, unit_price, currency, round=False)
+            prices[product.id] = unit_price
         return prices
 
     @classmethod
diff -r 1e2f5cb3760f -r 00702ac99acc purchase.py
--- a/purchase.py       Thu Sep 02 23:19:36 2021 +0200
+++ b/purchase.py       Mon Sep 13 23:29:56 2021 +0200
@@ -1331,7 +1331,7 @@
         with Transaction().set_context(self._get_context_purchase_price()):
             unit_price = Product.get_purchase_price([self.product],
                 abs(self.quantity or 0))[self.product.id]
-            if unit_price:
+            if unit_price is not None:
                 unit_price = round_price(unit_price)
             return unit_price
 

Reply via email to