From 69b28c9ed37db6b4b37ee1cf9f489ac602561114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Beau?= Date: Fri, 14 Jun 2013 18:09:31 +0200 Subject: [PATCH 01/48] [INIT] add module account_statement_simple_view --- account_statement_simple_view/__init__.py | 22 ++++++++++ account_statement_simple_view/__openerp__.py | 41 +++++++++++++++++++ .../statement_view.xml | 29 +++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 account_statement_simple_view/__init__.py create mode 100644 account_statement_simple_view/__openerp__.py create mode 100644 account_statement_simple_view/statement_view.xml diff --git a/account_statement_simple_view/__init__.py b/account_statement_simple_view/__init__.py new file mode 100644 index 00000000..b50f6309 --- /dev/null +++ b/account_statement_simple_view/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# account_bank_statement_simple_view for OpenERP +# Copyright (C) 2013-TODAY Akretion . +# @author Sébastien BEAU +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + diff --git a/account_statement_simple_view/__openerp__.py b/account_statement_simple_view/__openerp__.py new file mode 100644 index 00000000..ee75594a --- /dev/null +++ b/account_statement_simple_view/__openerp__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# account_statement_simple_view for OpenERP +# Copyright (C) 2013-TODAY Akretion . +# @author Sébastien BEAU +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +{ + 'name': 'account_bank_statement_simple_view', + 'version': '0.1', + 'category': 'Generic Modules/Others', + 'license': 'AGPL-3', + 'description': """Module that remove the useless import button on bank statement and also the useless red icon on bank statement line""", + 'author': 'Akretion', + 'website': 'http://www.akretion.com/', + 'depends': [ + 'account_statement_base_import', + ], + 'init_xml': [], + 'update_xml': [ + 'statement_view.xml', + ], + 'demo_xml': [], + 'installable': True, + 'active': False, +} diff --git a/account_statement_simple_view/statement_view.xml b/account_statement_simple_view/statement_view.xml new file mode 100644 index 00000000..682d93b2 --- /dev/null +++ b/account_statement_simple_view/statement_view.xml @@ -0,0 +1,29 @@ + + + + + + + + + + account_bank_statement_simple_view.account_bank_statement.view_form + account.bank.statement + + + form + +
+
+ + + +
+
+ +
+
From b6cb19e401f9bc3256c5cc289a084ae5631a9ea0 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 14:41:23 +0100 Subject: [PATCH 02/48] [FIX] fix api and put the incorrect method in deprecated --- account_statement_base_import/statement.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 97e8e8ab..d8badee2 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -85,7 +85,12 @@ class AccountStatementProfil(Model): context=context) return True - def prepare_statetement_lines_vals( + #Deprecated remove on V8 + def prepare_statetement_lines_vals(self, *args, **kwargs): + return super(self, AccountStatementProfil).\ + prepare_statetement_lines_vals(*args, **kwargs) + + def prepare_statement_lines_vals( self, cr, uid, parser_vals, account_payable, account_receivable, statement_id, context): """ @@ -172,7 +177,7 @@ class AccountStatementProfil(Model): statement_store = [] for line in result_row_list: parser_vals = parser.get_st_line_vals(line) - values = self.prepare_statetement_lines_vals( + values = self.prepare_statement_lines_vals( cr, uid, parser_vals, account_payable, account_receivable, statement_id, context) statement_store.append(values) From 4933e28d0670572805857d8a56fcd74352740e4d Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 17:13:46 +0100 Subject: [PATCH 03/48] [REF] remove useless unlink as the raise osv will roolback the cursor --- account_statement_base_import/statement.py | 1 - 1 file changed, 1 deletion(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index d8badee2..56fad9c0 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -212,7 +212,6 @@ class AccountStatementProfil(Model): context) except Exception: - statement_obj.unlink(cr, uid, [statement_id], context=context) error_type, error_value, trbk = sys.exc_info() st = "Error: %s\nDescription: %s\nTraceback:" % (error_type.__name__, error_value) st += ''.join(traceback.format_tb(trbk, 30)) From d1e1c06364139d6c2c51563b447a93d33adc7c1f Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 17:25:04 +0100 Subject: [PATCH 04/48] [REF] rename OpenERP class AccountBankSatement into AccountBankStatement --- .../account.py | 4 ++-- account_statement_base_completion/statement.py | 2 +- account_statement_ext/statement.py | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/account_advanced_reconcile_transaction_ref/account.py b/account_advanced_reconcile_transaction_ref/account.py index 0525de31..b3e2cd24 100644 --- a/account_advanced_reconcile_transaction_ref/account.py +++ b/account_advanced_reconcile_transaction_ref/account.py @@ -30,7 +30,7 @@ class AccountMoveLine(Model): 'transaction_ref': fields.char('Transaction Ref.', size=128), } -class AccountBankSatement(Model): +class AccountBankStatement(Model): """ Inherit account.bank.statement class in order to set transaction_ref info on account.move.line """ @@ -43,7 +43,7 @@ class AccountBankSatement(Model): if context is None: context = {} - res = super(AccountBankSatement, self)._prepare_move_line_vals( + res = super(AccountBankStatement, self)._prepare_move_line_vals( cr, uid, st_line, move_id, debit, credit, currency_id=currency_id, amount_currency=amount_currency, diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 96ab741b..d9782252 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -511,7 +511,7 @@ class AccountStatementLine(orm.Model): sql_err.pgerror) -class AccountBankSatement(orm.Model): +class AccountBankStatement(orm.Model): """ We add a basic button and stuff to support the auto-completion of the bank statement once line have been imported or manually fullfill. diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index f8762054..48667715 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -113,7 +113,7 @@ class AccountStatementProfile(Model): ] -class AccountBankSatement(Model): +class AccountBankStatement(Model): """ We improve the bank statement class mostly for : - Removing the period and compute it from the date of each line. @@ -202,7 +202,7 @@ class AccountBankSatement(Model): profile_obj = self.pool.get('account.statement.profile') profile = profile_obj.browse(cr, uid, vals['profile_id'], context=context) vals['journal_id'] = profile.journal_id.id - return super(AccountBankSatement, self).create(cr, uid, vals, context=context) + return super(AccountBankStatement, self).create(cr, uid, vals, context=context) def _get_period(self, cr, uid, date, context=None): """ @@ -243,7 +243,7 @@ class AccountBankSatement(Model): """ if context is None: context = {} - res = super(AccountBankSatement, self)._prepare_move( + res = super(AccountBankStatement, self)._prepare_move( cr, uid, st_line, st_line_number, context=context) ctx = context.copy() ctx['company_id'] = st_line.company_id.id @@ -273,7 +273,7 @@ class AccountBankSatement(Model): """ if context is None: context = {} - res = super(AccountBankSatement, self)._prepare_move_line_vals( + res = super(AccountBankStatement, self)._prepare_move_line_vals( cr, uid, st_line, move_id, debit, credit, currency_id=currency_id, amount_currency=amount_currency, @@ -297,7 +297,7 @@ class AccountBankSatement(Model): create the move from. :return: int/long of the res.partner to use as counterpart """ - bank_partner_id = super(AccountBankSatement, self)._get_counter_part_partner(cr, + bank_partner_id = super(AccountBankStatement, self)._get_counter_part_partner(cr, uid, st_line, context=context) @@ -530,7 +530,7 @@ class AccountBankSatement(Model): """ st = self.browse(cr, uid, st_id, context=context) if st.balance_check: - return super(AccountBankSatement, self).balance_check( + return super(AccountBankStatement, self).balance_check( cr, uid, st_id, journal_type, context=context) else: return True @@ -555,7 +555,7 @@ class AccountBankSatement(Model): 'credit_partner_id': credit_partner_id}} -class AccountBankSatementLine(Model): +class AccountBankStatementLine(Model): """ Override to compute the period from the date of the line, add a method to retrieve the values for a line from the profile. Override the on_change method to take care of @@ -684,7 +684,7 @@ class AccountBankSatementLine(Model): Keep the same features as in standard and call super. If an account is returned, call the method to compute line values. """ - res = super(AccountBankSatementLine, self).onchange_type(cr, uid, + res = super(AccountBankStatementLine, self).onchange_type(cr, uid, line_id, partner_id, line_type, From 0164efeae71a14f040bedad7a61d3a910db32817 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 11 Dec 2013 17:18:58 +0100 Subject: [PATCH 05/48] [IMP] hide useless red button of voucher_id on the statement line --- statement_voucher_killer/__openerp__.py | 6 ++--- statement_voucher_killer/statement_view.xml | 25 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 statement_voucher_killer/statement_view.xml diff --git a/statement_voucher_killer/__openerp__.py b/statement_voucher_killer/__openerp__.py index 2460cd9a..1e5f2f1d 100644 --- a/statement_voucher_killer/__openerp__.py +++ b/statement_voucher_killer/__openerp__.py @@ -39,9 +39,9 @@ line will be take from imported line in this order: 'author': 'Camptocamp', 'website': 'http://www.camptocamp.com', 'depends': ['account_voucher', 'account_payment'], - 'init_xml': [], - 'update_xml': [], - 'demo_xml': [], + 'data': [ + 'statement_view.xml', + ], 'test': [], 'installable': True, 'active': False, diff --git a/statement_voucher_killer/statement_view.xml b/statement_voucher_killer/statement_view.xml new file mode 100644 index 00000000..5aee5c28 --- /dev/null +++ b/statement_voucher_killer/statement_view.xml @@ -0,0 +1,25 @@ + + + + + + + + + + account.bank.statement + + + form + + + + + + + + From fcdfe6ac6ccc8f3e8653e2831aa93f25d40df3df Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 11 Dec 2013 17:19:03 +0100 Subject: [PATCH 06/48] [REF] move the replace of the voucher_id into the statement_voucher_killer and rename simple_view in no_invoice_import' --- .../__init__.py | 2 +- .../__openerp__.py | 8 ++++---- .../statement_view.xml | 3 --- 3 files changed, 5 insertions(+), 8 deletions(-) rename {account_statement_simple_view => account_statement_no_invoice_import}/__init__.py (95%) rename {account_statement_simple_view => account_statement_no_invoice_import}/__openerp__.py (82%) rename {account_statement_simple_view => account_statement_no_invoice_import}/statement_view.xml (91%) diff --git a/account_statement_simple_view/__init__.py b/account_statement_no_invoice_import/__init__.py similarity index 95% rename from account_statement_simple_view/__init__.py rename to account_statement_no_invoice_import/__init__.py index b50f6309..b42d6e1b 100644 --- a/account_statement_simple_view/__init__.py +++ b/account_statement_no_invoice_import/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################### # -# account_bank_statement_simple_view for OpenERP +# module for OpenERP # Copyright (C) 2013-TODAY Akretion . # @author Sébastien BEAU # diff --git a/account_statement_simple_view/__openerp__.py b/account_statement_no_invoice_import/__openerp__.py similarity index 82% rename from account_statement_simple_view/__openerp__.py rename to account_statement_no_invoice_import/__openerp__.py index ee75594a..d2c8be37 100644 --- a/account_statement_simple_view/__openerp__.py +++ b/account_statement_no_invoice_import/__openerp__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################### # -# account_statement_simple_view for OpenERP +# module for OpenERP # Copyright (C) 2013-TODAY Akretion . # @author Sébastien BEAU # @@ -21,15 +21,15 @@ ############################################################################### { - 'name': 'account_bank_statement_simple_view', + 'name': 'account bank statement no invoice import', 'version': '0.1', 'category': 'Generic Modules/Others', 'license': 'AGPL-3', - 'description': """Module that remove the useless import button on bank statement and also the useless red icon on bank statement line""", + 'description': """Module that remove the import button on bank statement""", 'author': 'Akretion', 'website': 'http://www.akretion.com/', 'depends': [ - 'account_statement_base_import', + 'account', ], 'init_xml': [], 'update_xml': [ diff --git a/account_statement_simple_view/statement_view.xml b/account_statement_no_invoice_import/statement_view.xml similarity index 91% rename from account_statement_simple_view/statement_view.xml rename to account_statement_no_invoice_import/statement_view.xml index 682d93b2..3ecd4567 100644 --- a/account_statement_simple_view/statement_view.xml +++ b/account_statement_no_invoice_import/statement_view.xml @@ -19,9 +19,6 @@
- - -
From a346f295ddf904f1500e216f3cbb17892c5418e8 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 11 Dec 2013 17:22:17 +0100 Subject: [PATCH 07/48] [REF] remove useless comment --- account_statement_no_invoice_import/statement_view.xml | 5 ----- statement_voucher_killer/statement_view.xml | 5 ----- 2 files changed, 10 deletions(-) diff --git a/account_statement_no_invoice_import/statement_view.xml b/account_statement_no_invoice_import/statement_view.xml index 3ecd4567..663de0d2 100644 --- a/account_statement_no_invoice_import/statement_view.xml +++ b/account_statement_no_invoice_import/statement_view.xml @@ -1,9 +1,4 @@ - diff --git a/statement_voucher_killer/statement_view.xml b/statement_voucher_killer/statement_view.xml index 5aee5c28..e0ceda0a 100644 --- a/statement_voucher_killer/statement_view.xml +++ b/statement_voucher_killer/statement_view.xml @@ -1,9 +1,4 @@ - From 3e4eb1095838e907b8007fdace776cd63b294bea Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 24 Dec 2013 19:16:40 +0100 Subject: [PATCH 08/48] [IMP] account_statement_base_import: private method that returns import type to ease inheritance [IMP] account_statement_ofx_import: changed accordingly previous improvement --- account_statement_base_import/statement.py | 9 +++++---- account_statement_ofx_import/statement.py | 13 +------------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 97e8e8ab..e2057bc2 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -31,12 +31,13 @@ from parser import new_bank_statement_parser class AccountStatementProfil(Model): _inherit = "account.statement.profile" - def get_import_type_selection(self, cr, uid, context=None): - """ - Has to be inherited to add parser - """ + def _get_import_type_selection(self, cr, uid, context=None): + """This is the method to be inherited for adding the parser""" return [('generic_csvxls_so', 'Generic .csv/.xls based on SO Name')] + def get_import_type_selection(self, cr, uid, context=None): + return _get_import_type selection(cr, uid, context=context) + _columns = { 'launch_import_completion': fields.boolean( "Launch completion after import", diff --git a/account_statement_ofx_import/statement.py b/account_statement_ofx_import/statement.py index c5b06fe8..bc31980a 100644 --- a/account_statement_ofx_import/statement.py +++ b/account_statement_ofx_import/statement.py @@ -24,7 +24,7 @@ from openerp.osv import fields, orm class AccountStatementProfil(orm.Model): _inherit = "account.statement.profile" - def get_import_type_selection(self, cr, uid, context=None): + def _get_import_type_selection(self, cr, uid, context=None): """ Inherited from parent to add parser. """ @@ -33,14 +33,3 @@ class AccountStatementProfil(orm.Model): context=context) selection.append(('ofx_so', _('OFX - Open Financial Exchange'))) return selection - - _columns = { - 'import_type': fields.selection( - get_import_type_selection, - 'Type of import', - required=True, - help="Choose here the method by which you want to import bank" - "statement for this profile."), - - } - From 760a4781becac4dcd5929f87676313231ff3290d Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Mon, 13 Jan 2014 16:14:02 +0100 Subject: [PATCH 09/48] 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 10/48] 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 d5ecec5a41f6910e94019d3ca86ae4eb89f039fd Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Tue, 14 Jan 2014 15:39:02 +0100 Subject: [PATCH 11/48] Add the possibility to use instance of account.statement.completion.rule --- account_statement_base_completion/statement.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 96ab741b..b54803e1 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -23,6 +23,7 @@ import traceback import sys import logging import simplejson +import inspect import psycopg2 @@ -79,8 +80,7 @@ class AccountStatementProfil(orm.Model): else: prof = profile # We need to respect the sequence order - sorted_array = sorted(prof.rule_ids, key=attrgetter('sequence')) - return tuple((x.function_to_call for x in sorted_array)) + return sorted(prof.rule_ids, key=attrgetter('sequence')) def _find_values_from_rules(self, cr, uid, calls, line, context=None): """ @@ -103,8 +103,11 @@ class AccountStatementProfil(orm.Model): rule_obj = self.pool.get('account.statement.completion.rule') for call in calls: - method_to_call = getattr(rule_obj, call) - result = method_to_call(cr, uid, line, context) + method_to_call = getattr(rule_obj, call.function_to_call) + if len(inspect.getargspec(method_to_call)) == 5: + result = method_to_call(cr, uid, call.id, line, context) + else: + result = method_to_call(cr, uid, line, context) if result: result['already_completed'] = True return result From 6ca1e05c966ef1f25e747c6a7e1da4b915286b18 Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Tue, 14 Jan 2014 16:27:23 +0100 Subject: [PATCH 12/48] rename _get_callable in _get_rules. Correct the args len. --- account_statement_base_completion/statement.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index b54803e1..cd5174c3 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -74,7 +74,7 @@ class AccountStatementProfil(orm.Model): rel='as_rul_st_prof_rel'), } - def _get_callable(self, cr, uid, profile, context=None): + def _get_rules(self, cr, uid, profile, context=None): if isinstance(profile, (int, long)): prof = self.browse(cr, uid, profile, context=context) else: @@ -99,12 +99,12 @@ class AccountStatementProfil(orm.Model): if context is None: context = {} if not calls: - calls = self._get_callable(cr, uid, line['profile_id'], context=context) + calls = self._get_rules(cr, uid, line['profile_id'], context=context) rule_obj = self.pool.get('account.statement.completion.rule') for call in calls: method_to_call = getattr(rule_obj, call.function_to_call) - if len(inspect.getargspec(method_to_call)) == 5: + if len(inspect.getargspec(method_to_call).args) == 6: result = method_to_call(cr, uid, call.id, line, context) else: result = method_to_call(cr, uid, line, context) @@ -573,7 +573,7 @@ class AccountBankSatement(orm.Model): ctx = context.copy() ctx['line_ids'] = tuple((x.id for x in stat.line_ids)) b_profile = stat.profile_id - rules = profile_obj._get_callable(cr, uid, b_profile, context=context) + rules = profile_obj._get_rules(cr, uid, b_profile, context=context) profile_id = b_profile.id # Only for perfo even it gains almost nothing master_account_id = b_profile.receivable_account_id master_account_id = master_account_id.id if master_account_id else False From e6bb1337c5734ccdb339a4a0f22c7487ca1b198d Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Tue, 14 Jan 2014 16:50:19 +0100 Subject: [PATCH 13/48] 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 220eef50ec7c8b51eca6139d4970a82dad27c159 Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Tue, 14 Jan 2014 19:16:23 +0100 Subject: [PATCH 14/48] Add new completion rules to set a specific account in function of regex on name --- .../__init__.py | 21 +++++ .../__openerp__.py | 56 +++++++++++ .../data.xml | 12 +++ .../statement.py | 75 +++++++++++++++ .../statement_view.xml | 21 +++++ .../tests/__init__.py | 36 ++++++++ .../tests/test_regex_account_completion.py | 92 +++++++++++++++++++ 7 files changed, 313 insertions(+) create mode 100644 account_statement_regex_account_completion/__init__.py create mode 100644 account_statement_regex_account_completion/__openerp__.py create mode 100644 account_statement_regex_account_completion/data.xml create mode 100644 account_statement_regex_account_completion/statement.py create mode 100644 account_statement_regex_account_completion/statement_view.xml create mode 100644 account_statement_regex_account_completion/tests/__init__.py create mode 100644 account_statement_regex_account_completion/tests/test_regex_account_completion.py diff --git a/account_statement_regex_account_completion/__init__.py b/account_statement_regex_account_completion/__init__.py new file mode 100644 index 00000000..133223b9 --- /dev/null +++ b/account_statement_regex_account_completion/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# +# +# Author: Laurent Mignon +# Copyright 2013 'ACSONE SA/NV' +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# +import statement diff --git a/account_statement_regex_account_completion/__openerp__.py b/account_statement_regex_account_completion/__openerp__.py new file mode 100644 index 00000000..b8f937c9 --- /dev/null +++ b/account_statement_regex_account_completion/__openerp__.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Authors: Laetitia Gangloff +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + "name": "Account Statement Regex Account Completion addon", + "version": "0.1", + "author": "ACSONE SA/NV", + "category": "Other", + "website": "http://www.acsone.eu", + "depends": ["account_statement_base_completion", + ], + "description": """ + +Account Statement Regex Account Completion addon +========================= + +- Add a completion method based on a specified regular expression + and update account to use in the bank statement line with the specified account. +""", + "data": [#'statement_view.xml', + ], + "demo": [], + "test": [], + "active": False, + "license": "AGPL-3", + "installable": True, + "auto_install": False, + "application": False, +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_statement_regex_account_completion/data.xml b/account_statement_regex_account_completion/data.xml new file mode 100644 index 00000000..a6a84429 --- /dev/null +++ b/account_statement_regex_account_completion/data.xml @@ -0,0 +1,12 @@ + + + + + + Match from bank account number (Nomal or IBAN)) + 10 + get_from_bank_account + + + + diff --git a/account_statement_regex_account_completion/statement.py b/account_statement_regex_account_completion/statement.py new file mode 100644 index 00000000..72213e30 --- /dev/null +++ b/account_statement_regex_account_completion/statement.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Authors: Laetitia Gangloff +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +from openerp.osv.orm import Model +from openerp.osv import fields + +import re + + +class AccountStatementCompletionRule(Model): + """Add a rule to complete account based on a regular expression""" + + _inherit = "account.statement.completion.rule" + + def _get_functions(self, cr, uid, context=None): + res = super(AccountStatementCompletionRule, self)._get_functions( + cr, uid, context=context) + res.append(('set_account', + 'Set account')) + return res + + _columns = { + 'function_to_call': fields.selection(_get_functions, 'Method'), + 'regexp': fields.char('Regular Expression', size=128), + 'account_id': fields.many2one('account.account', string="Account to set"), + } + + def set_account(self, cr, uid, id, st_line, context=None): + """ + If line name match regexp, update account_id + Then, call the generic st_line method to complete other values. + :param dict st_line: read of the concerned account.bank.statement.line + :return: + A dict of value that can be passed directly to the write method of + the statement line or {} + {'partner_id': value, + 'account_id' : value, + ...} + """ + name = st_line['name'] + res = {} + if name: + rule = self.browse(cr, uid, id, context=context) + if re.match(rule.regexp, name): + res['account_id'] = rule.account_id.id + return res + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_statement_regex_account_completion/statement_view.xml b/account_statement_regex_account_completion/statement_view.xml new file mode 100644 index 00000000..2dd4e204 --- /dev/null +++ b/account_statement_regex_account_completion/statement_view.xml @@ -0,0 +1,21 @@ + + + + + + account.statement.completion.rule.view (account_statement_regex_account_completion) + account.statement.completion.rule + + form + + + + + + + + + + + + diff --git a/account_statement_regex_account_completion/tests/__init__.py b/account_statement_regex_account_completion/tests/__init__.py new file mode 100644 index 00000000..826f535a --- /dev/null +++ b/account_statement_regex_account_completion/tests/__init__.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Authors: Laetitia Gangloff +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import test_regex_account_completion + +checks = [ + test_regex_account_completion +] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_statement_regex_account_completion/tests/test_regex_account_completion.py b/account_statement_regex_account_completion/tests/test_regex_account_completion.py new file mode 100644 index 00000000..7fa62081 --- /dev/null +++ b/account_statement_regex_account_completion/tests/test_regex_account_completion.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Authors: Laetitia Gangloff +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.tests import common +import time + +ACC_NUMBER = "BE38733040385372" + + +class test_regex_account_completion(common.TransactionCase): + + def prepare(self): + self.account_bank_statement_obj = self.registry("account.bank.statement") + self.account_bank_statement_line_obj = self.registry("account.bank.statement.line") + self.account_id = self.ref('account.a_expense') + # create the completion rule + rule_vals = {'function_to_call': 'set_account', + 'regex': '^My statement', + 'account_id': self.account_id} + self.completion_rule_id = self.registry("account.statement.completion.rule").create(self.cr, self.uid, rule_vals) + + # Create the profile + self.journal_id = self.ref("account.bank_journal") + self.profile_id = self.registry("account.statement.profile").create(self.cr, self.uid, { + "name": "TEST", + "commission_account_id": self.ref("account.a_recv"), + "journal_id": self.journal_id, + "rule_ids": [(6, 0, [self.completion_rule_id])]}) + + # Create a bank statement + self.statement_id = self.account_bank_statement_obj.create(self.cr, self.uid, { + "balance_end_real": 0.0, + "balance_start": 0.0, + "date": time.strftime('%Y-%m-%d'), + "journal_id": self.journal_id, + "profile_id": self.profile_id + }) + + # Create two bank statement lines + self.statement_line1_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, { + 'amount': 1000.0, + 'name': 'My statement', + 'ref': 'My ref', + 'statement_id': self.statement_id, + 'partner_acc_number': ACC_NUMBER + }) + + self.statement_line2_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, { + 'amount': 2000.0, + 'name': 'My second statement', + 'ref': 'My second ref', + 'statement_id': self.statement_id, + 'partner_acc_number': ACC_NUMBER + }) + + def test_00(self): + """Test the automatic completion on account + """ + self.prepare() + statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, self.statement_line_id) + # before import, the + self.assertFalse(statement_line.partner_id, "Partner_id must be blank before completion") + statement_obj = self.account_bank_statement_obj.browse(self.cr, self.uid, self.statement_id) + statement_obj.button_auto_completion() + statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, self.statement_line_id) + self.assertEquals(self.partner_id, statement_line.partner_id['id'], "Missing expected partner id after completion") From ac777e58fedb1d49717a75c9544ba8a4fb0dde7a Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Wed, 15 Jan 2014 10:28:54 +0100 Subject: [PATCH 15/48] Remove unused data file. Add view in __openerp__.py. --- .../__init__.py | 19 +++++++++++++++---- .../__openerp__.py | 2 +- .../data.xml | 12 ------------ 3 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 account_statement_regex_account_completion/data.xml diff --git a/account_statement_regex_account_completion/__init__.py b/account_statement_regex_account_completion/__init__.py index 133223b9..41101e40 100644 --- a/account_statement_regex_account_completion/__init__.py +++ b/account_statement_regex_account_completion/__init__.py @@ -1,8 +1,16 @@ # -*- coding: utf-8 -*- +############################################################################## # +# Authors: Laetitia Gangloff +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved # -# Author: Laurent Mignon -# Copyright 2013 'ACSONE SA/NV' +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -17,5 +25,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # -# -import statement +############################################################################## + +from . import statement + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_statement_regex_account_completion/__openerp__.py b/account_statement_regex_account_completion/__openerp__.py index b8f937c9..9acb1940 100644 --- a/account_statement_regex_account_completion/__openerp__.py +++ b/account_statement_regex_account_completion/__openerp__.py @@ -43,7 +43,7 @@ Account Statement Regex Account Completion addon - Add a completion method based on a specified regular expression and update account to use in the bank statement line with the specified account. """, - "data": [#'statement_view.xml', + "data": ['statement_view.xml', ], "demo": [], "test": [], diff --git a/account_statement_regex_account_completion/data.xml b/account_statement_regex_account_completion/data.xml deleted file mode 100644 index a6a84429..00000000 --- a/account_statement_regex_account_completion/data.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Match from bank account number (Nomal or IBAN)) - 10 - get_from_bank_account - - - - From cd86039a596c3e57b14a8df92a65b3e9f63a1720 Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Wed, 15 Jan 2014 13:30:10 +0100 Subject: [PATCH 16/48] rename some regexp to regex --- account_statement_regex_account_completion/statement.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/account_statement_regex_account_completion/statement.py b/account_statement_regex_account_completion/statement.py index 72213e30..179a0c62 100644 --- a/account_statement_regex_account_completion/statement.py +++ b/account_statement_regex_account_completion/statement.py @@ -48,13 +48,13 @@ class AccountStatementCompletionRule(Model): _columns = { 'function_to_call': fields.selection(_get_functions, 'Method'), - 'regexp': fields.char('Regular Expression', size=128), + 'regex': fields.char('Regular Expression', size=128), 'account_id': fields.many2one('account.account', string="Account to set"), } def set_account(self, cr, uid, id, st_line, context=None): """ - If line name match regexp, update account_id + If line name match regex, update account_id Then, call the generic st_line method to complete other values. :param dict st_line: read of the concerned account.bank.statement.line :return: @@ -68,7 +68,7 @@ class AccountStatementCompletionRule(Model): res = {} if name: rule = self.browse(cr, uid, id, context=context) - if re.match(rule.regexp, name): + if re.match(rule.regex, name): res['account_id'] = rule.account_id.id return res From a29bc87b97fe30775797cbaf1f96b8999d4d91ae Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Wed, 15 Jan 2014 13:54:22 +0100 Subject: [PATCH 17/48] correct test --- .../tests/test_regex_account_completion.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/account_statement_regex_account_completion/tests/test_regex_account_completion.py b/account_statement_regex_account_completion/tests/test_regex_account_completion.py index 7fa62081..64958844 100644 --- a/account_statement_regex_account_completion/tests/test_regex_account_completion.py +++ b/account_statement_regex_account_completion/tests/test_regex_account_completion.py @@ -43,23 +43,23 @@ class test_regex_account_completion(common.TransactionCase): rule_vals = {'function_to_call': 'set_account', 'regex': '^My statement', 'account_id': self.account_id} - self.completion_rule_id = self.registry("account.statement.completion.rule").create(self.cr, self.uid, rule_vals) + completion_rule_id = self.registry("account.statement.completion.rule").create(self.cr, self.uid, rule_vals) # Create the profile - self.journal_id = self.ref("account.bank_journal") - self.profile_id = self.registry("account.statement.profile").create(self.cr, self.uid, { + journal_id = self.ref("account.bank_journal") + profile_id = self.registry("account.statement.profile").create(self.cr, self.uid, { "name": "TEST", "commission_account_id": self.ref("account.a_recv"), - "journal_id": self.journal_id, - "rule_ids": [(6, 0, [self.completion_rule_id])]}) + "journal_id": journal_id, + "rule_ids": [(6, 0, [completion_rule_id])]}) # Create a bank statement self.statement_id = self.account_bank_statement_obj.create(self.cr, self.uid, { "balance_end_real": 0.0, "balance_start": 0.0, "date": time.strftime('%Y-%m-%d'), - "journal_id": self.journal_id, - "profile_id": self.profile_id + "journal_id": journal_id, + "profile_id": profile_id }) # Create two bank statement lines @@ -83,10 +83,9 @@ class test_regex_account_completion(common.TransactionCase): """Test the automatic completion on account """ self.prepare() - statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, self.statement_line_id) - # before import, the - self.assertFalse(statement_line.partner_id, "Partner_id must be blank before completion") statement_obj = self.account_bank_statement_obj.browse(self.cr, self.uid, self.statement_id) statement_obj.button_auto_completion() - statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, self.statement_line_id) - self.assertEquals(self.partner_id, statement_line.partner_id['id'], "Missing expected partner id after completion") + statement_line1 = self.account_bank_statement_line_obj.browse(self.cr, self.uid, self.statement_line1_id) + self.assertEquals(self.account_id, statement_line1.account_id.id, "The account should be the account of the completion") + statement_line2 = self.account_bank_statement_line_obj.browse(self.cr, self.uid, self.statement_line2_id) + self.assertNotEqual(self.account_id, statement_line2.account_id.id, "The account should be not the account of the completion") From df53643070492311431acea67fbcc4ba7bc7955b Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 17 Jan 2014 14:20:56 +0100 Subject: [PATCH 18/48] Only commercial partners are allowed in bank statement lines --- account_statement_ext/statement.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 80edbfcc..2ca8627b 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -655,6 +655,8 @@ class AccountBankSatementLine(Model): # This can be quite a performance killer as we read ir.properity fields if partner_id: part = obj_partner.browse(cr, uid, partner_id, context=context) + part = part.commercial_partner_id + res['partner_id'] = part.id pay_account = part.property_account_payable.id receiv_account = part.property_account_receivable.id # If no value, look on the default company property From fda091b8d4d4892266c14cbd49886b47b37c65e4 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 17 Jan 2014 15:10:42 +0100 Subject: [PATCH 19/48] explain the last change --- account_statement_ext/statement.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 2ca8627b..0a436ab2 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -656,6 +656,9 @@ class AccountBankSatementLine(Model): if partner_id: part = obj_partner.browse(cr, uid, partner_id, context=context) part = part.commercial_partner_id + # When the method is called from bank statement completion, + # ensure that the line's partner is a commercial + # (accounting) entity res['partner_id'] = part.id pay_account = part.property_account_payable.id receiv_account = part.property_account_receivable.id From b962fc2669b7773c993634b8dbb87b58ce074f5d Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Mon, 20 Jan 2014 10:06:39 +0100 Subject: [PATCH 20/48] update name of the funtion to 'Set account for line labels matching a regular expression' instead of 'Set account' --- account_statement_regex_account_completion/statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_regex_account_completion/statement.py b/account_statement_regex_account_completion/statement.py index 179a0c62..e54f136e 100644 --- a/account_statement_regex_account_completion/statement.py +++ b/account_statement_regex_account_completion/statement.py @@ -43,7 +43,7 @@ class AccountStatementCompletionRule(Model): res = super(AccountStatementCompletionRule, self)._get_functions( cr, uid, context=context) res.append(('set_account', - 'Set account')) + 'Set account for line labels matching a regular expression')) return res _columns = { From 3f1999ed8cea4d6ba273d486e8414f23dd2971df Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 21 Jan 2014 02:04:59 +0100 Subject: [PATCH 21/48] [IMP] account_statement_base_import: Inheritable method with public name. --- account_statement_base_import/statement.py | 9 ++++----- account_statement_ofx_import/statement.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index e2057bc2..3dbddd60 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -31,12 +31,12 @@ from parser import new_bank_statement_parser class AccountStatementProfil(Model): _inherit = "account.statement.profile" - def _get_import_type_selection(self, cr, uid, context=None): + def get_import_type_selection(self, cr, uid, context=None): """This is the method to be inherited for adding the parser""" return [('generic_csvxls_so', 'Generic .csv/.xls based on SO Name')] - def get_import_type_selection(self, cr, uid, context=None): - return _get_import_type selection(cr, uid, context=context) + def _get_import_type_selection(self, cr, uid, context=None): + return get_import_type selection(cr, uid, context=context) _columns = { 'launch_import_completion': fields.boolean( @@ -47,12 +47,11 @@ class AccountStatementProfil(Model): # we remove deprecated as it floods logs in standard/warning level sob... 'rec_log': fields.text('log', readonly=True), # Deprecated 'import_type': fields.selection( - get_import_type_selection, + _get_import_type_selection, 'Type of import', required=True, help="Choose here the method by which you want to import bank" "statement for this profile."), - } def _write_extra_statement_lines( diff --git a/account_statement_ofx_import/statement.py b/account_statement_ofx_import/statement.py index bc31980a..15060360 100644 --- a/account_statement_ofx_import/statement.py +++ b/account_statement_ofx_import/statement.py @@ -24,7 +24,7 @@ from openerp.osv import fields, orm class AccountStatementProfil(orm.Model): _inherit = "account.statement.profile" - def _get_import_type_selection(self, cr, uid, context=None): + def get_import_type_selection(self, cr, uid, context=None): """ Inherited from parent to add parser. """ From 1e0c40e3a1117de0ab1aa2b2d864ee0eb5a52549 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Tue, 21 Jan 2014 17:50:31 +0100 Subject: [PATCH 22/48] 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" From 9c570e8c257014970d9595e9e0e0de5e085156d8 Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Wed, 22 Jan 2014 12:17:19 +0100 Subject: [PATCH 23/48] add translation for account_statement_regex_account_completion module --- ...unt_statement_regex_account_completion.pot | 32 +++++++++++++++++++ .../i18n/fr.po | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 account_statement_regex_account_completion/i18n/account_statement_regex_account_completion.pot create mode 100644 account_statement_regex_account_completion/i18n/fr.po diff --git a/account_statement_regex_account_completion/i18n/account_statement_regex_account_completion.pot b/account_statement_regex_account_completion/i18n/account_statement_regex_account_completion.pot new file mode 100644 index 00000000..42587093 --- /dev/null +++ b/account_statement_regex_account_completion/i18n/account_statement_regex_account_completion.pot @@ -0,0 +1,32 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * account_statement_regex_account_completion +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-01-22 10:59+0000\n" +"PO-Revision-Date: 2014-01-22 10:59+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_statement_regex_account_completion +#: field:account.statement.completion.rule,regex:0 +msgid "Regular Expression" +msgstr "" + +#. module: account_statement_regex_account_completion +#: field:account.statement.completion.rule,account_id:0 +msgid "Account to set" +msgstr "" + +#. module: account_statement_regex_account_completion +#: model:ir.model,name:account_statement_regex_account_completion.model_account_statement_completion_rule +msgid "account.statement.completion.rule" +msgstr "" + diff --git a/account_statement_regex_account_completion/i18n/fr.po b/account_statement_regex_account_completion/i18n/fr.po new file mode 100644 index 00000000..5a06dfa3 --- /dev/null +++ b/account_statement_regex_account_completion/i18n/fr.po @@ -0,0 +1,32 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * account_statement_regex_account_completion +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-01-22 10:59+0000\n" +"PO-Revision-Date: 2014-01-22 10:59+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_statement_regex_account_completion +#: field:account.statement.completion.rule,regex:0 +msgid "Regular Expression" +msgstr "Expression Régulière" + +#. module: account_statement_regex_account_completion +#: field:account.statement.completion.rule,account_id:0 +msgid "Account to set" +msgstr "Compte à utiliser" + +#. module: account_statement_regex_account_completion +#: model:ir.model,name:account_statement_regex_account_completion.model_account_statement_completion_rule +msgid "account.statement.completion.rule" +msgstr "account.statement.completion.rule" + \ No newline at end of file From 05d2948ca561eda395cb3cf56641f5a745df99f6 Mon Sep 17 00:00:00 2001 From: Launchpad Translations on behalf of banking-addons-team Date: Fri, 24 Jan 2014 06:27:43 +0000 Subject: [PATCH 24/48] Launchpad automatic translations update. --- account_statement_regex_account_completion/i18n/fr.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/account_statement_regex_account_completion/i18n/fr.po b/account_statement_regex_account_completion/i18n/fr.po index 5a06dfa3..303b085b 100644 --- a/account_statement_regex_account_completion/i18n/fr.po +++ b/account_statement_regex_account_completion/i18n/fr.po @@ -7,13 +7,14 @@ msgstr "" "Project-Id-Version: OpenERP Server 7.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-01-22 10:59+0000\n" -"PO-Revision-Date: 2014-01-22 10:59+0000\n" -"Last-Translator: <>\n" +"PO-Revision-Date: 2014-01-23 17:42+0000\n" +"Last-Translator: Laetitia Gangloff (Acsone) \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2014-01-24 06:27+0000\n" +"X-Generator: Launchpad (build 16914)\n" #. module: account_statement_regex_account_completion #: field:account.statement.completion.rule,regex:0 @@ -29,4 +30,3 @@ msgstr "Compte à utiliser" #: model:ir.model,name:account_statement_regex_account_completion.model_account_statement_completion_rule msgid "account.statement.completion.rule" msgstr "account.statement.completion.rule" - \ No newline at end of file From de19604dc0926ec4ab516b411950ac4a884c9ffa Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 30 Jan 2014 13:48:51 +0100 Subject: [PATCH 25/48] [fix] on the first/last day on the year, avoid choosing the opening/closing period. --- account_statement_ext/statement.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 80edbfcc..4c249a37 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -213,7 +213,10 @@ class AccountBankSatement(Model): """ Find matching period for date, used in the statement line creation. """ + if context is None: + context = {} period_obj = self.pool.get('account.period') + context['account_period_prefer_normal'] = True periods = period_obj.find(cr, uid, dt=date, context=context) return periods and periods[0] or False From 12c51fa3c47bf2d001ce907ea61571bfdc437ea8 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 30 Jan 2014 14:01:20 +0100 Subject: [PATCH 26/48] [fix] copy the context before modifying it: safer upstream --- account_statement_ext/statement.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 4c249a37..e2c7cddd 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -216,8 +216,9 @@ class AccountBankSatement(Model): if context is None: context = {} period_obj = self.pool.get('account.period') - context['account_period_prefer_normal'] = True - periods = period_obj.find(cr, uid, dt=date, context=context) + local_context = context.copy() + local_context['account_period_prefer_normal'] = True + periods = period_obj.find(cr, uid, dt=date, context=local_context) return periods and periods[0] or False def _check_company_id(self, cr, uid, ids, context=None): From 0eb7bf7825c63bf6d038d72a3c11463db21ca820 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 30 Jan 2014 14:06:24 +0100 Subject: [PATCH 27/48] [imp] docstring --- account_statement_ext/statement.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index e2c7cddd..a41038ea 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -210,9 +210,7 @@ class AccountBankSatement(Model): return super(AccountBankSatement, self).create(cr, uid, vals, context=context) def _get_period(self, cr, uid, date, context=None): - """ - Find matching period for date, used in the statement line creation. - """ + """Return matching period for a date.""" if context is None: context = {} period_obj = self.pool.get('account.period') @@ -575,9 +573,7 @@ class AccountBankSatementLine(Model): _inherit = "account.bank.statement.line" def _get_period(self, cr, uid, context=None): - """ - Return a period from a given date in the context. - """ + """Return matching period for a date.""" if context is None: context = {} date = context.get('date') From 5c728ccd481c087186c5fe5470175d926b8692d7 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 30 Jan 2014 14:11:58 +0100 Subject: [PATCH 28/48] [fix] similarly fix another _get_period --- account_statement_ext/statement.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index a41038ea..3a5a95cf 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -576,9 +576,12 @@ class AccountBankSatementLine(Model): """Return matching period for a date.""" if context is None: context = {} + period_obj = self.pool['account.period'] date = context.get('date') + local_context = context.copy() + local_context['account_period_prefer_normal'] = True try: - periods = self.pool.get('account.period').find(cr, uid, dt=date) + periods = period_obj.find(cr, uid, dt=date, context=local_context) except osv.except_osv: # if no period defined, we are certainly at installation time return False From 0f7fa422b458800dd1b9d035d7232ffaf8dd28da Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Mon, 3 Feb 2014 10:16:01 +0100 Subject: [PATCH 29/48] [FIX] Clean data --- account_statement_base_import/statement.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 56fad9c0..e85b7c8e 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -87,8 +87,7 @@ class AccountStatementProfil(Model): #Deprecated remove on V8 def prepare_statetement_lines_vals(self, *args, **kwargs): - return super(self, AccountStatementProfil).\ - prepare_statetement_lines_vals(*args, **kwargs) + return self.prepare_statement_lines_vals(*args, **kwargs) def prepare_statement_lines_vals( self, cr, uid, parser_vals, account_payable, account_receivable, From a08c8340a844abbb365f58cb14e3a33d48d89300 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Mon, 3 Feb 2014 10:25:07 +0100 Subject: [PATCH 30/48] [FIX]Deprecated stuff --- account_statement_no_invoice_import/__openerp__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/account_statement_no_invoice_import/__openerp__.py b/account_statement_no_invoice_import/__openerp__.py index d2c8be37..645d897e 100644 --- a/account_statement_no_invoice_import/__openerp__.py +++ b/account_statement_no_invoice_import/__openerp__.py @@ -31,11 +31,10 @@ 'depends': [ 'account', ], - 'init_xml': [], - 'update_xml': [ + 'data': [ 'statement_view.xml', ], - 'demo_xml': [], + 'demo': [], 'installable': True, 'active': False, } From 4069e4c9251eb038978ded493c07e81ee0261c5b Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Mon, 3 Feb 2014 10:27:42 +0100 Subject: [PATCH 31/48] [FIX] Change description --- account_statement_no_invoice_import/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_no_invoice_import/__openerp__.py b/account_statement_no_invoice_import/__openerp__.py index 645d897e..29d30489 100644 --- a/account_statement_no_invoice_import/__openerp__.py +++ b/account_statement_no_invoice_import/__openerp__.py @@ -25,7 +25,7 @@ 'version': '0.1', 'category': 'Generic Modules/Others', 'license': 'AGPL-3', - 'description': """Module that remove the import button on bank statement""", + 'description': """Module that remove the 'Import invoices' button on bank statement""", 'author': 'Akretion', 'website': 'http://www.akretion.com/', 'depends': [ From 96012530c03643f3ff26fbd441cf6e6cbbcda2f5 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Fri, 7 Feb 2014 15:56:14 +0100 Subject: [PATCH 32/48] [FIX] Only remove the invoice import button instead of the whole div --- account_statement_no_invoice_import/__openerp__.py | 2 +- account_statement_no_invoice_import/statement_view.xml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/account_statement_no_invoice_import/__openerp__.py b/account_statement_no_invoice_import/__openerp__.py index 29d30489..abc1a218 100644 --- a/account_statement_no_invoice_import/__openerp__.py +++ b/account_statement_no_invoice_import/__openerp__.py @@ -29,7 +29,7 @@ 'author': 'Akretion', 'website': 'http://www.akretion.com/', 'depends': [ - 'account', + 'account_voucher', ], 'data': [ 'statement_view.xml', diff --git a/account_statement_no_invoice_import/statement_view.xml b/account_statement_no_invoice_import/statement_view.xml index 663de0d2..67920f41 100644 --- a/account_statement_no_invoice_import/statement_view.xml +++ b/account_statement_no_invoice_import/statement_view.xml @@ -8,12 +8,12 @@ account_bank_statement_simple_view.account_bank_statement.view_form account.bank.statement - + form -
-
+
From 46a09cda0ba5e11a1c862f71b620f212b4fb6a62 Mon Sep 17 00:00:00 2001 From: Launchpad Translations on behalf of banking-addons-team Date: Mon, 10 Feb 2014 05:56:29 +0000 Subject: [PATCH 33/48] Launchpad automatic translations update. --- account_statement_regex_account_completion/i18n/fr.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/account_statement_regex_account_completion/i18n/fr.po b/account_statement_regex_account_completion/i18n/fr.po index 303b085b..4d414f52 100644 --- a/account_statement_regex_account_completion/i18n/fr.po +++ b/account_statement_regex_account_completion/i18n/fr.po @@ -13,8 +13,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2014-01-24 06:27+0000\n" -"X-Generator: Launchpad (build 16914)\n" +"X-Launchpad-Export-Date: 2014-02-10 05:56+0000\n" +"X-Generator: Launchpad (build 16916)\n" #. module: account_statement_regex_account_completion #: field:account.statement.completion.rule,regex:0 From bb06a4b2aa53b92252a95f8cad9f9476b913fd33 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Sun, 16 Feb 2014 16:21:52 +0100 Subject: [PATCH 34/48] [FIX] search for name in the statement line label and no vice versa --- account_statement_base_completion/statement.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 0ab8e854..b4c717e8 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -319,7 +319,9 @@ class AccountStatementCompletionRule(orm.Model): if not context['partner_memoizer']: return res st_obj = self.pool.get('account.bank.statement.line') - sql = "SELECT id FROM res_partner WHERE name ~* %s and id in %s" + sql = """SELECT id FROM ( + SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner) AS res_patner_matcher + WHERE name_match IS NOT NULL AND id IN %s """ pattern = ".*%s.*" % re.escape(st_line['name']) cr.execute(sql, (pattern, context['partner_memoizer'])) result = cr.fetchall() @@ -332,7 +334,7 @@ class AccountStatementCompletionRule(orm.Model): res['partner_id'] = result[0][0] st_vals = st_obj.get_values_for_line(cr, uid, - profile_id=st_line['porfile_id'], + profile_id=st_line['profile_id'], master_account_id=st_line['master_account_id'], partner_id=res['partner_id'], line_type=False, From 4e538950d71f31dc9a32d465a3424e5a0d2a3cba Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Sun, 16 Feb 2014 16:28:57 +0100 Subject: [PATCH 35/48] typo --- account_statement_base_completion/statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index b4c717e8..6c44517a 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -320,7 +320,7 @@ class AccountStatementCompletionRule(orm.Model): return res st_obj = self.pool.get('account.bank.statement.line') sql = """SELECT id FROM ( - SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner) AS res_patner_matcher + SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner) AS res_patner_matcher WHERE name_match IS NOT NULL AND id IN %s """ pattern = ".*%s.*" % re.escape(st_line['name']) cr.execute(sql, (pattern, context['partner_memoizer'])) From a440f845b93ff9a7caed9b629f6d50b89edb6dcf Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Sun, 16 Feb 2014 16:45:03 +0100 Subject: [PATCH 36/48] [FIX] lp:1280822 define a default value for import_type to avoid breaking tests of completions addons --- account_statement_base_import/statement.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 8da3c7b3..93b4997a 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -54,6 +54,10 @@ class AccountStatementProfil(Model): } + _defaults = { + 'import_type': 'generic_csvxls_so' + } + def _write_extra_statement_lines( self, cr, uid, parser, result_row_list, profile, statement_id, context): """Insert extra lines after the main statement lines. From b290110758141639990b800dd20b69a24d05f458 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Sun, 16 Feb 2014 19:41:04 +0100 Subject: [PATCH 37/48] a little query optimization --- account_statement_base_completion/statement.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 6c44517a..965d977e 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -320,8 +320,9 @@ class AccountStatementCompletionRule(orm.Model): return res st_obj = self.pool.get('account.bank.statement.line') sql = """SELECT id FROM ( - SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner) AS res_patner_matcher - WHERE name_match IS NOT NULL AND id IN %s """ + SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner + WHERE id IN %s) AS res_patner_matcher + WHERE name_match IS NOT NULL""" pattern = ".*%s.*" % re.escape(st_line['name']) cr.execute(sql, (pattern, context['partner_memoizer'])) result = cr.fetchall() From 4f19caeb2009f9df6bc5a9f01fd590729bcb7eea Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Mon, 17 Feb 2014 18:24:03 +0100 Subject: [PATCH 38/48] [FIX] escape res_partner.name column as second arg of regexp_matches and keep the first one as unescaped. Add a lot of tests for completion based on the res_partner name --- account_statement_base_completion/__init__.py | 4 +- .../statement.py | 6 +- .../tests/__init__.py | 27 ++++++ .../tests/test_base_completion.py | 95 +++++++++++++++++++ 4 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 account_statement_base_completion/tests/__init__.py create mode 100644 account_statement_base_completion/tests/test_base_completion.py diff --git a/account_statement_base_completion/__init__.py b/account_statement_base_completion/__init__.py index 6c9ef1bc..a219be6a 100644 --- a/account_statement_base_completion/__init__.py +++ b/account_statement_base_completion/__init__.py @@ -19,5 +19,5 @@ # ############################################################################## -import statement -import partner +from . import partner +from . import statement diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 965d977e..910234d9 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -319,12 +319,12 @@ class AccountStatementCompletionRule(orm.Model): if not context['partner_memoizer']: return res st_obj = self.pool.get('account.bank.statement.line') + # regexp_replace(name,'([^a-zA-Z0-9 -])', '\\\1', 'g'), 'i') escape the column name to avoid false positive. (ex 'jho..doe' -> 'joh\.\.doe' sql = """SELECT id FROM ( - SELECT id, regexp_matches(%s, name) AS name_match FROM res_partner + SELECT id, regexp_matches(%s, regexp_replace(name,'([^[:alpha:]0-9 -])', %s, 'g'), 'i') AS name_match FROM res_partner WHERE id IN %s) AS res_patner_matcher WHERE name_match IS NOT NULL""" - pattern = ".*%s.*" % re.escape(st_line['name']) - cr.execute(sql, (pattern, context['partner_memoizer'])) + cr.execute(sql, (st_line['name'], r"\\\1", context['partner_memoizer'])) result = cr.fetchall() if not result: return res diff --git a/account_statement_base_completion/tests/__init__.py b/account_statement_base_completion/tests/__init__.py new file mode 100644 index 00000000..6f9e09ea --- /dev/null +++ b/account_statement_base_completion/tests/__init__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# +# +# Authors: Laurent Mignon +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# + +from . import test_base_completion + +checks = [ + test_base_completion +] diff --git a/account_statement_base_completion/tests/test_base_completion.py b/account_statement_base_completion/tests/test_base_completion.py new file mode 100644 index 00000000..d9416eff --- /dev/null +++ b/account_statement_base_completion/tests/test_base_completion.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +# +# +# Authors: Laurent Mignon +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# +from openerp.tests import common +import time +from collections import namedtuple + +name_completion_case = namedtuple("name_completion_case", ["partner_name", "line_label", "should_match"]) +NAMES_COMPLETION_CASES = [ + name_completion_case("Acsone", "Line for Acsone SA", True), + name_completion_case("Acsone", "Line for Acsone", True), + name_completion_case("Acsone", "Acsone for line", True), + name_completion_case("acsone", "Acsone for line", True), + name_completion_case("Acsone SA", "Line for Acsone SA test", True), + name_completion_case("Ac..ne", "Acsone for line", False), + name_completion_case("é@|r{}", "Acsone é@|r{} for line", True), + name_completion_case("Acsone", "A..one for line", False), + name_completion_case("A.one SA", "A.one SA for line", True), + name_completion_case("Acsone SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", False), + name_completion_case("Acsone ([^a-zA-Z0-9 -]) SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", True), + ] + + +class base_completion(common.TransactionCase): + + def setUp(self): + super(base_completion, self).setUp() + self.company_a = self.browse_ref('base.main_company') + self.profile_obj = self.registry("account.statement.profile") + self.partner_obj = self.registry("res.partner") + self.account_bank_statement_obj = self.registry("account.bank.statement") + self.account_bank_statement_line_obj = self.registry("account.bank.statement.line") + self.journal_id = self.ref("account.bank_journal") + self.partner_id = self.ref('base.main_partner') + self.account_id = self.ref("account.a_recv") + self.partner_id = self.ref("base.res_partner_12") + + def test_name_completion(self): + """Test complete partner_id from statement line label + Test the automatic completion of the partner_id based if the name of the partner appears in + the statement line label + """ + self.completion_rule_id = self.ref('account_statement_base_completion.bank_statement_completion_rule_3') + # Create the profile + self.profile_id = self.profile_obj.create(self.cr, self.uid, { + "name": "TEST", + "commission_account_id": self.account_id, + "journal_id": self.journal_id, + "rule_ids": [(6, 0, [self.completion_rule_id])]}) + # Create a bank statement + self.statement_id = self.account_bank_statement_obj.create(self.cr, self.uid, { + "balance_end_real": 0.0, + "balance_start": 0.0, + "date": time.strftime('%Y-%m-%d'), + "journal_id": self.journal_id, + "profile_id": self.profile_id + }) + + for case in NAMES_COMPLETION_CASES: + self.partner_obj.write(self.cr, self.uid, self.partner_id, {'name': case.partner_name}) + statement_line_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, { + 'amount': 1000.0, + 'name': case.line_label, + 'ref': 'My ref', + 'statement_id': self.statement_id, + }) + statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id) + self.assertFalse(statement_line.partner_id, "Partner_id must be blank before completion") + statement_obj = self.account_bank_statement_obj.browse(self.cr, self.uid, self.statement_id) + statement_obj.button_auto_completion() + statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id) + if case.should_match: + self.assertEquals(self.partner_id, statement_line.partner_id['id'], + "Missing expected partner id after completion (partner_name: %s, line_name: %s)" % (case.partner_name, case.line_label)) + else: + self.assertNotEquals(self.partner_id, statement_line.partner_id['id'], + "Partner id should be empty after completion(partner_name: %s, line_name: %s)" % (case.partner_name, case.line_label)) From e80f498d67cf96ac49eda16849b6b2b6c108b7c7 Mon Sep 17 00:00:00 2001 From: Launchpad Translations on behalf of banking-addons-team Date: Thu, 20 Feb 2014 05:47:21 +0000 Subject: [PATCH 39/48] Launchpad automatic translations update. --- account_statement_regex_account_completion/i18n/fr.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_regex_account_completion/i18n/fr.po b/account_statement_regex_account_completion/i18n/fr.po index 4d414f52..ab5e74f6 100644 --- a/account_statement_regex_account_completion/i18n/fr.po +++ b/account_statement_regex_account_completion/i18n/fr.po @@ -13,7 +13,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2014-02-10 05:56+0000\n" +"X-Launchpad-Export-Date: 2014-02-20 05:47+0000\n" "X-Generator: Launchpad (build 16916)\n" #. module: account_statement_regex_account_completion From 106294d36367d6aab319c974dba0e466bda250f4 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:18:26 +0100 Subject: [PATCH 40/48] UPD account_advanced_reconcile_transaction_ref version --- account_advanced_reconcile_transaction_ref/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_advanced_reconcile_transaction_ref/__openerp__.py b/account_advanced_reconcile_transaction_ref/__openerp__.py index d806ba9e..bd1586cf 100644 --- a/account_advanced_reconcile_transaction_ref/__openerp__.py +++ b/account_advanced_reconcile_transaction_ref/__openerp__.py @@ -25,7 +25,7 @@ Advanced reconciliation method for the module account_easy_reconcile Reconcile rules with transaction_ref """, - 'version': '1.0', + 'version': '1.0.1', 'author': 'Camptocamp', 'category': 'Finance', 'website': 'http://www.camptocamp.com', From 0cedf1b84dc79d0f38bdce497f9664f85365ac8b Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:19:17 +0100 Subject: [PATCH 41/48] UPD account_statement_base_completion version --- account_statement_base_completion/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_completion/__openerp__.py b/account_statement_base_completion/__openerp__.py index d868a314..1ff18db7 100644 --- a/account_statement_base_completion/__openerp__.py +++ b/account_statement_base_completion/__openerp__.py @@ -20,7 +20,7 @@ ############################################################################## {'name': "Bank statement base completion", - 'version': '1.0', + 'version': '1.0.1', 'author': 'Camptocamp', 'maintainer': 'Camptocamp', 'category': 'Finance', From fc6032597b33960b15f8c292b935d37e035e373a Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:19:53 +0100 Subject: [PATCH 42/48] UPD account_statement_base_import version --- account_statement_base_import/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_import/__openerp__.py b/account_statement_base_import/__openerp__.py index 086af048..59a5a338 100644 --- a/account_statement_base_import/__openerp__.py +++ b/account_statement_base_import/__openerp__.py @@ -20,7 +20,7 @@ ############################################################################## {'name': "Bank statement base import", - 'version': '1.0', + 'version': '1.0.1', 'author': 'Camptocamp', 'maintainer': 'Camptocamp', 'category': 'Finance', From 3875378fc9229d1107f1683854327e998269b618 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:25:38 +0100 Subject: [PATCH 43/48] PEP8 on changes --- account_statement_ext/statement.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 48667715..4fa5b0df 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -202,7 +202,8 @@ class AccountBankStatement(Model): profile_obj = self.pool.get('account.statement.profile') profile = profile_obj.browse(cr, uid, vals['profile_id'], context=context) vals['journal_id'] = profile.journal_id.id - return super(AccountBankStatement, self).create(cr, uid, vals, context=context) + return super(AccountBankStatement, self + ).create(cr, uid, vals, context=context) def _get_period(self, cr, uid, date, context=None): """ @@ -243,8 +244,9 @@ class AccountBankStatement(Model): """ if context is None: context = {} - res = super(AccountBankStatement, self)._prepare_move( - cr, uid, st_line, st_line_number, context=context) + res = super(AccountBankStatement, self + )._prepare_move(cr, uid, st_line, st_line_number, + context=context) ctx = context.copy() ctx['company_id'] = st_line.company_id.id period_id = self._get_period(cr, uid, st_line.date, context=ctx) @@ -297,10 +299,9 @@ class AccountBankStatement(Model): create the move from. :return: int/long of the res.partner to use as counterpart """ - bank_partner_id = super(AccountBankStatement, self)._get_counter_part_partner(cr, - uid, - st_line, - context=context) + bank_partner_id = super(AccountBankStatement, self + )._get_counter_part_partner(cr, uid, st_line, + context=context) # get the right partner according to the chosen profile if st_line.statement_id.profile_id.force_partner_on_bank: bank_partner_id = st_line.statement_id.profile_id.partner_id.id @@ -530,8 +531,9 @@ class AccountBankStatement(Model): """ st = self.browse(cr, uid, st_id, context=context) if st.balance_check: - return super(AccountBankStatement, self).balance_check( - cr, uid, st_id, journal_type, context=context) + return super(AccountBankStatement, self + ).balance_check(cr, uid, st_id, journal_type, + context=context) else: return True @@ -684,11 +686,9 @@ class AccountBankStatementLine(Model): Keep the same features as in standard and call super. If an account is returned, call the method to compute line values. """ - res = super(AccountBankStatementLine, self).onchange_type(cr, uid, - line_id, - partner_id, - line_type, - context=context) + res = super(AccountBankStatementLine, self + ).onchange_type(cr, uid, line_id, partner_id, + line_type, context=context) if 'account_id' in res['value']: result = self.get_values_for_line(cr, uid, profile_id=profile_id, From 25e916cdcbdd0d007f6c742dda30473357f39ae7 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 21 Feb 2014 19:26:17 +0100 Subject: [PATCH 44/48] UPD account_statement_ext version --- account_statement_ext/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_ext/__openerp__.py b/account_statement_ext/__openerp__.py index c6000063..32c518b9 100644 --- a/account_statement_ext/__openerp__.py +++ b/account_statement_ext/__openerp__.py @@ -20,7 +20,7 @@ ############################################################################## {'name': "Bank statement extension and profiles", - 'version': '1.3.0', + 'version': '1.3.1', 'author': 'Camptocamp', 'maintainer': 'Camptocamp', 'category': 'Finance', From 51c76544454b4dcf0609eed95b6e2cdf36cc5960 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Mon, 24 Feb 2014 23:45:29 +0100 Subject: [PATCH 45/48] [FIX] account_statement_base_import: self reference calling method. --- account_statement_base_import/statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 3dbddd60..3ad5dbe4 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -36,7 +36,7 @@ class AccountStatementProfil(Model): return [('generic_csvxls_so', 'Generic .csv/.xls based on SO Name')] def _get_import_type_selection(self, cr, uid, context=None): - return get_import_type selection(cr, uid, context=context) + return self.get_import_type_selection(cr, uid, context=context) _columns = { 'launch_import_completion': fields.boolean( From ba824ca100af6ea5f8828bca610a8e09794e2e98 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 26 Feb 2014 11:23:37 +0100 Subject: [PATCH 46/48] the sample is insufficient to guess the delimiters on some files --- account_statement_base_import/parser/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index 39d4d313..cda1b539 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -25,7 +25,7 @@ import csv def UnicodeDictReader(utf8_data, **kwargs): sniffer = csv.Sniffer() pos = utf8_data.tell() - sample_data = utf8_data.read(1024) + sample_data = utf8_data.read(2048) utf8_data.seek(pos) dialect = sniffer.sniff(sample_data, delimiters=',;\t') csv_reader = csv.DictReader(utf8_data, dialect=dialect, **kwargs) From 512fd89093b5fb1b0c8f0ca22fbd662707bd4230 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 26 Feb 2014 12:02:40 +0100 Subject: [PATCH 47/48] restore default values to prevent regression introduced in pedro.baeza@serviciosbaeza.com-20140202105840-ndjvkvas1y82pxlw --- account_statement_base_import/parser/parser.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index 39d4d313..83fe9bd0 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -20,6 +20,7 @@ ############################################################################## import base64 import csv +from datetime import datetime def UnicodeDictReader(utf8_data, **kwargs): @@ -121,10 +122,10 @@ class BankStatementImportParser(object): :return: dict of vals that represent additional infos for the statement """ return { - 'name': self.statement_name, + 'name': self.statement_name or '/', 'balance_start': self.balance_start, 'balance_end_real': self.balance_end, - 'date': self.statement_date + 'date': self.statement_date or datetime.now() } def get_st_line_vals(self, line, *args, **kwargs): From c17afe17b1795332c979e5ed7dd8953713673afa Mon Sep 17 00:00:00 2001 From: Launchpad Translations on behalf of banking-addons-team Date: Sat, 1 Mar 2014 05:55:31 +0000 Subject: [PATCH 48/48] Launchpad automatic translations update. --- account_statement_regex_account_completion/i18n/fr.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/account_statement_regex_account_completion/i18n/fr.po b/account_statement_regex_account_completion/i18n/fr.po index ab5e74f6..b2bdf2a0 100644 --- a/account_statement_regex_account_completion/i18n/fr.po +++ b/account_statement_regex_account_completion/i18n/fr.po @@ -13,8 +13,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2014-02-20 05:47+0000\n" -"X-Generator: Launchpad (build 16916)\n" +"X-Launchpad-Export-Date: 2014-03-01 05:55+0000\n" +"X-Generator: Launchpad (build 16948)\n" #. module: account_statement_regex_account_completion #: field:account.statement.completion.rule,regex:0