Create a new method on statement lines to get the currency

This commit is contained in:
Guewen Baconnier
2014-12-03 17:10:39 +01:00
parent 0656b9afa0
commit 7a869a6d12
3 changed files with 36 additions and 8 deletions

View File

@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import account_statement_operation_rule from . import account_statement_operation_rule
from . import account_statement_line

View File

@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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

View File

@@ -75,8 +75,7 @@ class AccountStatementOperationRule(models.Model):
@api.model @api.model
def _is_multicurrency(self, statement_line): def _is_multicurrency(self, statement_line):
currency = (statement_line.currency_id or currency = statement_line.currency_for_rules()
statement_line.statement_id.currency)
company_currency = statement_line.company_id.currency_id company_currency = statement_line.company_id.currency_id
return currency != company_currency return currency != company_currency
@@ -84,8 +83,7 @@ class AccountStatementOperationRule(models.Model):
def _is_valid_balance(self, statement_line, move_lines, balance): def _is_valid_balance(self, statement_line, move_lines, balance):
if self._is_multicurrency(statement_line): if self._is_multicurrency(statement_line):
return False return False
currency = (statement_line.currency_id or currency = statement_line.currency_for_rules()
statement_line.statement_id.currency)
return self._balance_in_range(balance, currency) return self._balance_in_range(balance, currency)
@api.multi @api.multi
@@ -93,8 +91,7 @@ class AccountStatementOperationRule(models.Model):
# FIXME: surely wrong # FIXME: surely wrong
if self._is_multicurrency(statement_line): if self._is_multicurrency(statement_line):
return False return False
currency = (statement_line.currency_id or currency = statement_line.currency_for_rules()
statement_line.statement_id.currency)
amount_currency = statement_line.amount_currency amount_currency = statement_line.amount_currency
for move_line in move_lines: for move_line in move_lines:
if move_line.currency_id != statement_line.currency_id: if move_line.currency_id != statement_line.currency_id:
@@ -145,8 +142,7 @@ class AccountStatementOperationRule(models.Model):
for move_line in move_lines: for move_line in move_lines:
balance += move_line.credit - move_line.debit balance += move_line.credit - move_line.debit
currency = (statement_line.currency_id or currency = statement_line.currency_for_rules()
statement_line.statement_id.currency)
if currency.is_zero(balance): if currency.is_zero(balance):
return self.browse() return self.browse()