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

 sale.py    |  13 ++++---------
 stock.py   |  10 +++-------
 tryton.cfg |   1 +
 3 files changed, 8 insertions(+), 16 deletions(-)

diffs (100 lines):

diff -r 5671c4ff0f91 -r 11cd1c53834a sale.py
--- a/sale.py   Thu Mar 19 19:12:39 2020 +0100
+++ b/sale.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 ModelView, Workflow, fields
@@ -9,7 +7,7 @@
 from trytond.pyson import Eval, If
 from trytond.pool import Pool, PoolMeta
 
-from trytond.modules.product import price_digits
+from trytond.modules.product import price_digits, round_price
 from trytond.modules.sale.exceptions import SaleConfirmError
 
 sale_shipment_cost_method = fields.Selection(
@@ -242,8 +240,7 @@
             if last_line.sequence is not None:
                 sequence = last_line.sequence + 1
 
-        shipment_cost = cost.quantize(
-            Decimal(1) / 10 ** SaleLine.shipment_cost.digits[1])
+        shipment_cost = round_price(cost)
         cost_line = SaleLine(
             sale=self,
             sequence=sequence,
@@ -254,8 +251,7 @@
             shipment_cost=shipment_cost,
             )
         cost_line.on_change_product()
-        cost_line.unit_price = cost.quantize(
-            Decimal(1) / 10 ** SaleLine.unit_price.digits[1])
+        cost_line.unit_price = round_price(cost)
         cost_line.amount = cost_line.on_change_with_amount()
         return cost_line
 
@@ -269,8 +265,7 @@
                 with Transaction().set_context(
                         shipment.get_carrier_context()):
                     cost, currency_id = self.carrier.get_sale_price()
-                cost = cost.quantize(
-                    Decimal(1) / 10 ** Shipment.cost.digits[1])
+                cost = round_price(cost)
                 Shipment.write([shipment], {
                         'carrier': self.carrier.id,
                         'cost': cost,
diff -r 5671c4ff0f91 -r 11cd1c53834a stock.py
--- a/stock.py  Thu Mar 19 19:12:39 2020 +0100
+++ b/stock.py  Thu Apr 23 21:44:00 2020 +0200
@@ -1,14 +1,12 @@
 # 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.i18n import gettext
 from trytond.model import fields
 from trytond.pyson import Eval, Bool
 from trytond.transaction import Transaction
 from trytond.pool import Pool, PoolMeta
 
-from trytond.modules.product import price_digits
+from trytond.modules.product import price_digits, round_price
 from .exceptions import InvoiceShipmentCostError
 
 
@@ -56,8 +54,7 @@
             return
         with Transaction().set_context(self._get_carrier_context()):
             cost, currency_id = self.carrier.get_sale_price()
-        self.cost = cost.quantize(
-            Decimal(1) / 10 ** self.__class__.cost.digits[1])
+        self.cost = round_price(cost)
         self.cost_currency = currency_id
 
     def _get_cost_tax_rule_pattern(self):
@@ -91,8 +88,7 @@
             with Transaction().set_context(date=invoice.currency_date):
                 cost = Currency.compute(self.cost_currency, cost,
                     invoice.currency, round=False)
-        invoice_line.unit_price = cost.quantize(
-            Decimal(1) / 10 ** InvoiceLine.unit_price.digits[1])
+        invoice_line.unit_price = round_price(cost)
 
         taxes = []
         pattern = self._get_cost_tax_rule_pattern()
diff -r 5671c4ff0f91 -r 11cd1c53834a tryton.cfg
--- a/tryton.cfg        Thu Mar 19 19:12:39 2020 +0100
+++ b/tryton.cfg        Thu Apr 23 21:44:00 2020 +0200
@@ -5,6 +5,7 @@
     carrier
     currency
     ir
+    product
     res
     sale
     stock

Reply via email to