From be9717dafd015e54ff982b2a79017a94e5e2f7dc Mon Sep 17 00:00:00 2001 From: Graeme Gellatly Date: Sun, 5 Jan 2014 18:40:54 +1300 Subject: [PATCH 1/5] [FIX] Minor fixes to enable install on trunk, explicit imports added, alternative string concatenation in help and change to correct xml comment style --- account_statement_base_completion/__init__.py | 5 +++-- account_statement_base_completion/partner.py | 8 ++++---- account_statement_base_completion/statement.py | 5 ++--- .../report/bank_statement_report.py | 2 +- account_statement_ext/statement_view.xml | 16 ++++++++-------- .../parser/ofx_parser.py | 6 ++++-- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/account_statement_base_completion/__init__.py b/account_statement_base_completion/__init__.py index 6c9ef1bc..2a3a858d 100644 --- a/account_statement_base_completion/__init__.py +++ b/account_statement_base_completion/__init__.py @@ -19,5 +19,6 @@ # ############################################################################## -import statement -import partner +from . import partner +from . import statement + diff --git a/account_statement_base_completion/partner.py b/account_statement_base_completion/partner.py index 89c810d5..4d3a452e 100644 --- a/account_statement_base_completion/partner.py +++ b/account_statement_base_completion/partner.py @@ -20,7 +20,7 @@ ################################################################################# from openerp.osv.orm import Model -from openerp.osv import fields, osv +from openerp.osv import fields class res_partner(Model): @@ -32,7 +32,7 @@ class res_partner(Model): _columns = { 'bank_statement_label': fields.char('Bank Statement Label', size=100, - help="Enter the various label found on your bank statement separated by a ; If \ - one of this label is include in the bank statement line, the partner will be automatically \ - filled (as long as you use this method/rules in your statement profile)."), + help="Enter the various label found on your bank statement separated by a ; If " + "one of this label is include in the bank statement line, the partner will be automatically " + "filled (as long as you use this method/rules in your statement profile)."), } diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 96ab741b..d387e7da 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -23,16 +23,15 @@ import traceback import sys import logging import simplejson - +import datetime import psycopg2 from collections import defaultdict import re -from tools.translate import _ +from openerp.tools.translate import _ from openerp.osv import osv, orm, fields from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from operator import attrgetter -import datetime _logger = logging.getLogger(__name__) diff --git a/account_statement_ext/report/bank_statement_report.py b/account_statement_ext/report/bank_statement_report.py index 9bdca7fa..80e6af65 100644 --- a/account_statement_ext/report/bank_statement_report.py +++ b/account_statement_ext/report/bank_statement_report.py @@ -22,7 +22,7 @@ from openerp.report import report_sxw from openerp.tools.translate import _ from openerp import pooler from datetime import datetime -from report_webkit import webkit_report +from openerp.addons.report_webkit import webkit_report class BankStatementWebkit(report_sxw.rml_parse): diff --git a/account_statement_ext/statement_view.xml b/account_statement_ext/statement_view.xml index f42d6581..063ba92a 100644 --- a/account_statement_ext/statement_view.xml +++ b/account_statement_ext/statement_view.xml @@ -96,13 +96,9 @@ account.bank.statement form - + - - True - - - # Make balance visible or not depending on profile + + True + + + {'invisible':[('balance_check','=',False)]} @@ -128,7 +128,7 @@ - # Adapt onchange signature + @@ -139,7 +139,7 @@ - # also set type hidden as it has no impact on reconciliation + diff --git a/account_statement_ofx_import/parser/ofx_parser.py b/account_statement_ofx_import/parser/ofx_parser.py index 65961241..5b86035d 100644 --- a/account_statement_ofx_import/parser/ofx_parser.py +++ b/account_statement_ofx_import/parser/ofx_parser.py @@ -18,11 +18,13 @@ # along with this program. If not, see . # ############################################################################## -from openerp.tools.translate import _ -from account_statement_base_import.parser import BankStatementImportParser + import tempfile import datetime +from openerp.tools.translate import _ +from openerp.addons.account_statement_base_import.parser import BankStatementImportParser + try: import ofxparse except: From 50f47bc31b4087dbf9d23b10d97886d3b4f51743 Mon Sep 17 00:00:00 2001 From: Graeme Gellatly Date: Sun, 5 Jan 2014 21:53:40 +1300 Subject: [PATCH 2/5] [FIX][REF] Refactor method get_default_pay_receive_accounts of account_statement_ext to not reimplement property searching and also stop failure on trunk. --- account_statement_ext/statement.py | 36 +++++++++--------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 4775362b..6e2405eb 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -111,7 +111,7 @@ class AccountStatementProfile(Model): _constraints = [ (_check_partner, "You need to put a partner if you tic the 'Force partner on bank move'!", []), ] - + _sql_constraints = [ ('name_uniq', 'unique (name, company_id)', 'The name of the bank statement must be unique !') ] @@ -395,7 +395,7 @@ class AccountBankSatement(Model): if errors_stack: msg = u"\n".join(errors_stack) raise osv.except_osv(_('Error'), msg) -#end changes +# end changes self.write(cr, uid, [st.id], {'name': st_number, 'balance_end_real': st.balance_end}, @@ -498,31 +498,15 @@ class AccountBankSatement(Model): :return: tuple of int/long ID that give account_receivable, account_payable based on company default. """ - account_receivable = False - account_payable = False - property_obj = self.pool.get('ir.property') - model_fields_obj = self.pool.get('ir.model.fields') - model_fields_ids = model_fields_obj.search( - cr, - uid, - [('name', 'in', ['property_account_receivable', - 'property_account_payable']), - ('model', '=', 'res.partner')], - context=context - ) - property_ids = property_obj.search(cr, - uid, - [('fields_id', 'in', model_fields_ids), - ('res_id', '=', False)], - context=context) - for erp_property in property_obj.browse( - cr, uid, property_ids, context=context): - if erp_property.fields_id.name == 'property_account_receivable': - account_receivable = erp_property.value_reference.id - elif erp_property.fields_id.name == 'property_account_payable': - account_payable = erp_property.value_reference.id - return account_receivable, account_payable + property_obj = self.pool.get('ir.property') + account_receivable = property_obj.get(cr, uid, 'property_account_receivable', + 'res.partner', context=context) + account_payable = property_obj.get(cr, uid, 'property_account_payable', + 'res.partner', context=context) + + return (account_receivable and account_receivable.id or False, + account_payable and account_payable.id or False) def balance_check(self, cr, uid, st_id, journal_type='bank', context=None): """ From d005ec45b0207a88172e480ac8dc0dc7823332e9 Mon Sep 17 00:00:00 2001 From: Graeme Gellatly Date: Sun, 2 Feb 2014 22:27:27 +1300 Subject: [PATCH 3/5] ofxparse update --- .../parser/ofx_parser.py | 60 ++++++++++++------- account_statement_ofx_import/statement.py | 10 ++-- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/account_statement_ofx_import/parser/ofx_parser.py b/account_statement_ofx_import/parser/ofx_parser.py index 5b86035d..f2a75551 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,25 +60,23 @@ 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. """ - 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 + 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) return True def _validate(self, *args, **kwargs): @@ -93,12 +91,6 @@ 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 @@ -118,3 +110,27 @@ 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 c5b06fe8..b182882a 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 AccountStatementProfil(orm.Model): +class AccountStatementProfile(orm.Model): _inherit = "account.statement.profile" def get_import_type_selection(self, cr, uid, context=None): """ Inherited from parent to add parser. """ - selection = super(AccountStatementProfil, self - ).get_import_type_selection(cr, uid, - context=context) - selection.append(('ofx_so', _('OFX - Open Financial Exchange'))) + 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)'))]) return selection _columns = { From 341552eef942e634f2e0219a5895a52c87481af4 Mon Sep 17 00:00:00 2001 From: Graeme Gellatly Date: Sun, 2 Feb 2014 22:42:28 +1300 Subject: [PATCH 4/5] refix imports after rebase --- account_statement_base_completion/statement.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 4ac7dab7..b69fb970 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -24,16 +24,17 @@ import sys import logging import simplejson import inspect +import datetime import psycopg2 from collections import defaultdict import re -from tools.translate import _ +from openerp.tools.translate import _ from openerp.osv import osv, orm, fields from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from operator import attrgetter -import datetime + _logger = logging.getLogger(__name__) @@ -184,7 +185,7 @@ class AccountStatementCompletionRule(orm.Model): inv = self._find_invoice(cr, uid, line, inv_type, context=context) if inv: # FIXME use only commercial_partner_id of invoice in 7.1 - # this is for backward compatibility in 7.0 before + # this is for backward compatibility in 7.0 before # the refactoring of res.partner if hasattr(inv, 'commercial_partner_id'): partner_id = inv.commercial_partner_id.id @@ -256,7 +257,7 @@ class AccountStatementCompletionRule(orm.Model): st_obj = self.pool.get('account.bank.statement.line') res = {} # As we have to iterate on each partner for each line, - # we memoize the pair to avoid + #  we memoize the pair to avoid # to redo computation for each line. # Following code can be done by a single SQL query # but this option is not really maintanable @@ -429,10 +430,10 @@ class AccountStatementLine(orm.Model): serialized = st_copy.setdefault(col.serialization_field, {}) serialized[k] = st_copy[k] for k in to_json_k: - st_copy[k] = simplejson.dumps(st_copy[k]) + st_copy[k] = simplejson.dumps(st_copy[k]) values.append(st_copy) return values - + def _insert_lines(self, cr, uid, statement_store, context=None): """ Do raw insert into database because ORM is awfully slow @@ -456,7 +457,7 @@ class AccountStatementLine(orm.Model): when cheking security. TODO / WARM: sparse fields are skipped by the method. IOW, if your completion rule update an sparse field, the updated value will never - be stored in the database. It would be safer to call the update method + be stored in the database. It would be safer to call the update method from the ORM for records updating this kind of fields. """ cols = self._get_available_columns([vals]) @@ -552,7 +553,7 @@ class AccountBankSatement(orm.Model): st += ''.join(traceback.format_tb(trbk, 30)) _logger.error(st) if res: - #stat_line_obj.write(cr, uid, [line.id], vals, context=ctx) + # stat_line_obj.write(cr, uid, [line.id], vals, context=ctx) try: stat_line_obj._update_line(cr, uid, res, context=context) except Exception as exc: From f65e3a3a57df40074110bc7e06e4106febdffe0c Mon Sep 17 00:00:00 2001 From: Graeme Gellatly Date: Sun, 2 Feb 2014 22:48:28 +1300 Subject: [PATCH 5/5] [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 = {