From 16357ebcf655ceb75686ee866da6dc89382215ce Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 14 Nov 2016 17:21:14 +0100 Subject: [PATCH] Skip lines with amount = 0 (blocker for this bank: www.banque-rhone-alpes.fr) Use account number instead of bank number as 'name' (sync with code in v8) Update import lines --- .../models/account_bank_statement_import.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/account_bank_statement_import_ofx/models/account_bank_statement_import.py b/account_bank_statement_import_ofx/models/account_bank_statement_import.py index c05ee73..720df18 100644 --- a/account_bank_statement_import_ofx/models/account_bank_statement_import.py +++ b/account_bank_statement_import_ofx/models/account_bank_statement_import.py @@ -3,9 +3,9 @@ import logging import StringIO -from openerp import api, models -from openerp.tools.translate import _ -from openerp.exceptions import Warning as UserError +from openerp import api, models, _ +from openerp.exceptions import UserError +from openerp.tools import float_is_zero from .ofx import OfxParser, OfxParser_ok @@ -35,8 +35,16 @@ class AccountBankStatementImport(models.TransientModel): transactions = [] total_amt = 0.00 + precision = self.env['decimal.precision'].precision_get('Account') try: for transaction in ofx.account.statement.transactions: + # since odoo 9, the account module defines a constraint + # on account.bank.statement.line: 'amount' must be != 0 + # But some banks have some transactions with amount=0 + # for bank charges that are offered, which blocks the import + if float_is_zero( + float(transaction.amount), precision_digits=precision): + continue # 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 @@ -65,7 +73,7 @@ class AccountBankStatementImport(models.TransientModel): "The file might not be valid.\n\n %s" % e.message)) vals_bank_statement = { - 'name': ofx.account.routing_number, + 'name': ofx.account.number, 'transactions': transactions, 'balance_start': ofx.account.statement.balance, 'balance_end_real':