Merge lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion into lp:banking-addons/bank-statement-reconcile-70

Proposed by Laurent Mignon (Acsone)
Status: Needs review
Proposed branch: lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 190 lines (+94/-30)
4 files modified
account_statement_bankaccount_completion/__init__.py (+2/-1)
account_statement_bankaccount_completion/res_partner_bank.py (+49/-0)
account_statement_bankaccount_completion/statement.py (+2/-2)
account_statement_bankaccount_completion/tests/test_bankaccount_completion.py (+41/-27)
To merge this branch: bzr merge lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion
Reviewer Review Type Date Requested Status
Laurent Mignon (Acsone) (community) Disapprove
Yannick Vaucher @ Camptocamp code review, no test Needs Fixing
Pedro Manuel Baeza code review Needs Fixing
Review via email: mp+202861@code.launchpad.net

Description of the change

Improve the matching on acc_number by removing the formatting characters when querying the res_partner_bank table

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Some things catched on a first sight:

- Use from . import xxx on __init__.py
- 'if len(ids):' could be 'if ids', or better, put 'if not ids:' and put the rest of the code inside, returning only the value at the end, because it makes it more readable.
- Don't use SQL query. You can use also ORM search with like operator.
- Complete tests with calls to this method with more cases: account number without spaces that must be right, account number that must be wrong, so that we can test false positives.

Regards.

review: Needs Fixing (code review)
Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote :

> Some things catched on a first sight:
>
> - Use from . import xxx on __init__.py
OK I'll change

> - 'if len(ids):' could be 'if ids', or better, put 'if not ids:' and put the
OK
> rest of the code inside, returning only the value at the end, because it makes
> it more readable.
It's a point of view. I prefer to avoid too much indentation and return as soon as possible.

> - Don't use SQL query. You can use also ORM search with like operator.
The problem is not the 'like' operator, but the field to match "replace(replace(acc_number,' ',''),'-','')" The search method of the orm require a valid field name but in my case it's an expression. One thing can be done to avoid the bypass of the orm in this case (for security, etc), is to add a second search using the orm with an expression [('ids', 'in', ids] where ids is the result of the first search.

> - Complete tests with calls to this method with more cases: account number
> without spaces that must be right, account number that must be wrong, so that
> we can test false positives.
>
'account number without spaces' is already tested. I'll add a test for wrong account number.
> Regards.

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

res_partner_bank.py

Missing encoding definition in res_partner_bank.py

ll.49-51 have indentation issues

About SQL querry isn't it an issue of how are saved account number in database?

Maybe we should ensure data is clean instead of doing special querries.

review: Needs Fixing (code review, no test)
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

This project is now hosted on https://github.com/OCA/bank-statement-reconcile. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote :

following steps in
https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub
I'm not able to migrate my MP :(

On Wed, Jul 2, 2014 at 1:05 PM, Pedro Manuel Baeza <email address hidden>
wrote:

> This project is now hosted on
> https://github.com/OCA/bank-statement-reconcile. Please move your
> proposal there. This guide may help you
> https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub
> --
>
> https://code.launchpad.net/~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion/+merge/202861
> You proposed
> lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion
> for merging.
>

--
*Laurent Mignon*
*Senior Software Engineer*

*Tel : +352 20 21 10 20 32*
*Fax : +352 20 21 10 21*
*Gsm : +352 691 506 009*
*Email: <email address hidden> <email address hidden>*

*Acsone SA, Succursale de Luxembourg*
*22, Zone industrielle*
*L-8287 Kehlen, Luxembourg*
*www.acsone.eu <http://www.acsone.eu>*

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

I have already problems in this type of migration with some MPs, but not with others, but I'm not a git expert. What I have done is to recreate the diff on git base and make the PR as new. Can you do it this way?

Regards.

Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote :

It's what I'm doing ;)
Thank you for your reply.

Regards,

lmi

On Mon, Jul 7, 2014 at 12:36 PM, Pedro Manuel Baeza <email address hidden>
wrote:

> I have already problems in this type of migration with some MPs, but not
> with others, but I'm not a git expert. What I have done is to recreate the
> diff on git base and make the PR as new. Can you do it this way?
>
> Regards.
> --
>
> https://code.launchpad.net/~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion/+merge/202861
> You proposed
> lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion
> for merging.
>

--
*Laurent Mignon*
*Senior Software Engineer*

*Tel : +352 20 21 10 20 32*
*Fax : +352 20 21 10 21*
*Gsm : +352 691 506 009*
*Email: <email address hidden> <email address hidden>*

*Acsone SA, Succursale de Luxembourg*
*22, Zone industrielle*
*L-8287 Kehlen, Luxembourg*
*www.acsone.eu <http://www.acsone.eu>*

Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote :
review: Disapprove

Unmerged revisions

113. By Laurent Mignon (Acsone)

Use from . import xxx on __init__.py
Improve the SQL used to match account number
Filter results from the plain SQL query by using the method search from the ORM

112. By Laurent Mignon (Acsone)

[MRG] lp:banking-addons/bank-statement-reconcile-7.0

111. By Laurent Mignon (Acsone)

remove obsolete comment

110. By Laurent Mignon (Acsone)

Improve the matching on acc_number by removing the formatting characters when querying the res_partner_bank table

109. By Laurent Mignon (Acsone)

clean up tests before modifcations

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_statement_bankaccount_completion/__init__.py'
--- account_statement_bankaccount_completion/__init__.py 2013-08-22 15:09:03 +0000
+++ account_statement_bankaccount_completion/__init__.py 2014-04-24 10:53:38 +0000
@@ -18,4 +18,5 @@
18# along with this program. If not, see <http://www.gnu.org/licenses/>.18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#19#
20#20#
21import statement21from . import statement
22from . import res_partner_bank
2223
=== added file 'account_statement_bankaccount_completion/res_partner_bank.py'
--- account_statement_bankaccount_completion/res_partner_bank.py 1970-01-01 00:00:00 +0000
+++ account_statement_bankaccount_completion/res_partner_bank.py 2014-04-24 10:53:38 +0000
@@ -0,0 +1,49 @@
1#
2# Authors: Laurent Mignon
3# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
4# All Rights Reserved
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19#
20from openerp.osv.orm import Model
21from openerp.addons.base_iban import base_iban
22
23
24class res_partner_bank(Model):
25 _inherit = 'res.partner.bank'
26
27 def search_by_acc_number(self, cr, uid, acc_number, context=None):
28 '''
29 Try to find the Account Number using a 'like' operator to avoid problems with the input mask
30 used to store the value.
31 '''
32 # first try with an exact match
33 ids = self.search(cr,
34 uid,
35 [('acc_number', '=', acc_number)],
36 context=context)
37 if ids:
38 return ids
39
40 cr.execute("""
41 SELECT
42 id
43 FROM
44 res_partner_bank
45 WHERE
46 regexp_replace(acc_number,'([^[:alnum:]])', '','g') ilike regexp_replace(%s,'([^[:alnum:]])', '','g') """,
47 (acc_number,))
48 #apply security constraints by using the orm
49 return self.search(cr, uid, [('id', 'in', [r[0] for r in cr.fetchall()])])
050
=== modified file 'account_statement_bankaccount_completion/statement.py'
--- account_statement_bankaccount_completion/statement.py 2013-09-12 08:36:23 +0000
+++ account_statement_bankaccount_completion/statement.py 2014-04-24 10:53:38 +0000
@@ -60,9 +60,9 @@
60 st_obj = self.pool.get('account.bank.statement.line')60 st_obj = self.pool.get('account.bank.statement.line')
61 res = {}61 res = {}
62 res_bank_obj = self.pool.get('res.partner.bank')62 res_bank_obj = self.pool.get('res.partner.bank')
63 ids = res_bank_obj.search(cr,63 ids = res_bank_obj.search_by_acc_number(cr,
64 uid,64 uid,
65 [('acc_number', '=', partner_acc_number)],65 partner_acc_number,
66 context=context)66 context=context)
67 if len(ids) > 1:67 if len(ids) > 1:
68 raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than '68 raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than '
6969
=== modified file 'account_statement_bankaccount_completion/tests/test_bankaccount_completion.py'
--- account_statement_bankaccount_completion/tests/test_bankaccount_completion.py 2013-09-12 09:05:01 +0000
+++ account_statement_bankaccount_completion/tests/test_bankaccount_completion.py 2014-04-24 10:53:38 +0000
@@ -22,29 +22,28 @@
22from openerp.tests import common22from openerp.tests import common
23import time23import time
2424
25ACC_NUMBER = "BE38733040385372"25ACC_NUMBER = " BE38 7330 4038 5372 "
2626
2727
28class bankaccount_completion(common.TransactionCase):28class bankaccount_completion(common.TransactionCase):
2929
30 def prepare(self):30 def setUp(self):
31 super(bankaccount_completion, self).setUp()
31 self.company_a = self.browse_ref('base.main_company')32 self.company_a = self.browse_ref('base.main_company')
32 self.profile_obj = self.registry("account.statement.profile")33 self.profile_obj = self.registry("account.statement.profile")
33 self.account_bank_statement_obj = self.registry("account.bank.statement")34 self.account_bank_statement_obj = self.registry("account.bank.statement")
34 self.account_bank_statement_line_obj = self.registry("account.bank.statement.line")35 self.account_bank_statement_line_obj = self.registry("account.bank.statement.line")
35 self.completion_rule_id = self.ref('account_statement_bankaccount_completion.bank_statement_completion_rule_10')36 self.completion_rule_id = self.ref('account_statement_bankaccount_completion.bank_statement_completion_rule_10')
36 self.journal_id = self.registry("ir.model.data").get_object_reference(self.cr, self. uid, "account", "bank_journal")[1]37 self.journal_id = self.ref("account.bank_journal")
37 self.partner_id = self.ref('base.main_partner')38 self.partner_id = self.ref('base.main_partner')
39 self.account_id = self.ref("account.a_recv")
40
38 # Create the profile41 # Create the profile
39 self.account_id = self.registry("ir.model.data").get_object_reference(self.cr, self.uid, "account", "a_recv")[1]
40 self.journal_id = self.registry("ir.model.data").get_object_reference(self.cr, self. uid, "account", "bank_journal")[1]
41 self.profile_id = self.profile_obj.create(self.cr, self.uid, {42 self.profile_id = self.profile_obj.create(self.cr, self.uid, {
42 "name": "TEST",43 "name": "TEST",
43 "commission_account_id": self.account_id,44 "commission_account_id": self.account_id,
44 "journal_id": self.journal_id,45 "journal_id": self.journal_id,
45 "rule_ids": [(6, 0, [self.completion_rule_id])]})46 "rule_ids": [(6, 0, [self.completion_rule_id])]})
46 # Create the completion rule
47
48 # Create a bank statement47 # Create a bank statement
49 self.statement_id = self.account_bank_statement_obj.create(self.cr, self.uid, {48 self.statement_id = self.account_bank_statement_obj.create(self.cr, self.uid, {
50 "balance_end_real": 0.0,49 "balance_end_real": 0.0,
@@ -55,18 +54,9 @@
5554
56 })55 })
5756
58 # Create bank a statement line
59 self.statement_line_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, {
60 'amount': 1000.0,
61 'name': 'EXT001',
62 'ref': 'My ref',
63 'statement_id': self.statement_id,
64 'partner_acc_number': ACC_NUMBER
65 })
66
67 # Add a bank account number to the partner57 # Add a bank account number to the partner
68 res_bank_obj = self.registry('res.partner.bank')58 self.res_partner_bank_obj = self.registry('res.partner.bank')
69 res_bank_obj.create(self.cr, self.uid, {59 self.res_partner_bank_id = self.res_partner_bank_obj.create(self.cr, self.uid, {
70 "state": "bank",60 "state": "bank",
71 "company_id": self.company_a.id,61 "company_id": self.company_a.id,
72 "partner_id": self.partner_id,62 "partner_id": self.partner_id,
@@ -77,15 +67,39 @@
7767
78 def test_00(self):68 def test_00(self):
79 """Test complete partner_id from bank account number69 """Test complete partner_id from bank account number
80
81 Test the automatic completion of the partner_id based on the account number associated to the70 Test the automatic completion of the partner_id based on the account number associated to the
82 statement line71 statement line
83 """72 """
84 self.prepare()73 for bank_acc_number in [ACC_NUMBER, ACC_NUMBER.replace(" ", ""), ACC_NUMBER.replace(" ", "-")]:
85 statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, self.statement_line_id)74 # check the completion for well formatted and not well formatted account number
86 # before import, the75 self.res_partner_bank_obj.write(self.cr, self.uid, self.res_partner_bank_id, {
87 self.assertFalse(statement_line.partner_id, "Partner_id must be blank before completion")76 "acc_number": bank_acc_number,
88 statement_obj = self.account_bank_statement_obj.browse(self.cr, self.uid, self.statement_id)77 })
89 statement_obj.button_auto_completion()78 for acc_number in [ACC_NUMBER, ACC_NUMBER.replace(" ", ""), ACC_NUMBER.replace(" ", "-"), " BE38-7330 4038-5372 "]:
90 statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, self.statement_line_id)79 statement_line_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, {
91 self.assertEquals(self.partner_id, statement_line.partner_id['id'], "Missing expected partner id after completion")80 'amount': 1000.0,
81 'name': 'EXT001',
82 'ref': 'My ref',
83 'statement_id': self.statement_id,
84 'partner_acc_number': acc_number
85 })
86 statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id)
87 self.assertFalse(statement_line.partner_id, "Partner_id must be blank before completion")
88 statement_obj = self.account_bank_statement_obj.browse(self.cr, self.uid, self.statement_id)
89 statement_obj.button_auto_completion()
90 statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id)
91 self.assertEquals(self.partner_id, statement_line.partner_id['id'], "Missing expected partner id after completion")
92
93 statement_line_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, {
94 'amount': 1000.0,
95 'name': 'EXT001',
96 'ref': 'My ref',
97 'statement_id': self.statement_id,
98 'partner_acc_number': 'BE38a7330.4038-5372.'
99 })
100 statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id)
101 self.assertFalse(statement_line.partner_id, "Partner_id must be blank before completion")
102 statement_obj = self.account_bank_statement_obj.browse(self.cr, self.uid, self.statement_id)
103 statement_obj.button_auto_completion()
104 statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id)
105 self.assertFalse(statement_line.partner_id.id)

Subscribers

People subscribed via source and target branches