Browse Source
[IMP] Add sanitezed_acc_number on res.partenr.bank
[IMP] Add sanitezed_acc_number on res.partenr.bank
The new field is computed by sanitzing the acc_number.pull/19/head
Laurent Mignon
10 years ago
committed by
Laurent Mignon (ACSONE)
5 changed files with 133 additions and 9 deletions
-
1account_bank_statement_import/__init__.py
-
11account_bank_statement_import/account_bank_statement_import.py
-
67account_bank_statement_import/res_partner_bank.py
-
1account_bank_statement_import/tests/__init__.py
-
62account_bank_statement_import/tests/test_res_partner_bank.py
@ -1,3 +1,4 @@ |
|||||
# -*- encoding: utf-8 -*- |
# -*- encoding: utf-8 -*- |
||||
|
|
||||
|
from . import res_partner_bank |
||||
from . import account_bank_statement_import |
from . import account_bank_statement_import |
@ -0,0 +1,67 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This file is part of account_bank_statement_import, |
||||
|
# an Odoo module. |
||||
|
# |
||||
|
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>) |
||||
|
# |
||||
|
# account_bank_statement_importis 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. |
||||
|
# |
||||
|
# account_bank_statement_import 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 account_bank_statement_import_coda. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
|
||||
|
import re |
||||
|
from openerp import api, models, fields |
||||
|
|
||||
|
|
||||
|
class ResPartnerBank(models.Model): |
||||
|
_inherit = 'res.partner.bank' |
||||
|
|
||||
|
sanitized_acc_number = fields.Char( |
||||
|
'Sanitized Account Number', size=64, readonly=True, |
||||
|
compute='_get_sanitized_account_number', store=True, index=True) |
||||
|
|
||||
|
def _sanitize_account_number(self, acc_number): |
||||
|
return re.sub(r'\W+', '', acc_number) |
||||
|
|
||||
|
@api.one |
||||
|
@api.depends('acc_number') |
||||
|
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) |
||||
|
|
||||
|
@api.returns('self') |
||||
|
def search(self, cr, user, args, offset=0, limit=None, order=None, |
||||
|
context=None, count=False): |
||||
|
pos = 0 |
||||
|
while pos < len(args): |
||||
|
if args[pos][0] == 'acc_number': |
||||
|
op = args[pos][1] |
||||
|
value = args[pos][2] |
||||
|
if hasattr(value, '__iter__'): |
||||
|
value = [self._sanitize_account_number(i) for i in value] |
||||
|
else: |
||||
|
value = self._sanitize_account_number(value) |
||||
|
if 'like' in op: |
||||
|
value = value + '%' |
||||
|
args[pos] = ('sanitized_acc_number', op, value) |
||||
|
pos += 1 |
||||
|
return super(ResPartnerBank, self).search( |
||||
|
cr, user, args, offset=0, limit=None, order=None, context=None, |
||||
|
count=False) |
@ -1,2 +1,3 @@ |
|||||
# -*- encoding: utf-8 -*- |
# -*- encoding: utf-8 -*- |
||||
|
from . import test_res_partner_bank |
||||
from . import test_import_bank_statement |
from . import test_import_bank_statement |
@ -0,0 +1,62 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# This file is part of account_bank_statement_import, |
||||
|
# an Odoo module. |
||||
|
# |
||||
|
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>) |
||||
|
# |
||||
|
# account_bank_statement_import 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. |
||||
|
# |
||||
|
# account_bank_statement_import 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 account_bank_statement_import_coda. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from openerp.tests.common import TransactionCase |
||||
|
|
||||
|
|
||||
|
class TestResPartnerBank(TransactionCase): |
||||
|
"""Tests acc_number |
||||
|
""" |
||||
|
|
||||
|
def test_sanitized_acc_number(self): |
||||
|
partner_bank_model = self.env['res.partner.bank'] |
||||
|
acc_number = " BE-001 2518823 03 " |
||||
|
vals = partner_bank_model.search([('acc_number', '=', acc_number)]) |
||||
|
self.assertEquals(0, len(vals)) |
||||
|
partner_bank = partner_bank_model.create({ |
||||
|
'acc_number': acc_number, |
||||
|
'partner_id': self.ref('base.res_partner_2'), |
||||
|
'state': 'bank', |
||||
|
}) |
||||
|
vals = partner_bank_model.search([('acc_number', '=', acc_number)]) |
||||
|
self.assertEquals(1, len(vals)) |
||||
|
self.assertEquals(partner_bank, vals[0]) |
||||
|
vals = partner_bank_model.search([('acc_number', 'in', [acc_number])]) |
||||
|
self.assertEquals(1, len(vals)) |
||||
|
self.assertEquals(partner_bank, vals[0]) |
||||
|
|
||||
|
self.assertEqual(partner_bank.acc_number, acc_number) |
||||
|
|
||||
|
# sanitaze the acc_number |
||||
|
sanitized_acc_number = 'BE001251882303' |
||||
|
vals = partner_bank_model.search( |
||||
|
[('acc_number', '=', sanitized_acc_number)]) |
||||
|
self.assertEquals(1, len(vals)) |
||||
|
self.assertEquals(partner_bank, vals[0]) |
||||
|
vals = partner_bank_model.search( |
||||
|
[('acc_number', 'in', [sanitized_acc_number])]) |
||||
|
self.assertEquals(1, len(vals)) |
||||
|
self.assertEquals(partner_bank, vals[0]) |
||||
|
self.assertEqual(partner_bank.sanitized_acc_number, |
||||
|
sanitized_acc_number) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue