changeset 0501bd437ae5 in modules/currency:default
details: https://hg.tryton.org/modules/currency?cmd=changeset;node=0501bd437ae5
description:
Add cash rounding
issue1000
review282601002
diffstat:
currency.py | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diffs (23 lines):
diff -r 6c42e8fe06c9 -r 0501bd437ae5 currency.py
--- a/currency.py Thu Mar 19 19:04:08 2020 +0100
+++ b/currency.py Sat Mar 21 16:08:12 2020 +0100
@@ -141,11 +141,15 @@
def round(self, amount, rounding=ROUND_HALF_EVEN):
'Round the amount depending of the currency'
+ return self._round(amount, self.rounding, rounding)
+
+ @classmethod
+ def _round(cls, amount, factor, rounding):
with localcontext() as ctx:
- ctx.prec = max(ctx.prec, (amount / self.rounding).adjusted() + 1)
- # Divide and multiple by rounding for case rounding is not 10En
- result = (amount / self.rounding).quantize(Decimal('1.'),
- rounding=rounding) * self.rounding
+ ctx.prec = max(ctx.prec, (amount / factor).adjusted() + 1)
+ # Divide and multiple by factor for case factor is not 10En
+ result = (amount / factor).quantize(Decimal('1.'),
+ rounding=rounding) * factor
return Decimal(result)
def is_zero(self, amount):