changeset 8b46722923ab in modules/stock_consignment:default
details: 
https://hg.tryton.org/modules/stock_consignment?cmd=changeset;node=8b46722923ab
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:

 stock.py   |  9 ++++-----
 tryton.cfg |  1 +
 2 files changed, 5 insertions(+), 5 deletions(-)

diffs (50 lines):

diff -r 7e8a3049d626 -r 8b46722923ab stock.py
--- a/stock.py  Thu Mar 19 19:13:39 2020 +0100
+++ b/stock.py  Thu Apr 23 21:44:00 2020 +0200
@@ -1,6 +1,5 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
-from decimal import Decimal
 from functools import wraps
 
 from trytond.model import ModelView, Workflow, fields
@@ -8,6 +7,8 @@
 from trytond.pool import PoolMeta, Pool
 from trytond.pyson import Eval
 
+from trytond.modules.product import round_price
+
 
 class Location(metaclass=PoolMeta):
     __name__ = 'stock.location'
@@ -211,8 +212,7 @@
                 taxes=[t.id for t in line.taxes]):
             line.unit_price = Product.get_purchase_price(
                 [line.product], line.quantity)[line.product.id]
-            line.unit_price = line.unit_price.quantize(
-                Decimal(1) / 10 ** line.__class__.unit_price.digits[1])
+            line.unit_price = round_price(line.unit_price)
         return line
 
     def _get_customer_invoice_line_consignment(self):
@@ -256,8 +256,7 @@
                 taxes=[t.id for t in line.taxes]):
             line.unit_price = Product.get_sale_price(
                 [line.product], line.quantity)[line.product.id]
-            line.unit_price = line.unit_price.quantize(
-                Decimal(1) / 10 ** line.__class__.unit_price.digits[1])
+            line.unit_price = round_price(line.unit_price)
         return line
 
     @classmethod
diff -r 7e8a3049d626 -r 8b46722923ab tryton.cfg
--- a/tryton.cfg        Thu Mar 19 19:13:39 2020 +0100
+++ b/tryton.cfg        Thu Apr 23 21:44:00 2020 +0200
@@ -5,6 +5,7 @@
     account_invoice_line_standalone
     account_invoice_stock
     ir
+    product
     purchase
     sale
     stock

Reply via email to