You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.5 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # This file is part of account_bank_statement_import,
  5. # an Odoo module.
  6. #
  7. # Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
  8. #
  9. # account_bank_statement_importis free software:
  10. # you can redistribute it and/or modify it under the terms of the GNU
  11. # Affero General Public License as published by the Free Software
  12. # Foundation,either version 3 of the License, or (at your option) any
  13. # later version.
  14. #
  15. # account_bank_statement_import is distributed
  16. # in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  17. # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  18. # PURPOSE. See the GNU Affero General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with account_bank_statement_import_coda.
  22. # If not, see <http://www.gnu.org/licenses/>.
  23. #
  24. ##############################################################################
  25. import re
  26. from openerp import api, models, fields
  27. class ResPartnerBank(models.Model):
  28. _inherit = 'res.partner.bank'
  29. sanitized_acc_number = fields.Char(
  30. 'Sanitized Account Number', size=64, readonly=True,
  31. compute='_get_sanitized_account_number', store=True, index=True)
  32. def _sanitize_account_number(self, acc_number):
  33. if acc_number:
  34. return re.sub(r'\W+', '', acc_number).upper()
  35. return False
  36. @api.one
  37. @api.depends('acc_number')
  38. def _get_sanitized_account_number(self):
  39. self.sanitized_acc_number = self._sanitize_account_number(
  40. self.acc_number)
  41. @api.returns('self')
  42. def search(self, cr, user, args, offset=0, limit=None, order=None,
  43. context=None, count=False):
  44. pos = 0
  45. while pos < len(args):
  46. if args[pos][0] == 'acc_number':
  47. op = args[pos][1]
  48. value = args[pos][2]
  49. if hasattr(value, '__iter__'):
  50. value = [self._sanitize_account_number(i) for i in value]
  51. else:
  52. value = self._sanitize_account_number(value)
  53. if 'like' in op:
  54. value = '%' + value + '%'
  55. args[pos] = ('sanitized_acc_number', op, value)
  56. pos += 1
  57. return super(ResPartnerBank, self).search(
  58. cr, user, args, offset=0, limit=None, order=None, context=None,
  59. count=False)