From aaf375018ab1600554dcdb34a335a7cedb79628b Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Fri, 26 Jun 2015 16:02:10 +0200 Subject: [PATCH] [ENH] Support both old and new style parse results. --- .../account_bank_statement_import.py | 10 +++++++++- .../account_bank_statement_import_ofx.py | 8 ++++---- .../account_bank_statement_import_qif.py | 4 +--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/account_bank_statement_import/account_bank_statement_import.py b/account_bank_statement_import/account_bank_statement_import.py index dafb846..9d985f4 100644 --- a/account_bank_statement_import/account_bank_statement_import.py +++ b/account_bank_statement_import/account_bank_statement_import.py @@ -77,7 +77,15 @@ class AccountBankStatementImport(models.TransientModel): # The appropriate implementation module returns the required data statement_ids = [] notifications = [] - statements = self._parse_file(data_file) + parse_result = self._parse_file(data_file) + # Check for old version result, with separate currency and account + if isinstance(parse_result, tuple) and len(parse_result) == 3: + (currency_code, account_number, statements) = parse_result + for stmt_vals in statements: + stmt_vals['currency_code'] = currency_code + stmt_vals['account_number'] = account_number + else: + statements = parse_result # Check raw data: self._check_parsed_data(statements) # Import all statements: diff --git a/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py b/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py index 94bd49a..9358ae1 100644 --- a/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py +++ b/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py @@ -67,12 +67,12 @@ class AccountBankStatementImport(models.TransientModel): raise Warning(_("The following problem occurred during import. " "The file might not be valid.\n\n %s" % e.message)) - return [{ - 'currency_code': ofx.account.statement.currency, - 'account_number': ofx.account.number, + vals_bank_statement = { 'name': ofx.account.routing_number, 'transactions': transactions, 'balance_start': ofx.account.statement.balance, 'balance_end_real': float(ofx.account.statement.balance) + total_amt, - }] + } + return ofx.account.statement.currency, ofx.account.number, [ + vals_bank_statement] diff --git a/account_bank_statement_import_qif/account_bank_statement_import_qif.py b/account_bank_statement_import_qif/account_bank_statement_import_qif.py index e165473..0b9061e 100644 --- a/account_bank_statement_import_qif/account_bank_statement_import_qif.py +++ b/account_bank_statement_import_qif/account_bank_statement_import_qif.py @@ -84,9 +84,7 @@ class AccountBankStatementImport(models.TransientModel): 'not correctly formed.')) vals_bank_statement.update({ - 'currency_code': None, - 'account_number': None, 'balance_end_real': total, 'transactions': transactions }) - return [vals_bank_statement] + return None, None, [vals_bank_statement]