[REF] l10n_fr_rib: refactored bank name_search as suggested by Olivier Dony (OpenERP)
authorNumerigraphe - Lionel Sausin <ls@numerigraphe.fr>
Mon, 28 Nov 2011 16:00:01 +0000 (17:00 +0100)
committerNumerigraphe - Lionel Sausin <ls@numerigraphe.fr>
Mon, 28 Nov 2011 16:00:01 +0000 (17:00 +0100)
[IMP] l10n_fr_rib: don't re-check error condition when constructing the message for key mismatch
[FIx] l10n_fr_rib: wrong field name for bank code

bzr revid: ls@numerigraphe.fr-20111128160001-q7re8fxr9lv2ad9g

addons/l10n_fr_rib/bank.py

index ea32bca..4875dc3 100644 (file)
@@ -61,7 +61,7 @@ class res_partner_bank(osv.osv):
         if bank_id:
             bank = self.pool.get('res.bank').browse(cr, uid, bank_id, 
                                                     context=context)
-            result['bank_code'] = bank.code
+            result['bank_code'] = bank.rib_code
         return {'value': result}
 
     _columns = {
@@ -74,8 +74,6 @@ class res_partner_bank(osv.osv):
     
     def _construct_constraint_msg(self, cr, uid, ids, context=None):
         """Quote the data in the warning message"""
-        if self._check_key(cr, uid, ids):
-            return
         # Only process the first id
         if type(ids) not in (int, long):
             id = ids[0]
@@ -100,17 +98,17 @@ class res_bank(osv.osv):
 
     def name_search(self, cr, user, name, args=None, operator='ilike',
                     context=None, limit=80):
-        """Search by bank code"""
-        if args is None:
-            args = []
-        ids = []
-        if name:
-            ids = self.search(cr, user, [('name', operator, name)] + args,
+        """Search by bank code in addition to the standard search"""
+        # Get the standard results
+        results = super(res_bank, self).name_search(cr, user,
+             name, args=args ,operator=operator, context=context, limit=limit)
+        # Get additional results using the RIB code
+        ids = self.search(cr, user, [('rib_code', operator, name)],
                               limit=limit, context=context)
-        if not ids:
-            ids = self.search(cr, user, [('code', operator, name)] + args,
-                              limit=limit, context=context)
-        return self.name_get(cr, user, ids, context)
+        # Merge the results
+        results = list(set(results + self.name_get(cr, user, ids, context)))
+        print results
+        return results
         
     _columns = {
         'rib_code': fields.char('RIB Bank Code', size=64),