diff --git a/sale.py b/sale.py index ff5b6af611..1c976514be 100644 --- a/sale.py +++ b/sale.py @@ -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.transaction import Transaction 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 @@ class Sale(metaclass=PoolMeta): 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 @@ class Sale(metaclass=PoolMeta): 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 @@ class Sale(metaclass=PoolMeta): 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 --git a/stock.py b/stock.py index d6daf92ec5..822d89c46a 100644 --- a/stock.py +++ b/stock.py @@ -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 @@ class ShipmentOut(metaclass=PoolMeta): 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 @@ class ShipmentOut(metaclass=PoolMeta): 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 --git a/tryton.cfg b/tryton.cfg index 51004ccadf..e7b28d5954 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -5,6 +5,7 @@ depends: carrier currency ir + product res sale stock