forked from OCA/account-reconcile
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathres_partner_bank.py
52 lines (48 loc) · 1.82 KB
/
res_partner_bank.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
# 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
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()])],
context=context)