Extract a function which is reused in account_statement_operation_rule_dunning_fees

This commit is contained in:
Guewen Baconnier
2014-11-26 12:00:15 +01:00
parent b901594459
commit f7074a2664

View File

@@ -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