Browse Source

[IMP] Sanitize acc_number to upper case

Use wildcard on both sides when opertor contains 'like'
pull/19/head
Laurent Mignon 10 years ago
committed by Laurent Mignon (ACSONE)
parent
commit
31fd68de92
  1. 13
      account_bank_statement_import/res_partner_bank.py
  2. 8
      account_bank_statement_import/tests/test_res_partner_bank.py

13
account_bank_statement_import/res_partner_bank.py

@ -35,16 +35,15 @@ class ResPartnerBank(models.Model):
compute='_get_sanitized_account_number', store=True, index=True) compute='_get_sanitized_account_number', store=True, index=True)
def _sanitize_account_number(self, acc_number): def _sanitize_account_number(self, acc_number):
return re.sub(r'\W+', '', acc_number)
if acc_number:
return re.sub(r'\W+', '', acc_number).upper()
return False
@api.one @api.one
@api.depends('acc_number') @api.depends('acc_number')
def _get_sanitized_account_number(self): def _get_sanitized_account_number(self):
value = self.acc_number
if not value:
self.sanitized_acc_number = False
else:
self.sanitized_acc_number = self._sanitize_account_number(value)
self.sanitized_acc_number = self._sanitize_account_number(
self.acc_number)
@api.returns('self') @api.returns('self')
def search(self, cr, user, args, offset=0, limit=None, order=None, def search(self, cr, user, args, offset=0, limit=None, order=None,
@ -59,7 +58,7 @@ class ResPartnerBank(models.Model):
else: else:
value = self._sanitize_account_number(value) value = self._sanitize_account_number(value)
if 'like' in op: if 'like' in op:
value = value + '%'
value = '%' + value + '%'
args[pos] = ('sanitized_acc_number', op, value) args[pos] = ('sanitized_acc_number', op, value)
pos += 1 pos += 1
return super(ResPartnerBank, self).search( return super(ResPartnerBank, self).search(

8
account_bank_statement_import/tests/test_res_partner_bank.py

@ -60,3 +60,11 @@ class TestResPartnerBank(TransactionCase):
self.assertEquals(partner_bank, vals[0]) self.assertEquals(partner_bank, vals[0])
self.assertEqual(partner_bank.sanitized_acc_number, self.assertEqual(partner_bank.sanitized_acc_number,
sanitized_acc_number) sanitized_acc_number)
# search is case insensitive
vals = partner_bank_model.search(
[('acc_number', '=', sanitized_acc_number.lower())])
self.assertEquals(1, len(vals))
vals = partner_bank_model.search(
[('acc_number', '=', acc_number.lower())])
self.assertEquals(1, len(vals))
Loading…
Cancel
Save