From a77f01aff0d81b52509c25d7692a231acbe60c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 2 Mar 2026 15:21:27 +0100 Subject: [PATCH] Allow cash rounding with opposite method --- modules/account_cash_rounding/CHANGELOG | 1 + modules/account_cash_rounding/currency.py | 5 ++++- modules/currency/__init__.py | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/account_cash_rounding/CHANGELOG b/modules/account_cash_rounding/CHANGELOG index f58f001f5d..9c12e6e794 100644 --- a/modules/account_cash_rounding/CHANGELOG +++ b/modules/account_cash_rounding/CHANGELOG @@ -1,3 +1,4 @@ +* Allow cash rounding with opposite method * Add support for Python 3.14 * Remove support for Python 3.9 diff --git a/modules/account_cash_rounding/currency.py b/modules/account_cash_rounding/currency.py index 77d24a8ada..1fa4d99598 100644 --- a/modules/account_cash_rounding/currency.py +++ b/modules/account_cash_rounding/currency.py @@ -3,6 +3,7 @@ from decimal import ROUND_HALF_EVEN from trytond.model import fields +from trytond.modules.currency import ROUNDING_OPPOSITES from trytond.pool import PoolMeta from trytond.pyson import Eval @@ -14,7 +15,9 @@ class Currency(metaclass=PoolMeta): "Cash Rounding Factor", digits=(None, Eval('digits', None))) - def cash_round(self, amount, rounding=ROUND_HALF_EVEN): + def cash_round(self, amount, rounding=ROUND_HALF_EVEN, opposite=False): + if opposite: + rounding = ROUNDING_OPPOSITES[rounding] if self.cash_rounding is not None: factor = self.cash_rounding else: diff --git a/modules/currency/__init__.py b/modules/currency/__init__.py index 4effdfa4a2..bf2dc9a763 100644 --- a/modules/currency/__init__.py +++ b/modules/currency/__init__.py @@ -1,2 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. + +__all__ = ['ROUNDING_OPPOSITES'] + + +def __getattr__(name): + if name == 'ROUNDING_OPPOSITES': + from .currency import ROUNDING_OPPOSITES + return ROUNDING_OPPOSITES + raise AttributeError(f"module {__name__!r} has no attribute {name!r}")