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:
Cédric Krier committed 2020-04-23 21:44:00 +02:00
1 parent f83ad25791
commit 30cd6e4cf9
2 files changed
+5 -9

No files matched your search

+2 -4
View File
@@ -20,7 +20,7 @@ from trytond.pool import Pool
from trytond.wizard import Wizard, StateView, StateAction, Button
from trytond.transaction import Transaction
from trytond.modules.product import price_digits
from trytond.modules.product import price_digits, round_price
from .exceptions import FormulaError
@@ -122,14 +122,12 @@ class Agent(ModelSQL, ModelView):
group_by=commission.agent)
cursor.execute(*query)
amounts.update(dict(cursor.fetchall()))
digits = cls.pending_amount.digits
exp = Decimal(str(10.0 ** -digits[1]))
for agent_id, amount in amounts.items():
if amount:
# SQLite uses float for SUM
if not isinstance(amount, Decimal):
amount = Decimal(str(amount))
amounts[agent_id] = amount.quantize(exp)
amounts[agent_id] = round_price(amount)
return amounts
@property
+3 -5
View File
@@ -1,14 +1,13 @@
# 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.pool import PoolMeta, Pool
from trytond.model import ModelView, Workflow, fields
from trytond.pyson import Eval, If, Bool
from trytond.transaction import Transaction
from trytond.tools import grouped_slice
from trytond.modules.product import round_price
class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
@@ -156,8 +155,7 @@ class InvoiceLine(metaclass=PoolMeta):
self.amount, agent.currency, round=False)
amount = self._get_commission_amount(amount, plan)
if amount:
digits = Commission.amount.digits
amount = amount.quantize(Decimal(str(10.0 ** -digits[1])))
amount = round_price(amount)
if not amount:
continue