From 7a869a6d1222a8ad50b81c73f8c15ebdaf1c8c20 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 3 Dec 2014 17:10:39 +0100 Subject: [PATCH] Create a new method on statement lines to get the currency --- .../model/__init__.py | 1 + .../model/account_statement_line.py | 31 +++++++++++++++++++ .../model/account_statement_operation_rule.py | 12 +++---- 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 account_statement_operation_rule/model/account_statement_line.py diff --git a/account_statement_operation_rule/model/__init__.py b/account_statement_operation_rule/model/__init__.py index f8bd646b..7854e715 100644 --- a/account_statement_operation_rule/model/__init__.py +++ b/account_statement_operation_rule/model/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- from . import account_statement_operation_rule +from . import account_statement_line diff --git a/account_statement_operation_rule/model/account_statement_line.py b/account_statement_operation_rule/model/account_statement_line.py new file mode 100644 index 00000000..40ead9cd --- /dev/null +++ b/account_statement_operation_rule/model/account_statement_line.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author: Guewen Baconnier +# Copyright 2014 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +from openerp import models, api + + +class AccountBankStatementLine(models.Model): + _inherit = 'account.bank.statement.line' + + @api.multi + def currency_for_rules(self): + return self.currency_id or self.statement_id.currency 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 3de82c85..d5c9673f 100644 --- a/account_statement_operation_rule/model/account_statement_operation_rule.py +++ b/account_statement_operation_rule/model/account_statement_operation_rule.py @@ -75,8 +75,7 @@ class AccountStatementOperationRule(models.Model): @api.model def _is_multicurrency(self, statement_line): - currency = (statement_line.currency_id or - statement_line.statement_id.currency) + currency = statement_line.currency_for_rules() company_currency = statement_line.company_id.currency_id return currency != company_currency @@ -84,8 +83,7 @@ class AccountStatementOperationRule(models.Model): def _is_valid_balance(self, statement_line, move_lines, balance): if self._is_multicurrency(statement_line): return False - currency = (statement_line.currency_id or - statement_line.statement_id.currency) + currency = statement_line.currency_for_rules() return self._balance_in_range(balance, currency) @api.multi @@ -93,8 +91,7 @@ class AccountStatementOperationRule(models.Model): # FIXME: surely wrong if self._is_multicurrency(statement_line): return False - currency = (statement_line.currency_id or - statement_line.statement_id.currency) + currency = statement_line.currency_for_rules() amount_currency = statement_line.amount_currency for move_line in move_lines: if move_line.currency_id != statement_line.currency_id: @@ -145,8 +142,7 @@ class AccountStatementOperationRule(models.Model): for move_line in move_lines: balance += move_line.credit - move_line.debit - currency = (statement_line.currency_id or - statement_line.statement_id.currency) + currency = statement_line.currency_for_rules() if currency.is_zero(balance): return self.browse()