From ed263e083dcb49bdd3f2d6cc707008cb5fe8ce1b Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Mon, 11 Nov 2013 13:33:43 +0100 Subject: [PATCH 01/34] [FIX] remove account.reconcile before deleting a account.move --- account_statement_ext/account.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/account_statement_ext/account.py b/account_statement_ext/account.py index 8dab9449..97f1103f 100644 --- a/account_statement_ext/account.py +++ b/account_statement_ext/account.py @@ -31,8 +31,11 @@ class account_move(Model): Delete the reconciliation when we delete the moves. This allow an easier way of cancelling the bank statement. """ + reconcile_to_delete = [] + reconcile_obj = self.pool.get('account.move.reconcile') for move in self.browse(cr, uid, ids, context=context): for move_line in move.line_id: if move_line.reconcile_id: - move_line.reconcile_id.unlink(context=context) + reconcile_to_delete.append(move_line.reconcile_id.id) + reconcile_obj.unlink(cr,uid,reconcile_to_delete,context=context) return super(account_move, self).unlink(cr, uid, ids, context=context) From 5c0e625e11f3b1c84beb25a1c1bbae037223fbf6 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 3 Dec 2013 16:04:25 +0100 Subject: [PATCH 02/34] [imp] account_statement_base_completion: put what depends on sale on a separate module --- .../__openerp__.py | 1 - account_statement_base_completion/data.xml | 6 -- .../statement.py | 44 --------- account_statement_so_completion/__init__.py | 25 +++++ .../__openerp__.py | 53 ++++++++++ account_statement_so_completion/data.xml | 12 +++ .../partner_view.xml | 22 +++++ account_statement_so_completion/statement.py | 98 +++++++++++++++++++ 8 files changed, 210 insertions(+), 51 deletions(-) create mode 100644 account_statement_so_completion/__init__.py create mode 100644 account_statement_so_completion/__openerp__.py create mode 100644 account_statement_so_completion/data.xml create mode 100644 account_statement_so_completion/partner_view.xml create mode 100644 account_statement_so_completion/statement.py diff --git a/account_statement_base_completion/__openerp__.py b/account_statement_base_completion/__openerp__.py index d868a314..2d795534 100644 --- a/account_statement_base_completion/__openerp__.py +++ b/account_statement_base_completion/__openerp__.py @@ -35,7 +35,6 @@ 1) Match from statement line label (based on partner field 'Bank Statement Label') 2) Match from statement line label (based on partner name) - 3) Match from statement line reference (based on SO number) 3) Match from statement line reference (based on Invoice number) You can easily override this module and add your own rules in your own one. The basic rules only diff --git a/account_statement_base_completion/data.xml b/account_statement_base_completion/data.xml index 59a75228..595a4af3 100644 --- a/account_statement_base_completion/data.xml +++ b/account_statement_base_completion/data.xml @@ -14,12 +14,6 @@ get_from_label_and_partner_name - - Match from line reference (based on SO number) - 50 - get_from_ref_and_so - - Match from line reference (based on Invoice number) 40 diff --git a/account_statement_base_completion/statement.py b/account_statement_base_completion/statement.py index 96ab741b..aacb7068 100644 --- a/account_statement_base_completion/statement.py +++ b/account_statement_base_completion/statement.py @@ -132,7 +132,6 @@ class AccountStatementCompletionRule(orm.Model): return [ ('get_from_ref_and_invoice', 'From line reference (based on customer invoice number)'), ('get_from_ref_and_supplier_invoice', 'From line reference (based on supplier invoice number)'), - ('get_from_ref_and_so', 'From line reference (based on SO number)'), ('get_from_label_and_partner_field', 'From line label (based on partner field)'), ('get_from_label_and_partner_name', 'From line label (based on partner name)')] @@ -232,49 +231,6 @@ class AccountStatementCompletionRule(orm.Model): """ return self._from_invoice(cr, uid, line, 'customer', context=context) - # Should be private but data are initialised with no update XML - def get_from_ref_and_so(self, cr, uid, st_line, context=None): - """ - Match the partner based on the SO number and the reference of the statement - line. Then, call the generic get_values_for_line method to complete other values. - If more than one partner matched, raise the ErrorTooManyPartner error. - - :param int/long 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, - - ...} - """ - st_obj = self.pool.get('account.bank.statement.line') - res = {} - if st_line: - so_obj = self.pool.get('sale.order') - so_id = so_obj.search(cr, - uid, - [('name', '=', st_line['ref'])], - context=context) - if so_id: - if so_id and len(so_id) == 1: - so = so_obj.browse(cr, uid, so_id[0], context=context) - res['partner_id'] = so.partner_id.id - elif so_id and len(so_id) > 1: - raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more ' - 'than one partner while looking on SO by ref.') % - (st_line['name'], st_line['ref'])) - st_vals = st_obj.get_values_for_line(cr, - uid, - profile_id=st_line['profile_id'], - master_account_id=st_line['master_account_id'], - partner_id=res.get('partner_id', False), - line_type='customer', - amount=st_line['amount'] if st_line['amount'] else 0.0, - context=context) - res.update(st_vals) - return res - # Should be private but data are initialised with no update XML def get_from_label_and_partner_field(self, cr, uid, st_line, context=None): """ diff --git a/account_statement_so_completion/__init__.py b/account_statement_so_completion/__init__.py new file mode 100644 index 00000000..5c28ebc2 --- /dev/null +++ b/account_statement_so_completion/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################### +# # +# Author: Joel Grand-Guillaume +# Copyright 2011-2012 Camptocamp SA +# # +# Author: Leonardo Pistone # +# Copyright 2013 Camptocamp SA # +# # +# 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_so_completion/__openerp__.py b/account_statement_so_completion/__openerp__.py new file mode 100644 index 00000000..9028d535 --- /dev/null +++ b/account_statement_so_completion/__openerp__.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +############################################################################### +# # +# Author: Joel Grand-Guillaume +# Copyright 2011-2012 Camptocamp SA +# # +# Author: Leonardo Pistone # +# Copyright 2013 Camptocamp SA # +# # +# 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': "Bank statement Sale Order completion", + 'version': '0.1', + 'author': 'Camptocamp', + 'maintainer': 'Camptocamp', + 'category': 'Finance', + 'complexity': 'easy', + 'depends': ['account_statement_base_completion', 'sale'], + 'description': """ + This module improve the module account_statement_base_completion to add + support for completion rules based on Sale Orders. This was initially part of + the module account_statement_base_completion, but is now separate to keep + dependencies separate. + + This module provides the following rule: + + 1) Match from statement line reference (based on SO number) +""", + 'website': 'http://www.camptocamp.com', + 'init_xml': [], + 'update_xml': [ + 'data.xml', + ], + 'demo_xml': [], + 'test': [], + 'installable': True, + 'images': [], + 'auto_install': False, + 'license': 'AGPL-3', + } diff --git a/account_statement_so_completion/data.xml b/account_statement_so_completion/data.xml new file mode 100644 index 00000000..89fedef2 --- /dev/null +++ b/account_statement_so_completion/data.xml @@ -0,0 +1,12 @@ + + + + + + Match from line reference (based on SO number) + 50 + get_from_ref_and_so + + + + diff --git a/account_statement_so_completion/partner_view.xml b/account_statement_so_completion/partner_view.xml new file mode 100644 index 00000000..c7ec3f1a --- /dev/null +++ b/account_statement_so_completion/partner_view.xml @@ -0,0 +1,22 @@ + + + + + + + + account_bank_statement_import.view.partner.form + res.partner + form + 20 + + + + + + + + + + + diff --git a/account_statement_so_completion/statement.py b/account_statement_so_completion/statement.py new file mode 100644 index 00000000..03d0a2b3 --- /dev/null +++ b/account_statement_so_completion/statement.py @@ -0,0 +1,98 @@ +# -*- coding: utf-8 -*- +############################################################################### +# # +# Author: Joel Grand-Guillaume +# Copyright 2011-2012 Camptocamp SA +# # +# Author: Leonardo Pistone # +# Copyright 2013 Camptocamp SA # +# # +# 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 import fields, orm +from tools.translate import _ + +from openerp.addons.account_statement_base_completion.statement import ErrorTooManyPartner + + +class account_statement_profile(orm.Model): + + _inherit = "account.statement.profile" + + # Should be private but data are initialised with no update XML + def get_from_ref_and_so(self, cr, uid, st_line, context=None): + """ + Match the partner based on the SO number and the reference of the + statement line. Then, call the generic get_values_for_line method to + complete other values. If more than one partner matched, raise the + ErrorTooManyPartner error. + + :param int/long 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, + + ...} + """ + st_obj = self.pool.get('account.bank.statement.line') + res = {} + if st_line: + so_obj = self.pool.get('sale.order') + so_id = so_obj.search(cr, + uid, + [('name', '=', st_line['ref'])], + context=context) + if so_id: + if so_id and len(so_id) == 1: + so = so_obj.browse(cr, uid, so_id[0], context=context) + res['partner_id'] = so.partner_id.id + elif so_id and len(so_id) > 1: + raise ErrorTooManyPartner( + _('Line named "%s" (Ref:%s) was matched by more ' + 'than one partner while looking on SO by ref.') % + (st_line['name'], st_line['ref'])) + st_vals = st_obj.get_values_for_line( + cr, + uid, + profile_id=st_line['profile_id'], + master_account_id=st_line['master_account_id'], + partner_id=res.get('partner_id', False), + line_type='customer', + amount=st_line['amount'] if st_line['amount'] else 0.0, + context=context) + res.update(st_vals) + return res + + +class account_statement_completion_rule(orm.Model): + + _name = "account.statement.completion.rule" + _inherit = "account.statement.completion.rule" + + def _get_functions(self, cr, uid, context=None): + res = super(account_statement_completion_rule, self)._get_functions( + cr, uid, context=context) + return res.append( + ('get_from_ref_and_so', 'From line reference (based on SO number)') + ) + + _columns = { + 'function_to_call': fields.selection(_get_functions, 'Method'), + } From 95242cd44b93fbae301230813e57514694c231cb Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 3 Dec 2013 16:08:34 +0100 Subject: [PATCH 03/34] [del] unused file --- .../partner_view.xml | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 account_statement_so_completion/partner_view.xml diff --git a/account_statement_so_completion/partner_view.xml b/account_statement_so_completion/partner_view.xml deleted file mode 100644 index c7ec3f1a..00000000 --- a/account_statement_so_completion/partner_view.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - account_bank_statement_import.view.partner.form - res.partner - form - 20 - - - - - - - - - - - From f80bba275eec1133d3bf300bcb2c06b7259b40df Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 3 Dec 2013 16:10:22 +0100 Subject: [PATCH 04/34] [ref] minor refactor --- account_statement_so_completion/__init__.py | 2 +- account_statement_so_completion/statement.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/account_statement_so_completion/__init__.py b/account_statement_so_completion/__init__.py index 5c28ebc2..34a7ad21 100644 --- a/account_statement_so_completion/__init__.py +++ b/account_statement_so_completion/__init__.py @@ -22,4 +22,4 @@ # # ############################################################################### -import statement +from . import statement diff --git a/account_statement_so_completion/statement.py b/account_statement_so_completion/statement.py index 03d0a2b3..439a66ad 100644 --- a/account_statement_so_completion/statement.py +++ b/account_statement_so_completion/statement.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################### # # -# Author: Joel Grand-Guillaume -# Copyright 2011-2012 Camptocamp SA +# Author: Joel Grand-Guillaume # +# Copyright 2011-2012 Camptocamp SA # # # # Author: Leonardo Pistone # # Copyright 2013 Camptocamp SA # From 53c5ab9c84e7ea6f206b3edb2d420594f7536161 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 3 Dec 2013 16:19:45 +0100 Subject: [PATCH 05/34] auto_install account_statement_so_completion --- account_statement_so_completion/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_statement_so_completion/__openerp__.py b/account_statement_so_completion/__openerp__.py index 9028d535..929e46c8 100644 --- a/account_statement_so_completion/__openerp__.py +++ b/account_statement_so_completion/__openerp__.py @@ -48,6 +48,6 @@ 'test': [], 'installable': True, 'images': [], - 'auto_install': False, + 'auto_install': True, 'license': 'AGPL-3', } From 3c3b6539504a39bed5a0d6d2137f6a056c6988de Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 14:30:34 +0100 Subject: [PATCH 06/34] [IMP] account_statement_base_import : add the posibility to set the starting and ending balance --- account_statement_base_import/parser/parser.py | 18 ++++++++++++++++++ account_statement_base_import/statement.py | 11 +++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index 377548b2..9d8ca4e1 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -49,6 +49,8 @@ class BankStatementImportParser(object): self.result_row_list = None # The file buffer on which to work on self.filebuffer = None + self.balance_start = None + self.balance_end = None @classmethod def parser_for(cls, parser_name): @@ -150,6 +152,22 @@ class BankStatementImportParser(object): self._post(*args, **kwargs) return self.result_row_list + def get_start_balance(self, *args, **kwargs): + """ + This is called by the importation method to set the balance start + amount in the bank statement. + return: float of the balance start (self.balance_start) + """ + return self.balance_start + + def get_end_balance(self, *args, **kwargs): + """ + This is called by the importation method to set the balance end + amount in the bank statement. + return: float of the balance end (self.balance_end) + """ + return self.balance_end + def itersubclasses(cls, _seen=None): """ diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 97e8e8ab..438f6f1b 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -158,10 +158,13 @@ class AccountStatementProfil(Model): raise osv.except_osv(_("Missing column!"), _("Column %s you try to import is not " "present in the bank statement line!") % col) - - statement_id = statement_obj.create(cr, uid, - {'profile_id': prof.id}, - context=context) + st_vals = { + 'profile_id': prof.id, + 'balance_start': parser.get_start_balance(), + 'balance_end_real': parser.get_end_balance(), + } + + statement_id = statement_obj.create(cr, uid, st_vals, context=context) if prof.receivable_account_id: account_receivable = account_payable = prof.receivable_account_id.id else: From 5e80529485412c30614839c6c2331298e92d9198 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 15:10:49 +0100 Subject: [PATCH 07/34] [IMP] add the posibility to customise the bank statement name in the parser --- account_statement_base_import/parser/parser.py | 9 +++++++++ account_statement_base_import/statement.py | 1 + account_statement_base_import/wizard/import_statement.py | 1 + 3 files changed, 11 insertions(+) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index 9d8ca4e1..b0d86de7 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -51,6 +51,7 @@ class BankStatementImportParser(object): self.filebuffer = None self.balance_start = None self.balance_end = None + self.statement_name = None @classmethod def parser_for(cls, parser_name): @@ -168,6 +169,14 @@ class BankStatementImportParser(object): """ return self.balance_end + def get_statement_name(self, *args, **kwargs): + """ + This is called by the importation method to set the statement + date in the bank statement. + return: float of the balance start (self.balance_start) + """ + return self.statement_name or '/' + def itersubclasses(cls, _seen=None): """ diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 438f6f1b..47f52f63 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -160,6 +160,7 @@ class AccountStatementProfil(Model): "present in the bank statement line!") % col) st_vals = { 'profile_id': prof.id, + 'name': parser.get_statement_name(), 'balance_start': parser.get_start_balance(), 'balance_end_real': parser.get_end_balance(), } diff --git a/account_statement_base_import/wizard/import_statement.py b/account_statement_base_import/wizard/import_statement.py index b6960ec9..260a900e 100644 --- a/account_statement_base_import/wizard/import_statement.py +++ b/account_statement_base_import/wizard/import_statement.py @@ -97,6 +97,7 @@ class CreditPartnerStatementImporter(orm.TransientModel): req_id = req_id[0] importer = self.browse(cr, uid, req_id, context) ftype = self._check_extension(importer.file_name) + context['file_name'] = importer.file_name sid = self.pool.get( 'account.statement.profile').statement_import( cr, From 9205414ee1bef9367b430e68ac3ba9fdf2e25b0a Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 15:14:56 +0100 Subject: [PATCH 08/34] [IMP] add the possibility to specify the bank statement date --- account_statement_base_import/parser/parser.py | 9 +++++++++ account_statement_commission/commission.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index b0d86de7..6472cea1 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): @@ -52,6 +53,7 @@ class BankStatementImportParser(object): self.balance_start = None self.balance_end = None self.statement_name = None + self.statement_date = None @classmethod def parser_for(cls, parser_name): @@ -177,6 +179,13 @@ class BankStatementImportParser(object): """ return self.statement_name or '/' + def get_statement_date(self, *args, **kwargs): + """ + This is called by the importation method to set the statement + date in the bank statement. + return: float of the balance start (self.balance_start) + """ + return self.statement_date or datetime.now() def itersubclasses(cls, _seen=None): """ diff --git a/account_statement_commission/commission.py b/account_statement_commission/commission.py index 138ad61f..f4d0fc74 100644 --- a/account_statement_commission/commission.py +++ b/account_statement_commission/commission.py @@ -22,7 +22,7 @@ class AccountStatementProfil(orm.Model): commission_analytic_id = profile.commission_analytic_id and profile.commission_analytic_id.id or False comm_values = { 'name': 'IN ' + _('Commission line'), - 'date': datetime.datetime.now().date(), + 'date': parser.get_statement_date(), 'amount': global_commission_amount, 'partner_id': partner_id, 'type': 'general', @@ -65,4 +65,4 @@ class CreditPartnerStatementImporter(orm.TransientModel): c.commission_account_id and c.commission_account_id.id or False res['value']['commission_a'] = \ c.commission_analytic_id and c.commission_analytic_id.id or False - return res \ No newline at end of file + return res From 1648c431f7678f5f75b768c422f7a43d9c926134 Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Wed, 4 Dec 2013 18:39:04 +0100 Subject: [PATCH 09/34] [REF] add a prepare method for custom for creating the bank statement --- account_statement_base_import/statement.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/account_statement_base_import/statement.py b/account_statement_base_import/statement.py index 47f52f63..960616d1 100644 --- a/account_statement_base_import/statement.py +++ b/account_statement_base_import/statement.py @@ -126,6 +126,15 @@ class AccountStatementProfil(Model): values['type'] = 'general' return values + + def _prepare_statement_vals(self, cr, uid, prof, parser, context=None): + return { + 'profile_id': prof.id, + 'name': parser.get_statement_name(), + 'balance_start': parser.get_start_balance(), + 'balance_end_real': parser.get_end_balance(), + } + 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 @@ -158,13 +167,8 @@ class AccountStatementProfil(Model): raise osv.except_osv(_("Missing column!"), _("Column %s you try to import is not " "present in the bank statement line!") % col) - st_vals = { - 'profile_id': prof.id, - 'name': parser.get_statement_name(), - 'balance_start': parser.get_start_balance(), - 'balance_end_real': parser.get_end_balance(), - } - + + st_vals = self._prepare_statement_vals(cr, uid, prof, parser, context=context) statement_id = statement_obj.create(cr, uid, st_vals, context=context) if prof.receivable_account_id: account_receivable = account_payable = prof.receivable_account_id.id From c921a717418b9b418a157fdb3b0dd2601d19d9ef Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 11 Dec 2013 20:11:44 +0100 Subject: [PATCH 10/34] [FIX] Change some methods description --- account_statement_base_import/parser/parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/account_statement_base_import/parser/parser.py b/account_statement_base_import/parser/parser.py index 6472cea1..cce55eea 100644 --- a/account_statement_base_import/parser/parser.py +++ b/account_statement_base_import/parser/parser.py @@ -174,8 +174,8 @@ class BankStatementImportParser(object): def get_statement_name(self, *args, **kwargs): """ This is called by the importation method to set the statement - date in the bank statement. - return: float of the balance start (self.balance_start) + name in the bank statement. + return: string of the statement name (self.statement_name) """ return self.statement_name or '/' @@ -183,7 +183,7 @@ class BankStatementImportParser(object): """ This is called by the importation method to set the statement date in the bank statement. - return: float of the balance start (self.balance_start) + return: datetime of the statement date (self.statement_date) """ return self.statement_date or datetime.now() From fc0b8ec312fed12ac4e4eb30a14fd12b61cc1ea0 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 13 Dec 2013 12:33:52 +0100 Subject: [PATCH 11/34] [fix] selection value --- account_statement_so_completion/statement.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/account_statement_so_completion/statement.py b/account_statement_so_completion/statement.py index 439a66ad..f41fd906 100644 --- a/account_statement_so_completion/statement.py +++ b/account_statement_so_completion/statement.py @@ -89,9 +89,10 @@ class account_statement_completion_rule(orm.Model): def _get_functions(self, cr, uid, context=None): res = super(account_statement_completion_rule, self)._get_functions( cr, uid, context=context) - return res.append( + res.append( ('get_from_ref_and_so', 'From line reference (based on SO number)') ) + return res _columns = { 'function_to_call': fields.selection(_get_functions, 'Method'), From 9080e3d6c8a491df0db5344f5cfe06e7af762d27 Mon Sep 17 00:00:00 2001 From: Vincent Renaville Date: Fri, 13 Dec 2013 15:06:53 +0100 Subject: [PATCH 12/34] [FIX] PEP8 --- account_statement_ext/account.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/account_statement_ext/account.py b/account_statement_ext/account.py index 97f1103f..ecd1853c 100644 --- a/account_statement_ext/account.py +++ b/account_statement_ext/account.py @@ -36,6 +36,6 @@ class account_move(Model): for move in self.browse(cr, uid, ids, context=context): for move_line in move.line_id: if move_line.reconcile_id: - reconcile_to_delete.append(move_line.reconcile_id.id) - reconcile_obj.unlink(cr,uid,reconcile_to_delete,context=context) + reconcile_to_delete.append(move_line.reconcile_id.id) + reconcile_obj.unlink(cr, uid, reconcile_to_delete, context=context) return super(account_move, self).unlink(cr, uid, ids, context=context) From 89e7700d21796d4be8bec6b522d2db7bfbde4fe3 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 13 Dec 2013 17:25:10 +0100 Subject: [PATCH 13/34] [add] tests for account_statement_base_completion: customer invoice --- .../__openerp__.py | 5 ++- .../test/TODO.txt | 3 ++ .../test/completion_test.yml | 31 ++++++++++++++++++ .../test/invoice.yml | 32 +++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 account_statement_base_completion/test/TODO.txt create mode 100644 account_statement_base_completion/test/completion_test.yml create mode 100644 account_statement_base_completion/test/invoice.yml diff --git a/account_statement_base_completion/__openerp__.py b/account_statement_base_completion/__openerp__.py index d868a314..3147822f 100644 --- a/account_statement_base_completion/__openerp__.py +++ b/account_statement_base_completion/__openerp__.py @@ -66,7 +66,10 @@ 'security/ir.model.access.csv', ], 'demo_xml': [], - 'test': [], + 'test': [ + 'test/invoice.yml', + 'test/completion_test.yml' + ], 'installable': True, 'images': [], 'auto_install': False, diff --git a/account_statement_base_completion/test/TODO.txt b/account_statement_base_completion/test/TODO.txt new file mode 100644 index 00000000..42bd3f37 --- /dev/null +++ b/account_statement_base_completion/test/TODO.txt @@ -0,0 +1,3 @@ +* statement default company, or company required? +* on_change +* statment doesn't have a company, why? \ No newline at end of file diff --git a/account_statement_base_completion/test/completion_test.yml b/account_statement_base_completion/test/completion_test.yml new file mode 100644 index 00000000..4936094f --- /dev/null +++ b/account_statement_base_completion/test/completion_test.yml @@ -0,0 +1,31 @@ +- + In order to test the banking framework, I first need to create a profile +- + !record {model: account.statement.profile, id: profile_test1}: + name: Bank EUR Profile + journal_id: account.bank_journal + commission_account_id: account.a_expense + company_id: base.main_company + balance_check: True + rule_ids: + - bank_statement_completion_rule_4 + - bank_statement_completion_rule_5 + - bank_statement_completion_rule_2 + - bank_statement_completion_rule_3 +- + Now I create a statement +- + !record {model: account.bank.statement, id: statement_test1}: + name: Statement 2 + profile_id: profile_test1 + company_id: base.main_company + line_ids: + - name: Test autocompletion based on Invoice Number + ref: CI0001 + date: '2013-12-13' + amount: 2100.0 +- + I run the auto complete +- + !python {model: account.bank.statement}: | + result = self.button_auto_completion(cr, uid, [ref("statement_test1")]) diff --git a/account_statement_base_completion/test/invoice.yml b/account_statement_base_completion/test/invoice.yml new file mode 100644 index 00000000..5b6845f5 --- /dev/null +++ b/account_statement_base_completion/test/invoice.yml @@ -0,0 +1,32 @@ +- + I create a customer Invoice to be found by the completion. +- + !record {model: account.invoice, id: invoice_for_completion_1}: + account_id: account.a_recv + company_id: base.main_company + currency_id: base.EUR + internal_number: CI0001 + invoice_line: + - account_id: account.a_sale + name: '[PCSC234] PC Assemble SC234' + price_unit: 450.0 + quantity: 1.0 + product_id: product.product_product_3 + uos_id: product.product_uom_unit + journal_id: account.bank_journal + partner_id: base.res_partner_12 + reference_type: none +- + I confirm the Invoice +- + !workflow {model: account.invoice, action: invoice_open, ref: invoice_for_completion_1} +- + I check that the invoice state is "Open" +- + !assert {model: account.invoice, id: invoice_for_completion_1}: + - state == 'open' +- + I check that it is given the number "CI0001" +- + !assert {model: account.invoice, id: invoice_for_completion_1, string: Check CI number}: + - number == 'CI0001' From ea399af06b5d5726f03ac4041135363390364754 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 13 Dec 2013 20:08:52 +0100 Subject: [PATCH 14/34] [add] statement completion: more tests --- .../__openerp__.py | 1 + .../test/completion_test.yml | 18 +++++++++++++++--- .../test/invoice.yml | 2 +- .../test/partner.yml | 5 +++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 account_statement_base_completion/test/partner.yml diff --git a/account_statement_base_completion/__openerp__.py b/account_statement_base_completion/__openerp__.py index 3147822f..b7e6bdc6 100644 --- a/account_statement_base_completion/__openerp__.py +++ b/account_statement_base_completion/__openerp__.py @@ -67,6 +67,7 @@ ], 'demo_xml': [], 'test': [ + 'test/partner.yml', 'test/invoice.yml', 'test/completion_test.yml' ], diff --git a/account_statement_base_completion/test/completion_test.yml b/account_statement_base_completion/test/completion_test.yml index 4936094f..976a2dac 100644 --- a/account_statement_base_completion/test/completion_test.yml +++ b/account_statement_base_completion/test/completion_test.yml @@ -20,10 +20,22 @@ profile_id: profile_test1 company_id: base.main_company line_ids: - - name: Test autocompletion based on Invoice Number + - name: Test autocompletion based on Customer Invoice Number ref: CI0001 - date: '2013-12-13' - amount: 2100.0 + date: '2013-12-20' + amount: 210.0 + - name: Test autocompletion based on Supplier Invoice Number + ref: T2S12345 + date: '2013-12-19' + amount: -65.0 + - name: Test autocompletion based on Partner Name Vauxoo + ref: / + date: '2013-12-17' + amount: 600.0 + - name: test autocompletion based on text (XXX66Z) matching with partner form information (note that Ref does not exist) + ref: ZU788 + date: '2013-12-24' + amount: -932.4 - I run the auto complete - diff --git a/account_statement_base_completion/test/invoice.yml b/account_statement_base_completion/test/invoice.yml index 5b6845f5..5619f0cd 100644 --- a/account_statement_base_completion/test/invoice.yml +++ b/account_statement_base_completion/test/invoice.yml @@ -9,7 +9,7 @@ invoice_line: - account_id: account.a_sale name: '[PCSC234] PC Assemble SC234' - price_unit: 450.0 + price_unit: 210.0 quantity: 1.0 product_id: product.product_product_3 uos_id: product.product_uom_unit diff --git a/account_statement_base_completion/test/partner.yml b/account_statement_base_completion/test/partner.yml new file mode 100644 index 00000000..bc8fca6c --- /dev/null +++ b/account_statement_base_completion/test/partner.yml @@ -0,0 +1,5 @@ +- + I fill in the field Bank Statement Label in a Partner +- + !record {model: res.partner, id: base.res_partner_6}: + bank_statement_label: XXX66Z From 1a2da08be81af7966424a8b640d80204aa02480f Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 13 Dec 2013 21:10:44 +0100 Subject: [PATCH 15/34] [imp] completion tests --- .../__openerp__.py | 1 + .../test/completion_test.yml | 58 +++++++++++++------ 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/account_statement_base_completion/__openerp__.py b/account_statement_base_completion/__openerp__.py index b7e6bdc6..2e15450b 100644 --- a/account_statement_base_completion/__openerp__.py +++ b/account_statement_base_completion/__openerp__.py @@ -69,6 +69,7 @@ 'test': [ 'test/partner.yml', 'test/invoice.yml', + 'test/supplier_invoice.yml', 'test/completion_test.yml' ], 'installable': True, diff --git a/account_statement_base_completion/test/completion_test.yml b/account_statement_base_completion/test/completion_test.yml index 976a2dac..796c4b6e 100644 --- a/account_statement_base_completion/test/completion_test.yml +++ b/account_statement_base_completion/test/completion_test.yml @@ -19,25 +19,49 @@ name: Statement 2 profile_id: profile_test1 company_id: base.main_company - line_ids: - - name: Test autocompletion based on Customer Invoice Number - ref: CI0001 - date: '2013-12-20' - amount: 210.0 - - name: Test autocompletion based on Supplier Invoice Number - ref: T2S12345 - date: '2013-12-19' - amount: -65.0 - - name: Test autocompletion based on Partner Name Vauxoo - ref: / - date: '2013-12-17' - amount: 600.0 - - name: test autocompletion based on text (XXX66Z) matching with partner form information (note that Ref does not exist) - ref: ZU788 - date: '2013-12-24' - amount: -932.4 +- + I create a statement line for a CI +- + !record {model: account.bank.statement.line, id: statement_line_ci}: + name: Test autocompletion based on Customer Invoice Number + statement_id: statement_test1 + ref: CI0001 + date: '2013-12-20' + amount: 210.0 +- + I create a statement line for a SI +- + !record {model: account.bank.statement.line, id: statement_line_si}: + name: Test autocompletion based on Supplier Invoice Number + statement_id: statement_test1 + ref: T2S12345 + date: '2013-12-19' + amount: -65.0 +- + I create a statement line for the Partner Name +- + !record {model: account.bank.statement.line, id: statement_line_partner_name}: + name: Test autocompletion based on Partner Name Vauxoo + statement_id: statement_test1 + ref: / + date: '2013-12-17' + amount: 600.0 +- + I create a statement line for the Partner Label +- + !record {model: account.bank.statement.line, id: statement_line_partner_label}: + name: test autocompletion based on text (XXX66Z) matching with partner form information (note that Ref does not exist) + statement_id: statement_test1 + ref: ZU788 + date: '2013-12-24' + amount: -932.4 - I run the auto complete - !python {model: account.bank.statement}: | result = self.button_auto_completion(cr, uid, [ref("statement_test1")]) +- + Now I can check that all is nice and shiny, line 1 +- + !assert {model: account.bank.statement.line, id: statement_line_ci, string: Check completion by CI number}: + - partner_id == ref('res_partner_12') \ No newline at end of file From 1c66e3c3951fdd4eb88e3fac49a195cff4d50c11 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Mon, 16 Dec 2013 14:55:56 +0100 Subject: [PATCH 16/34] [fix] account_statement_ext: unwind related and stored field because it does not work in a constraint in YAML test, for some reason. This probably needs a more general solution. --- account_statement_ext/statement.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 4775362b..54857212 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -223,12 +223,21 @@ class AccountBankSatement(Model): move of period_id to the statement line """ for statement in self.browse(cr, uid, ids, context=context): - if (statement.period_id and - statement.company_id.id != statement.period_id.company_id.id): + # statement.company_id is a related store=True that for some + # reason doesn't work in YAML tests. As a workaround, I unwind it + # to statement.journal_id.company_id here. + if ( + statement.period_id + and statement.journal_id.company_id.id + != statement.period_id.company_id.id + ): return False for line in statement.line_ids: - if (line.period_id and - statement.company_id.id != line.period_id.company_id.id): + if ( + line.period_id + and statement.journal_id.company_id.id + != line.period_id.company_id.id + ): return False return True From b54f6997e526722683ca2f74fb5660bb0bbbc86b Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Wed, 18 Dec 2013 19:09:04 +0100 Subject: [PATCH 17/34] [fix] account_statement_ext: remove hidden fields from on_change --- account_statement_ext/statement.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 4775362b..7022c366 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -552,12 +552,8 @@ class AccountBankSatement(Model): import_config = self.pool.get("account.statement.profile").browse( cr, uid, profile_id, context=context) journal_id = import_config.journal_id.id - account_id = import_config.journal_id.default_debit_account_id.id - credit_partner_id = import_config.partner_id and import_config.partner_id.id or False return {'value': {'journal_id': journal_id, - 'account_id': account_id, - 'balance_check': import_config.balance_check, - 'credit_partner_id': credit_partner_id}} + 'balance_check': import_config.balance_check}} class AccountBankSatementLine(Model): From 8a46f556f1f93590150a202d4e7e8fdb3c1d4aa8 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 19 Dec 2013 11:13:30 +0100 Subject: [PATCH 18/34] [imp] pep8 --- account_statement_ext/statement.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/account_statement_ext/statement.py b/account_statement_ext/statement.py index 54857212..392e0b9d 100644 --- a/account_statement_ext/statement.py +++ b/account_statement_ext/statement.py @@ -226,18 +226,14 @@ class AccountBankSatement(Model): # statement.company_id is a related store=True that for some # reason doesn't work in YAML tests. As a workaround, I unwind it # to statement.journal_id.company_id here. - if ( - statement.period_id - and statement.journal_id.company_id.id - != statement.period_id.company_id.id - ): + if (statement.period_id and + statement.journal_id.company_id.id != + statement.period_id.company_id.id): return False for line in statement.line_ids: - if ( - line.period_id - and statement.journal_id.company_id.id - != line.period_id.company_id.id - ): + if (line.period_id and + statement.journal_id.company_id.id + != line.period_id.company_id.id): return False return True From b16ece087d7e421c1e4df30d301a5ee6553e1f0a Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 20 Dec 2013 11:55:21 +0100 Subject: [PATCH 19/34] [imp] bank statements: check 4 lines --- .../test/completion_test.yml | 20 ++++++++++++++++++- .../test/supplier_invoice.yml | 14 +++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 account_statement_base_completion/test/supplier_invoice.yml diff --git a/account_statement_base_completion/test/completion_test.yml b/account_statement_base_completion/test/completion_test.yml index 4d8ae085..5b87a959 100644 --- a/account_statement_base_completion/test/completion_test.yml +++ b/account_statement_base_completion/test/completion_test.yml @@ -13,7 +13,8 @@ - bank_statement_completion_rule_2 - bank_statement_completion_rule_3 - - Now I create a statement + Now I create a statement. I create statment lines separately because I need + to find each one by XML id - !record {model: account.bank.statement, id: statement_test1}: name: Statement 2 @@ -67,3 +68,20 @@ - !assert {model: account.bank.statement.line, id: statement_line_ci, string: Check completion by CI number}: - partner_id.id == _ref("base.res_partner_12") +- + Line 2. I expect the Supplier invoice number to be recognised. The supplier + invoice was created by the account module demo data, and we confirmed it + here. +- + !assert {model: account.bank.statement.line, id: statement_line_si, string: Check completion by SI number}: + - partner_id.id == _ref("base.res_partner_17") +- + Line 3. I check that the partner name has been recognised. +- + !assert {model: account.bank.statement.line, id: statement_line_partner_name, string: Check completion by partner name}: + - partner_id.name == 'Vauxoo' +- + Line 4. I check that the partner special label has been recognised. +- + !assert {model: account.bank.statement.line, id: statement_line_partner_label, string: Check completion by partner label}: + - partner_id.id == _ref("base.res_partner_6") diff --git a/account_statement_base_completion/test/supplier_invoice.yml b/account_statement_base_completion/test/supplier_invoice.yml new file mode 100644 index 00000000..24dbad82 --- /dev/null +++ b/account_statement_base_completion/test/supplier_invoice.yml @@ -0,0 +1,14 @@ +- + I add a reference to an existing supplier invoce +- + !record {model: account.invoice, id: account.demo_invoice_0}: + supplier_invoice_number: T2S12345 +- + Now I confirm it +- + !workflow {model: account.invoice, action: invoice_open, ref: account.demo_invoice_0} +- + I check that the supplier number is there +- + !assert {model: account.invoice, id: account.demo_invoice_0, string: Check supplier number}: + - supplier_invoice_number == 'T2S12345' From 562250842a564e6d4b9611c64417934b94dc8547 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 20 Dec 2013 15:16:41 +0100 Subject: [PATCH 20/34] [fix] yaml: !record is to create. use python write --- .../test/supplier_invoice.yml | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/account_statement_base_completion/test/supplier_invoice.yml b/account_statement_base_completion/test/supplier_invoice.yml index 24dbad82..1bd826f9 100644 --- a/account_statement_base_completion/test/supplier_invoice.yml +++ b/account_statement_base_completion/test/supplier_invoice.yml @@ -1,8 +1,20 @@ +- + I check that my invoice is a supplier invoice +- + !assert {model: account.invoice, id: account.demo_invoice_0, string: Check invoice type}: + - type == 'in_invoice' - I add a reference to an existing supplier invoce - - !record {model: account.invoice, id: account.demo_invoice_0}: - supplier_invoice_number: T2S12345 + !python {model: account.invoice}: | + self.write(cr, uid, ref('account.demo_invoice_0'), { + 'supplier_invoice_number': 'T2S12345' + }) +- + I check a second time that my invoice is still a supplier invoice +- + !assert {model: account.invoice, id: account.demo_invoice_0, string: Check invoice type 2}: + - type == 'in_invoice' - Now I confirm it - @@ -12,3 +24,8 @@ - !assert {model: account.invoice, id: account.demo_invoice_0, string: Check supplier number}: - supplier_invoice_number == 'T2S12345' +- + I check a third time that my invoice is still a supplier invoice +- + !assert {model: account.invoice, id: account.demo_invoice_0, string: Check invoice type 3}: + - type == 'in_invoice' From aba2cd43974698a9f443d8579c6e453785d89d27 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 20 Dec 2013 16:43:01 +0100 Subject: [PATCH 21/34] [add] account_statement_so_completion/test --- .../__openerp__.py | 3 +- .../test/completion_so_test.yml | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 account_statement_so_completion/test/completion_so_test.yml diff --git a/account_statement_so_completion/__openerp__.py b/account_statement_so_completion/__openerp__.py index 929e46c8..cc0e4286 100644 --- a/account_statement_so_completion/__openerp__.py +++ b/account_statement_so_completion/__openerp__.py @@ -45,7 +45,8 @@ 'data.xml', ], 'demo_xml': [], - 'test': [], + 'test': [ + 'test/completion_so_test.yml'], 'installable': True, 'images': [], 'auto_install': True, diff --git a/account_statement_so_completion/test/completion_so_test.yml b/account_statement_so_completion/test/completion_so_test.yml new file mode 100644 index 00000000..3b0bda3f --- /dev/null +++ b/account_statement_so_completion/test/completion_so_test.yml @@ -0,0 +1,44 @@ +- + In order to test the banking framework for Sale Orders, I first need to + create a profile +- + !record {model: account.statement.profile, id: profile_test_so}: + name: Bank EUR Profile for SO + journal_id: account.bank_journal + commission_account_id: account.a_expense + company_id: base.main_company + balance_check: True + rule_ids: + - account_statement_base_completion.bank_statement_completion_rule_4 + - account_statement_base_completion.bank_statement_completion_rule_5 + - account_statement_base_completion.bank_statement_completion_rule_2 + - account_statement_base_completion.bank_statement_completion_rule_3 + - bank_statement_completion_rule_1 +- + Now I create a statement. I create statment lines separately because I need + to find each one by XML id +- + !record {model: account.bank.statement, id: statement_test_sale1}: + name: Statement for SO + profile_id: profile_test_so + company_id: base.main_company +- + I create a statement line for a SO +- + !record {model: account.bank.statement.line, id: statement_line_so}: + name: Test autocompletion based on Sale Order Number + statement_id: statement_test_sale1 + ref: SO007 + date: '2013-12-20' + amount: 14981.0 +- + I run the auto complete +- + !python {model: account.bank.statement}: | + result = self.button_auto_completion(cr, uid, [ref("statement_test_sale1")]) +- + Now I can check that all is nice and shiny, line 1. I expect the Sale Order + Number to be recognised. +- + !assert {model: account.bank.statement.line, id: statement_line_so, string: Check completion by SO number}: + - partner_id.name == u'Luminous Technologies' From 655162b5993fdff88e2524c68267b42648dd2fb2 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 20 Dec 2013 16:45:19 +0100 Subject: [PATCH 22/34] [fix] function in the wrong place --- account_statement_so_completion/statement.py | 27 ++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/account_statement_so_completion/statement.py b/account_statement_so_completion/statement.py index f41fd906..dcf2378f 100644 --- a/account_statement_so_completion/statement.py +++ b/account_statement_so_completion/statement.py @@ -28,9 +28,18 @@ from tools.translate import _ from openerp.addons.account_statement_base_completion.statement import ErrorTooManyPartner -class account_statement_profile(orm.Model): +class account_statement_completion_rule(orm.Model): - _inherit = "account.statement.profile" + _name = "account.statement.completion.rule" + _inherit = "account.statement.completion.rule" + + def _get_functions(self, cr, uid, context=None): + res = super(account_statement_completion_rule, self)._get_functions( + cr, uid, context=context) + res.append( + ('get_from_ref_and_so', 'From line reference (based on SO number)') + ) + return res # Should be private but data are initialised with no update XML def get_from_ref_and_so(self, cr, uid, st_line, context=None): @@ -80,20 +89,6 @@ class account_statement_profile(orm.Model): res.update(st_vals) return res - -class account_statement_completion_rule(orm.Model): - - _name = "account.statement.completion.rule" - _inherit = "account.statement.completion.rule" - - def _get_functions(self, cr, uid, context=None): - res = super(account_statement_completion_rule, self)._get_functions( - cr, uid, context=context) - res.append( - ('get_from_ref_and_so', 'From line reference (based on SO number)') - ) - return res - _columns = { 'function_to_call': fields.selection(_get_functions, 'Method'), } From 53f2c55faaec540881484305b2ee2a6a4de79541 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Fri, 20 Dec 2013 17:25:50 +0100 Subject: [PATCH 23/34] [del] TODO --- account_statement_base_completion/test/TODO.txt | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 account_statement_base_completion/test/TODO.txt diff --git a/account_statement_base_completion/test/TODO.txt b/account_statement_base_completion/test/TODO.txt deleted file mode 100644 index 42bd3f37..00000000 --- a/account_statement_base_completion/test/TODO.txt +++ /dev/null @@ -1,3 +0,0 @@ -* statement default company, or company required? -* on_change -* statment doesn't have a company, why? \ No newline at end of file From ed60c48bea698646c55741b47466f69f407b943a Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 7 Jan 2014 12:27:26 +0100 Subject: [PATCH 24/34] [add] yaml tests for module account_statement_transactionid_completion --- .../__openerp__.py | 5 ++- .../test/completion_transactionid_test.yml | 44 +++++++++++++++++++ .../test/sale.yml | 11 +++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 account_statement_transactionid_completion/test/completion_transactionid_test.yml create mode 100644 account_statement_transactionid_completion/test/sale.yml diff --git a/account_statement_transactionid_completion/__openerp__.py b/account_statement_transactionid_completion/__openerp__.py index d8c20ea3..46513591 100644 --- a/account_statement_transactionid_completion/__openerp__.py +++ b/account_statement_transactionid_completion/__openerp__.py @@ -48,7 +48,10 @@ "data.xml", ], 'demo_xml': [], - 'test': [], + 'test': [ + 'test/sale.yml', + 'test/completion_transactionid_test.yml', + ], 'installable': True, 'images': [], 'auto_install': True, diff --git a/account_statement_transactionid_completion/test/completion_transactionid_test.yml b/account_statement_transactionid_completion/test/completion_transactionid_test.yml new file mode 100644 index 00000000..5b1cb4bd --- /dev/null +++ b/account_statement_transactionid_completion/test/completion_transactionid_test.yml @@ -0,0 +1,44 @@ +- + In order to test the banking framework, I first need to create a profile +- + !record {model: account.statement.profile, id: statement_profile_transactionid}: + name: Bank EUR Profile (transaction ID) + journal_id: account.bank_journal + commission_account_id: account.a_expense + company_id: base.main_company + balance_check: True + rule_ids: + - bank_statement_completion_rule_4 + - account_statement_base_completion.bank_statement_completion_rule_4 + - account_statement_base_completion.bank_statement_completion_rule_5 + - account_statement_base_completion.bank_statement_completion_rule_2 + - account_statement_base_completion.bank_statement_completion_rule_3 +- + Now I create a statement. I create statment lines separately because I need + to find each one by XML id +- + !record {model: account.bank.statement, id: statement_transactionid_test1}: + name: Statement with transaction ID + profile_id: statement_profile_transactionid + company_id: base.main_company +- + I create a statement line for a SO with transaction ID +- + !record {model: account.bank.statement.line, id: statement_line_transactionid}: + name: Test autocompletion based on SO with transaction ID + statement_id: statement_transactionid_test1 + transaction_id: XXX66Z + ref: 6 + date: '2014-01-06' + amount: 118.4 +- + I run the auto complete +- + !python {model: account.bank.statement}: | + result = self.button_auto_completion(cr, uid, [ref("statement_profile_transactionid")]) +- + Now I can check that all is nice and shiny, line 1. I expect the SO has been + recognised from the transaction ID. +- + !assert {model: account.bank.statement.line, id: statement_line_transactionid, string: Check completion by SO transaction ID}: + - partner_id.name == u'Agrolait' diff --git a/account_statement_transactionid_completion/test/sale.yml b/account_statement_transactionid_completion/test/sale.yml new file mode 100644 index 00000000..a8ba93a9 --- /dev/null +++ b/account_statement_transactionid_completion/test/sale.yml @@ -0,0 +1,11 @@ +- + I create a new Sale Order with transaction ID +- + !record {model: sale.order, id: so_with_transaction_id}: + partner_id: base.res_partner_2 + note: Invoice after delivery + payment_term: account.account_payment_term + transaction_id: XXX66Z + order_line: + - product_id: product.product_product_7 + product_uom_qty: 8 From d5ecec5a41f6910e94019d3ca86ae4eb89f039fd Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Tue, 14 Jan 2014 15:39:02 +0100 Subject: [PATCH 25/34] 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 26/34] 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 220eef50ec7c8b51eca6139d4970a82dad27c159 Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Tue, 14 Jan 2014 19:16:23 +0100 Subject: [PATCH 27/34] 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 28/34] 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 29/34] 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 30/34] 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 19abe5ed0195c8f7b442720976bc9f706e55c945 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Thu, 16 Jan 2014 11:35:20 +0100 Subject: [PATCH 31/34] [imp] manifest: data --- account_statement_so_completion/__openerp__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/account_statement_so_completion/__openerp__.py b/account_statement_so_completion/__openerp__.py index cc0e4286..30a7f581 100644 --- a/account_statement_so_completion/__openerp__.py +++ b/account_statement_so_completion/__openerp__.py @@ -40,11 +40,9 @@ 1) Match from statement line reference (based on SO number) """, 'website': 'http://www.camptocamp.com', - 'init_xml': [], - 'update_xml': [ + 'data': [ 'data.xml', ], - 'demo_xml': [], 'test': [ 'test/completion_so_test.yml'], 'installable': True, From b962fc2669b7773c993634b8dbb87b58ce074f5d Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Mon, 20 Jan 2014 10:06:39 +0100 Subject: [PATCH 32/34] 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 9c570e8c257014970d9595e9e0e0de5e085156d8 Mon Sep 17 00:00:00 2001 From: "Laetitia Gangloff (Acsone)" Date: Wed, 22 Jan 2014 12:17:19 +0100 Subject: [PATCH 33/34] 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 34/34] 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