From f65e3a3a57df40074110bc7e06e4106febdffe0c Mon Sep 17 00:00:00 2001 From: Graeme Gellatly Date: Sun, 2 Feb 2014 22:48:28 +1300 Subject: [PATCH] [REM] Revert OFXparse changes for import merege --- .../parser/ofx_parser.py | 60 +++++++------------ account_statement_ofx_import/statement.py | 10 ++-- 2 files changed, 27 insertions(+), 43 deletions(-) diff --git a/account_statement_ofx_import/parser/ofx_parser.py b/account_statement_ofx_import/parser/ofx_parser.py index f2a75551..5b86035d 100644 --- a/account_statement_ofx_import/parser/ofx_parser.py +++ b/account_statement_ofx_import/parser/ofx_parser.py @@ -34,7 +34,7 @@ class OfxParser(BankStatementImportParser): """ Class for defining parser for OFX file format. """ - + def __init__(self, parser_name, *args, **kwargs): """ """ @@ -60,23 +60,25 @@ class OfxParser(BankStatementImportParser): """ return True - def _prepare_lines(self, transactions): - return [{'date': transaction.date, - 'amount': transaction.amount, - 'ref': transaction.type, - 'label': transaction.payee} for transaction in transactions] - def _parse(self, *args, **kwargs): """ Launch the parsing itself. """ - with tempfile.NamedTemporaryFile() as ofx_file: - ofx_file.seek(0) - ofx_file.write(self.filebuffer) - ofx_file.flush() - ofx = ofxparse.OfxParser.parse(file(ofx_file.name)) - ofx_file.close() - self.result_row_list = self._prepare_lines(ofx.account.statement.transactions) + ofx_file = tempfile.NamedTemporaryFile() + ofx_file.seek(0) + ofx_file.write(self.filebuffer) + ofx_file.flush() + ofx = ofxparse.OfxParser.parse(file(ofx_file.name)) + ofx_file.close() + res = [] + for transaction in ofx.account.statement.transactions: + res.append({ + 'date': transaction.date, + 'amount': transaction.amount, + 'ref': transaction.type, + 'label': transaction.payee, + }) + self.result_row_list = res return True def _validate(self, *args, **kwargs): @@ -91,6 +93,12 @@ class OfxParser(BankStatementImportParser): """ return True + def _post(self, *args, **kwargs): + """ + Nothing to do. + """ + return True + def get_st_line_vals(self, line, *args, **kwargs): """ This method must return a dict of vals that can be passed to create @@ -110,27 +118,3 @@ class OfxParser(BankStatementImportParser): 'label': line.get('label', ''), } -class OfxParser2(OfxParser): - """ - Class for defining parser for OFX file format. Only differs from above - by setting ref to be the memo rather than type field - """ - - def __init__(self, parser_name, *args, **kwargs): - """ - """ - super(OfxParser2, self).__init__(parser_name, *args, **kwargs) - - @classmethod - def parser_for(cls, parser_name): - """ - Used by the new_bank_statement_parser class factory. Return true if - the providen name is 'ofx_alt'. - """ - return parser_name == 'ofx_alt' - - def _prepare_lines(self, transactions): - return [{'date': transaction.date, - 'amount': transaction.amount, - 'ref': transaction.memo, - 'label': transaction.payee} for transaction in transactions] diff --git a/account_statement_ofx_import/statement.py b/account_statement_ofx_import/statement.py index b182882a..c5b06fe8 100644 --- a/account_statement_ofx_import/statement.py +++ b/account_statement_ofx_import/statement.py @@ -21,17 +21,17 @@ from openerp.tools.translate import _ from openerp.osv import fields, orm -class AccountStatementProfile(orm.Model): +class AccountStatementProfil(orm.Model): _inherit = "account.statement.profile" def get_import_type_selection(self, cr, uid, context=None): """ Inherited from parent to add parser. """ - selection = super(AccountStatementProfile, self - ).get_import_type_selection(cr, uid, context=context) - selection.extend([('ofx_so', _('OFX - Open Financial Exchange')), - ('ofx_alt', _('OFX - (memo rather than type in ref field)'))]) + selection = super(AccountStatementProfil, self + ).get_import_type_selection(cr, uid, + context=context) + selection.append(('ofx_so', _('OFX - Open Financial Exchange'))) return selection _columns = {