changeset d997f6af3995 in modules/purchase:default
details: https://hg.tryton.org/modules/purchase?cmd=changeset;node=d997f6af3995
description:
        Add round_price

        We add a common method to round prices that are stored using the price 
digits.
        It is useless to use the digits from the field because it can not be 
changed in
        any other way than by configuration.

        issue9146
        review299521002
diffstat:

 purchase.py |  8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diffs (32 lines):

diff -r 64bfe27634dd -r d997f6af3995 purchase.py
--- a/purchase.py       Tue Apr 14 09:27:53 2020 +0200
+++ b/purchase.py       Thu Apr 23 21:44:00 2020 +0200
@@ -26,7 +26,7 @@
 from trytond.modules.account_product.exceptions import AccountError
 from trytond.modules.company.model import (
     employee_field, set_employee, reset_employee)
-from trytond.modules.product import price_digits
+from trytond.modules.product import price_digits, round_price
 
 from .exceptions import PurchaseQuotationError, PartyLocationError
 
@@ -1301,8 +1301,7 @@
             unit_price = Product.get_purchase_price([self.product],
                 abs(self.quantity or 0))[self.product.id]
             if unit_price:
-                unit_price = unit_price.quantize(
-                    Decimal(1) / 10 ** self.__class__.unit_price.digits[1])
+                unit_price = round_price(unit_price)
             return unit_price
 
     @fields.depends('product', 'product_supplier',
@@ -1333,8 +1332,7 @@
             self.unit_price = Product.get_purchase_price([self.product],
                 abs(self.quantity or 0))[self.product.id]
             if self.unit_price:
-                self.unit_price = self.unit_price.quantize(
-                    Decimal(1) / 10 ** self.__class__.unit_price.digits[1])
+                self.unit_price = round_price(self.unit_price)
 
     @fields.depends(methods=['on_change_quantity'])
     def on_change_unit(self):

Reply via email to