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
This commit is contained in:
1 parent
2ae4f4382c
commit
413cdbfbce
3 files changed
+8
-16
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -5,6 +5,7 @@ depends:
|
||||
carrier
|
||||
currency
|
||||
ir
|
||||
product
|
||||
res
|
||||
sale
|
||||
stock
|
||||
|
||||
Reference in new issue
Block a user