[FIX] account_bank_statement_import_ofx: multiple accounts
An OFX file can contain more than one account. Therefore, we need to loop over all the included accounts, otherwise statements will be missed. opw-673814
This commit is contained in:
@@ -32,37 +32,51 @@ class account_bank_statement_import(osv.TransientModel):
|
||||
if not ofx:
|
||||
return super(account_bank_statement_import, self)._parse_file(cr, uid, data_file, context=context)
|
||||
|
||||
transactions = []
|
||||
total_amt = 0.00
|
||||
try:
|
||||
for transaction in ofx.account.statement.transactions:
|
||||
# Since ofxparse doesn't provide account numbers, we'll have to find res.partner and res.partner.bank here
|
||||
# (normal behavious is to provide 'account_number', which the generic module uses to find partner/bank)
|
||||
bank_account_id = partner_id = False
|
||||
ids = self.pool.get('res.partner.bank').search(cr, uid, [('owner_name', '=', transaction.payee)], context=context)
|
||||
if ids:
|
||||
bank_account_id = bank_account_id = ids[0]
|
||||
partner_id = self.pool.get('res.partner.bank').browse(cr, uid, bank_account_id, context=context).partner_id.id
|
||||
vals_line = {
|
||||
'date': transaction.date,
|
||||
'name': transaction.payee + (transaction.memo and ': ' + transaction.memo or ''),
|
||||
'ref': transaction.id,
|
||||
'amount': transaction.amount,
|
||||
'unique_import_id': transaction.id,
|
||||
'bank_account_id': bank_account_id,
|
||||
'partner_id': partner_id,
|
||||
}
|
||||
total_amt += float(transaction.amount)
|
||||
transactions.append(vals_line)
|
||||
except Exception, e:
|
||||
raise UserError(_("The following problem occurred during import. The file might not be valid.\n\n %s" % e.message))
|
||||
vals_bank_statement = []
|
||||
account_lst = set()
|
||||
currency_lst = set()
|
||||
for account in ofx.accounts:
|
||||
account_lst.add(account.number)
|
||||
currency_lst.add(account.statement.currency)
|
||||
transactions = []
|
||||
total_amt = 0.00
|
||||
try:
|
||||
for transaction in account.statement.transactions:
|
||||
# Since ofxparse doesn't provide account numbers, we'll have to find res.partner and res.partner.bank here
|
||||
# (normal behavious is to provide 'account_number', which the generic module uses to find partner/bank)
|
||||
bank_account_id = partner_id = False
|
||||
ids = self.pool.get('res.partner.bank').search(cr, uid, [('owner_name', '=', transaction.payee)], context=context)
|
||||
if ids:
|
||||
bank_account_id = bank_account_id = ids[0]
|
||||
partner_id = self.pool.get('res.partner.bank').browse(cr, uid, bank_account_id, context=context).partner_id.id
|
||||
vals_line = {
|
||||
'date': transaction.date,
|
||||
'name': transaction.payee + (transaction.memo and ': ' + transaction.memo or ''),
|
||||
'ref': transaction.id,
|
||||
'amount': transaction.amount,
|
||||
'unique_import_id': transaction.id,
|
||||
'bank_account_id': bank_account_id,
|
||||
'partner_id': partner_id,
|
||||
}
|
||||
total_amt += float(transaction.amount)
|
||||
transactions.append(vals_line)
|
||||
except Exception, e:
|
||||
raise UserError(_("The following problem occurred during import. The file might not be valid.\n\n %s" % e.message))
|
||||
|
||||
vals_bank_statement = {
|
||||
'name': ofx.account.routing_number,
|
||||
'transactions': transactions,
|
||||
# WARNING: the provided ledger balance is not necessarily the ending balance of the statement
|
||||
# see https://github.com/odoo/odoo/issues/3003
|
||||
'balance_start': float(ofx.account.statement.balance) - total_amt,
|
||||
'balance_end_real': ofx.account.statement.balance,
|
||||
}
|
||||
return ofx.account.statement.currency, ofx.account.number, [vals_bank_statement]
|
||||
vals_bank_statement.append({
|
||||
'name': account.routing_number,
|
||||
'transactions': transactions,
|
||||
# WARNING: the provided ledger balance is not necessarily the ending balance of the statement
|
||||
# see https://github.com/odoo/odoo/issues/3003
|
||||
'balance_start': float(account.statement.balance) - total_amt,
|
||||
'balance_end_real': account.statement.balance,
|
||||
})
|
||||
|
||||
if account_lst and len(account_lst) == 1:
|
||||
account_lst = account_lst.pop()
|
||||
currency_lst = currency_lst.pop()
|
||||
else:
|
||||
account_lst = None
|
||||
currency_lst = None
|
||||
|
||||
return currency_lst, account_lst, vals_bank_statement
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
<CCSTMTRS>
|
||||
<CURDEF>USD</CURDEF>
|
||||
<CCACCTFROM>
|
||||
<ACCTID>123412341234</ACCTID>
|
||||
<ACCTID>123456</ACCTID>
|
||||
</CCACCTFROM>
|
||||
<BANKTRANLIST>
|
||||
</BANKTRANLIST>
|
||||
|
||||
Reference in New Issue
Block a user