diff --git a/addons/account_bank_statement_import/account_bank_statement_import.py b/addons/account_bank_statement_import/account_bank_statement_import.py index 87e2de0d860..85cb6a6f103 100644 --- a/addons/account_bank_statement_import/account_bank_statement_import.py +++ b/addons/account_bank_statement_import/account_bank_statement_import.py @@ -117,6 +117,9 @@ class AccountBankStatementImport(models.TransientModel): if no_st_line: raise UserError(_('This file doesn\'t contain any transaction.')) + def _check_journal_bank_account(self, journal, account_number): + return journal.bank_account_id.sanitized_acc_number == account_number + def _find_additional_data(self, currency_code, account_number): """ Look for a res.currency and account.journal using values extracted from the statement and make sure it's consistent. @@ -138,12 +141,13 @@ class AccountBankStatementImport(models.TransientModel): # No bank account on the journal : create one from the account number of the statement if journal and not journal.bank_account_id: journal.set_bank_account(account_number) - # Already a bank account on the journal : check it's the same as on the statement - elif journal and journal.bank_account_id.sanitized_acc_number != sanitized_account_number: - raise UserError(_('The account of this statement (%s) is not the same as the journal (%s).') % (account_number, journal.bank_account_id.acc_number)) # No journal passed to the wizard : try to find one using the account number of the statement elif not journal: journal = journal_obj.search([('bank_account_id.sanitized_acc_number', '=', sanitized_account_number)]) + # Already a bank account on the journal : check it's the same as on the statement + else: + if not self._check_journal_bank_account(journal, sanitized_account_number): + raise UserError(_('The account of this statement (%s) is not the same as the journal (%s).') % (account_number, journal.bank_account_id.acc_number)) # If importing into an existing journal, its currency must be the same as the bank statement if journal: