changeset 5fb6c24f35b8 in modules/purchase_shipment_cost:default
details: 
https://hg.tryton.org/modules/purchase_shipment_cost?cmd=changeset;node=5fb6c24f35b8
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   |  10 +++++-----
 tryton.cfg |   1 +
 2 files changed, 6 insertions(+), 5 deletions(-)

diffs (45 lines):

diff -r 938f26a29b40 -r 5fb6c24f35b8 stock.py
--- a/stock.py  Mon Apr 13 17:18:28 2020 +0200
+++ b/stock.py  Thu Apr 23 21:44:00 2020 +0200
@@ -8,7 +8,7 @@
 from trytond.pool import Pool, PoolMeta
 from trytond.transaction import Transaction
 
-from trytond.modules.product import price_digits
+from trytond.modules.product import price_digits, round_price
 
 
 class ShipmentIn(metaclass=PoolMeta):
@@ -91,8 +91,8 @@
                 move_cost = cost / Decimal(len(moves))
             else:
                 move_cost = cost * quantity * unit_prices[move.id] / sum_value
-            unit_shipment_cost = (move_cost / quantity).quantize(exp,
-                rounding=ROUND_DOWN)
+            unit_shipment_cost = round_price(
+                move_cost / quantity, rounding=ROUND_DOWN)
             costs.append({
                     'unit_shipment_cost': unit_shipment_cost,
                     'difference': move_cost - (unit_shipment_cost * quantity),
@@ -114,8 +114,8 @@
             unit_shipment_cost = Currency.compute(
                 self.company.currency, cost['unit_shipment_cost'],
                 move.currency, round=False)
-            unit_shipment_cost = unit_shipment_cost.quantize(
-                exp, rounding=ROUND_HALF_EVEN)
+            unit_shipment_cost = round_price(
+                unit_shipment_cost, rounding=ROUND_HALF_EVEN)
             move.unit_price += unit_shipment_cost
             move.unit_shipment_cost = unit_shipment_cost
         Move.save(moves)
diff -r 938f26a29b40 -r 5fb6c24f35b8 tryton.cfg
--- a/tryton.cfg        Mon Apr 13 17:18:28 2020 +0200
+++ b/tryton.cfg        Thu Apr 23 21:44:00 2020 +0200
@@ -4,6 +4,7 @@
     carrier
     currency
     ir
+    product
     res
     stock
 extras_depend:

Reply via email to