mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[ENH] Support both old and new style parse results.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user