From 760a4781becac4dcd5929f87676313231ff3290d Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Mon, 13 Jan 2014 16:14:02 +0100 Subject: [PATCH 1/4] Add new hook to build values of the statement from he parser and the profile --- account_statement_base_import/statement.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 97e8e8ab..51fbb08c 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -90,7 +90,7 @@ class AccountStatementProfil(Model): statement_id, context): """ Hook to build the values of a line from the parser returned values. At - least it fullfill the statement_id and account_id. Overide it to add your + least it fullfill the statement_id and account_id. Override it to add your own completion if needed. :param dict of vals from parser for account.bank.statement.line (called by @@ -126,6 +126,13 @@ class AccountStatementProfil(Model): values['type'] = 'general' return values + def prepare_statement_vals(self, cr, uid, profile_id, result_row_list, parser, context): + """ + Hook to build the values of the statement from the parser and + the profile. + """ + return {'profile_id': profile_id} + def statement_import(self, cr, uid, ids, profile_id, file_stream, ftype="csv", context=None): """ Create a bank statement with the given profile and parser. It will fullfill the bank statement @@ -159,9 +166,11 @@ class AccountStatementProfil(Model): _("Column %s you try to import is not " "present in the bank statement line!") % col) + statement_vals = self.prepare_statement_vals(cr, uid, prof.id, result_row_list, parser, context) statement_id = statement_obj.create(cr, uid, - {'profile_id': prof.id}, + statement_vals, context=context) + if prof.receivable_account_id: account_receivable = account_payable = prof.receivable_account_id.id else: From bc879326ed542d241c634ca71990a7d97cc6174f Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Tue, 14 Jan 2014 15:37:18 +0100 Subject: [PATCH 2/4] PEP 8 --- account_statement_base_completion/statement.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 96ab741b..d1a028c3 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -182,7 +182,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 @@ -459,7 +459,7 @@ class AccountStatementLine(orm.Model): """ statement_line_obj = self.pool['account.bank.statement.line'] model_cols = statement_line_obj._columns - sparse_fields = dict([(k , col) for k, col in model_cols.iteritems() if isinstance(col, fields.sparse) and col._type == 'char']) + sparse_fields = dict([(k, col) for k, col in model_cols.iteritems() if isinstance(col, fields.sparse) and col._type == 'char']) values = [] for statement in statement_store: to_json_k = set() @@ -470,10 +470,9 @@ 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 @@ -497,7 +496,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]) From e6bb1337c5734ccdb339a4a0f22c7487ca1b198d Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Tue, 14 Jan 2014 16:50:19 +0100 Subject: [PATCH 3/4] add new method to the parser that can be used to provide statement info found in the parsed file --- account_statement_base_import/parser/parser.py | 8 ++++++++ account_statement_base_import/statement.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index 377548b2..ad9f6c99 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -110,6 +110,14 @@ class BankStatementImportParser(object): """ return NotImplementedError + def get_st_vals(self): + """ + This method return a dict of vals that ca be passed to + create method of statement. + :return: dict of vals that represent additional infos for the statement + """ + return {} + def get_st_line_vals(self, line, *args, **kwargs): """ Implement a method in your parser that must return a dict of vals that can be diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 51fbb08c..8da3c7b3 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -131,7 +131,9 @@ class AccountStatementProfil(Model): Hook to build the values of the statement from the parser and the profile. """ - return {'profile_id': profile_id} + vals = {'profile_id': profile_id} + vals.update(parser.get_st_vals()) + return vals def statement_import(self, cr, uid, ids, profile_id, file_stream, ftype="csv", context=None): """ From 1e0c40e3a1117de0ab1aa2b2d864ee0eb5a52549 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Tue, 21 Jan 2014 17:50:31 +0100 Subject: [PATCH 4/4] pep8 --- account_statement_commission/commission.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/account_statement_commission/commission.py b/account_statement_commission/commission.py index 09f1fddc..b98227b8 100644 --- a/account_statement_commission/commission.py +++ b/account_statement_commission/commission.py @@ -2,9 +2,11 @@ from openerp.tools.translate import _ import datetime from openerp.osv import orm, fields + def float_or_zero(val): return float(val) if val else 0.0 + class AccountStatementProfil(orm.Model): _inherit = "account.statement.profile" @@ -36,6 +38,7 @@ class AccountStatementProfil(orm.Model): statement_line_obj = self.pool.get('account.bank.statement.line') statement_line_obj.create(cr, uid, comm_values, context=context) + class AccountStatementLineWithCommission(orm.Model): _inherit = "account.bank.statement.line" _columns = { @@ -45,6 +48,7 @@ class AccountStatementLineWithCommission(orm.Model): serialization_field='additionnal_bank_fields'), } + class CreditPartnerStatementImporter(orm.TransientModel): _inherit = "credit.statement.import"