From b376806d597297289b5d8b399ea573fe96ace026 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 26 Nov 2014 12:00:15 +0100 Subject: [PATCH] Extract a function which is reused in account_statement_operation_rule_dunning_fees --- .../model/account_statement_operation_rule.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/account_statement_operation_rule/model/account_statement_operation_rule.py b/account_statement_operation_rule/model/account_statement_operation_rule.py index dc69f166..9c616556 100644 --- a/account_statement_operation_rule/model/account_statement_operation_rule.py +++ b/account_statement_operation_rule/model/account_statement_operation_rule.py @@ -53,14 +53,26 @@ class AccountStatementOperationRule(models.Model): help="If several rules match, the first one is used.", ) - @api.multi - def _balance_in_range(self, balance, currency): - if currency.compare_amounts(balance, self.amount_min) == -1: + @staticmethod + def _between_with_bounds(low, value, high, currency): + """ Equivalent to a three way comparison: ``min <= value <= high`` + + The comparisons are done with the currency to use the correct + precision. + """ + if currency.compare_amounts(value, low) == -1: return False - if currency.compare_amounts(balance, self.amount_max) == 1: + if currency.compare_amounts(value, high) == 1: return False return True + @api.multi + def _balance_in_range(self, balance, currency): + amount_min = self.amount_min + amount_max = self.amount_max + return self._between_with_bounds(amount_min, balance, + amount_max, currency) + @api.model def _is_multicurrency(self, statement_line): currency = (statement_line.currency_id or