[ENH] Support both old and new style parse results.

This commit is contained in:
Ronald Portier (Therp BV)
2015-06-26 16:02:10 +02:00
parent f317579f58
commit aaf375018a
3 changed files with 14 additions and 8 deletions

View File

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

View File

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

View File

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