← Back to team overview

banking-addons-team team mailing list archive

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

 

Laurent Mignon (Acsone) has proposed merging lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion into lp:banking-addons/bank-statement-reconcile-7.0.

Requested reviews:
  Pedro Manuel Baeza (pedro.baeza): code review

For more details, see:
https://code.launchpad.net/~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion/+merge/202861

Improve the matching on acc_number by removing the formatting characters when querying the res_partner_bank table
-- 
https://code.launchpad.net/~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion/+merge/202861
Your team Banking Addons Core Editors is subscribed to branch lp:banking-addons/bank-statement-reconcile-7.0.
=== 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 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 #
-import statement
+from . import statement
+from . import res_partner_bank

=== 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 @@
+#
+# Authors: Laurent Mignon
+# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
+# All Rights Reserved
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#
+from openerp.osv.orm import Model
+from openerp.addons.base_iban import base_iban
+
+
+class res_partner_bank(Model):
+    _inherit = 'res.partner.bank'
+
+    def search_by_acc_number(self, cr, uid, acc_number, context=None):
+        '''
+        Try to find the Account Number using a 'like' operator to avoid problems with the input mask
+        used to store the value.
+        '''
+        # first try with an exact match
+        ids = self.search(cr,
+                                  uid,
+                                  [('acc_number', '=', acc_number)],
+                                  context=context)
+        if ids:
+            return ids
+
+        cr.execute("""
+            SELECT
+                id
+            FROM
+                res_partner_bank
+            WHERE
+                regexp_replace(acc_number,'([^[:alnum:]])', '','g')  ilike  regexp_replace(%s,'([^[:alnum:]])', '','g') """,
+            (acc_number,))
+        #apply security constraints by using the orm
+        return self.search(cr, uid, [('id', 'in', [r[0] for r in cr.fetchall()])])

=== 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 @@
         st_obj = self.pool.get('account.bank.statement.line')
         res = {}
         res_bank_obj = self.pool.get('res.partner.bank')
-        ids = res_bank_obj.search(cr,
+        ids = res_bank_obj.search_by_acc_number(cr,
                                   uid,
-                                  [('acc_number', '=', partner_acc_number)],
+                                  partner_acc_number,
                                   context=context)
         if len(ids) > 1:
             raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more than '

=== 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 @@
 from openerp.tests import common
 import time
 
-ACC_NUMBER = "BE38733040385372"
+ACC_NUMBER = " BE38 7330 4038 5372 "
 
 
 class bankaccount_completion(common.TransactionCase):
 
-    def prepare(self):
+    def setUp(self):
+        super(bankaccount_completion, self).setUp()
         self.company_a = self.browse_ref('base.main_company')
         self.profile_obj = self.registry("account.statement.profile")
         self.account_bank_statement_obj = self.registry("account.bank.statement")
         self.account_bank_statement_line_obj = self.registry("account.bank.statement.line")
         self.completion_rule_id = self.ref('account_statement_bankaccount_completion.bank_statement_completion_rule_10')
-        self.journal_id = self.registry("ir.model.data").get_object_reference(self.cr, self. uid, "account", "bank_journal")[1]
+        self.journal_id = self.ref("account.bank_journal")
         self.partner_id = self.ref('base.main_partner')
+        self.account_id = self.ref("account.a_recv")
+
         # Create the profile
-        self.account_id = self.registry("ir.model.data").get_object_reference(self.cr, self.uid, "account", "a_recv")[1]
-        self.journal_id = self.registry("ir.model.data").get_object_reference(self.cr, self. uid, "account", "bank_journal")[1]
         self.profile_id = self.profile_obj.create(self.cr, self.uid, {
             "name": "TEST",
             "commission_account_id": self.account_id,
             "journal_id": self.journal_id,
             "rule_ids": [(6, 0, [self.completion_rule_id])]})
-        # Create the completion rule
-
         # Create a bank statement
         self.statement_id = self.account_bank_statement_obj.create(self.cr, self.uid, {
             "balance_end_real": 0.0,
@@ -55,18 +54,9 @@
 
         })
 
-        # Create bank a statement line
-        self.statement_line_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, {
-            'amount': 1000.0,
-            'name': 'EXT001',
-            'ref': 'My ref',
-            'statement_id': self.statement_id,
-            'partner_acc_number': ACC_NUMBER
-        })
-
         # Add a bank account number to the partner
-        res_bank_obj = self.registry('res.partner.bank')
-        res_bank_obj.create(self.cr, self.uid, {
+        self.res_partner_bank_obj = self.registry('res.partner.bank')
+        self.res_partner_bank_id = self.res_partner_bank_obj.create(self.cr, self.uid, {
                             "state": "bank",
                             "company_id": self.company_a.id,
                             "partner_id": self.partner_id,
@@ -77,15 +67,39 @@
 
     def test_00(self):
         """Test complete partner_id from bank account number
-        
         Test the automatic completion of the partner_id based on the account number associated to the
         statement line
         """
-        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")
+        for bank_acc_number in [ACC_NUMBER, ACC_NUMBER.replace(" ", ""), ACC_NUMBER.replace(" ", "-")]:
+            # check the completion for well formatted and not well formatted account number
+            self.res_partner_bank_obj.write(self.cr, self.uid, self.res_partner_bank_id, {
+                            "acc_number": bank_acc_number,
+                            })
+            for acc_number in [ACC_NUMBER, ACC_NUMBER.replace(" ", ""), ACC_NUMBER.replace(" ", "-"), " BE38-7330 4038-5372 "]:
+                statement_line_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, {
+                    'amount': 1000.0,
+                    'name': 'EXT001',
+                    'ref': 'My ref',
+                    'statement_id': self.statement_id,
+                    'partner_acc_number': acc_number
+                })
+                statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id)
+                self.assertFalse(statement_line.partner_id, "Partner_id must be blank before completion")
+                statement_obj = self.account_bank_statement_obj.browse(self.cr, self.uid, self.statement_id)
+                statement_obj.button_auto_completion()
+                statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id)
+                self.assertEquals(self.partner_id, statement_line.partner_id['id'], "Missing expected partner id after completion")
+
+            statement_line_id = self.account_bank_statement_line_obj.create(self.cr, self.uid, {
+                    'amount': 1000.0,
+                    'name': 'EXT001',
+                    'ref': 'My ref',
+                    'statement_id': self.statement_id,
+                    'partner_acc_number': 'BE38a7330.4038-5372.'
+                })
+            statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id)
+            self.assertFalse(statement_line.partner_id, "Partner_id must be blank before completion")
+            statement_obj = self.account_bank_statement_obj.browse(self.cr, self.uid, self.statement_id)
+            statement_obj.button_auto_completion()
+            statement_line = self.account_bank_statement_line_obj.browse(self.cr, self.uid, statement_line_id)
+            self.assertFalse(statement_line.partner_id.id)


Follow ups