changeset 4151464e05be in modules/commission:default
details:
https://hg.tryton.org/modules/commission?cmd=changeset;node=4151464e05be
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:
commission.py | 6 ++----
invoice.py | 8 +++-----
2 files changed, 5 insertions(+), 9 deletions(-)
diffs (58 lines):
diff -r 125801867e0b -r 4151464e05be commission.py
--- a/commission.py Mon Apr 20 14:03:27 2020 +0200
+++ b/commission.py Thu Apr 23 21:44:00 2020 +0200
@@ -20,7 +20,7 @@
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 @@
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
diff -r 125801867e0b -r 4151464e05be invoice.py
--- a/invoice.py Mon Apr 20 14:03:27 2020 +0200
+++ b/invoice.py Thu Apr 23 21:44:00 2020 +0200
@@ -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 @@
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