[FIX] Prevent unneeded processing and memory use in parsers.

This commit is contained in:
Ronald Portier (Therp BV)
2015-06-19 12:43:20 +02:00
parent 6fe358a6cd
commit d3c1c8d39f
7 changed files with 203 additions and 108 deletions

View File

@@ -20,11 +20,10 @@
##############################################################################
import logging
from openerp import models
from openerp.addons.bank_statement_parse.parserlib import convert_statements
from .mt940 import MT940Parser as Parser
_logger = logging.getLogger(__name__)
_LOGGER = logging.getLogger(__name__)
class AccountBankStatementImport(models.TransientModel):
@@ -35,10 +34,10 @@ class AccountBankStatementImport(models.TransientModel):
"""Parse a MT940 IBAN ING file."""
parser = Parser()
try:
_logger.debug("Try parsing with MT940 IBAN ING.")
return convert_statements(parser.parse(data_file))
_LOGGER.debug("Try parsing with MT940 IBAN ING.")
return parser.parse(data_file)
except ValueError:
# Returning super will call next candidate:
_logger.debug("Statement file was not a MT940 IBAN ING file.")
_LOGGER.debug("Statement file was not a MT940 IBAN ING file.")
return super(AccountBankStatementImport, self)._parse_file(
cr, uid, data_file, context=context)

View File

@@ -63,7 +63,7 @@ class TestStatementFile(TransactionCase):
(statement_obj.balance_start, start_balance)
)
self.assertTrue(
abs(statement_obj.balance_end - end_balance) < 0.00001,
abs(statement_obj.balance_end_real - end_balance) < 0.00001,
'Start balance %f not equal to expected %f' %
(statement_obj.balance_end_real, end_balance)
)