[REF] account_bank_statement_import_ofx: no exception shadowing
* Only except exceptions raised by OfxParser.parse * The second try except was useless since OfxParser.parse checks that required fields are present
This commit is contained in:
@@ -6,6 +6,7 @@ import StringIO
|
||||
from openerp import api, models, _
|
||||
from openerp.exceptions import UserError
|
||||
from ofxparse import OfxParser
|
||||
from ofxparse.ofxparse import OfxParserException
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,7 +17,7 @@ class AccountBankStatementImport(models.TransientModel):
|
||||
def _check_ofx(self, file):
|
||||
try:
|
||||
ofx = OfxParser.parse(file)
|
||||
except:
|
||||
except (TypeError, AttributeError, OfxParserException):
|
||||
return False
|
||||
return ofx
|
||||
|
||||
@@ -27,28 +28,25 @@ class AccountBankStatementImport(models.TransientModel):
|
||||
|
||||
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
|
||||
partner_bank = self.env['res.partner.bank'].search([('owner_name', '=', transaction.payee)], limit=1)
|
||||
if partner_bank:
|
||||
bank_account_id = partner_bank.id
|
||||
partner_id = partner_bank.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))
|
||||
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
|
||||
partner_bank = self.env['res.partner.bank'].search([('owner_name', '=', transaction.payee)], limit=1)
|
||||
if partner_bank:
|
||||
bank_account_id = partner_bank.id
|
||||
partner_id = partner_bank.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)
|
||||
|
||||
vals_bank_statement = {
|
||||
'name': ofx.account.routing_number,
|
||||
|
||||
Reference in New Issue
Block a user