changeset 52f959701cc3 in modules/sale_supply_drop_shipment:default
details: 
https://hg.tryton.org/modules/sale_supply_drop_shipment?cmd=changeset;node=52f959701cc3
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 |  7 ++-----
 stock.py    |  4 ++--
 tryton.cfg  |  1 +
 3 files changed, 5 insertions(+), 7 deletions(-)

diffs (71 lines):

diff -r 2de777c46af5 -r 52f959701cc3 purchase.py
--- a/purchase.py       Thu Apr 23 21:39:31 2020 +0200
+++ b/purchase.py       Thu Apr 23 21:44:00 2020 +0200
@@ -1,7 +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 trytond import backend
 from trytond.i18n import gettext
 from trytond.model import ModelSQL, ValueMixin, fields
@@ -11,6 +9,7 @@
 from trytond.transaction import Transaction
 from trytond.tools.multivalue import migrate_property
 
+from trytond.modules.product import round_price
 from trytond.modules.purchase.purchase import (
     get_shipments_returns, search_shipments_returns)
 
@@ -181,11 +180,9 @@
         Currency = pool.get('currency.currency')
         move = super().get_move(move_type)
         if move and self.purchase.customer:
-            digits = move.__class__.cost_price.digits
             cost_price = Currency.compute(
                 move.currency, move.unit_price, move.company.currency)
-            move.cost_price = cost_price.quantize(
-                Decimal(str(10.0 ** -digits[1])))
+            move.cost_price = round_price(cost_price)
         return move
 
 
diff -r 2de777c46af5 -r 52f959701cc3 stock.py
--- a/stock.py  Thu Apr 23 21:39:31 2020 +0200
+++ b/stock.py  Thu Apr 23 21:44:00 2020 +0200
@@ -17,6 +17,7 @@
 from trytond.tools import grouped_slice, cursor_dict
 
 from trytond.modules.sale.stock import process_sale
+from trytond.modules.product import round_price
 from trytond.modules.purchase.stock import process_purchase
 
 
@@ -402,7 +403,6 @@
         Move = pool.get('stock.move')
 
         to_save = []
-        cost_exp = Decimal(str(10.0 ** -Move.cost_price.digits[1]))
         for shipment in shipments:
             product_qty = defaultdict(int)
             product_cost = defaultdict(int)
@@ -454,7 +454,7 @@
             for product, cost in product_cost.items():
                 qty = Decimal(str(s_product_qty[product]))
                 if qty:
-                    product_cost[product] = (cost / qty).quantize(cost_exp)
+                    product_cost[product] = round_price(cost / qty)
             for c_move in list(shipment.customer_moves) + to_save:
                 if c_move.id is not None and c_move.state == 'cancel':
                     continue
diff -r 2de777c46af5 -r 52f959701cc3 tryton.cfg
--- a/tryton.cfg        Thu Apr 23 21:39:31 2020 +0200
+++ b/tryton.cfg        Thu Apr 23 21:44:00 2020 +0200
@@ -3,6 +3,7 @@
 depends:
     company
     ir
+    product
     purchase
     purchase_request
     sale

Reply via email to