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.

64 lines
2.4 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.model
  42. def search(self, args, offset=0, limit=None, order=None, count=False):
  43. pos = 0
  44. while pos < len(args):
  45. if args[pos][0] == 'acc_number':
  46. op = args[pos][1]
  47. value = args[pos][2]
  48. if hasattr(value, '__iter__'):
  49. value = [self._sanitize_account_number(i) for i in value]
  50. else:
  51. value = self._sanitize_account_number(value)
  52. if 'like' in op:
  53. value = '%' + value + '%'
  54. args[pos] = ('sanitized_acc_number', op, value)
  55. pos += 1
  56. return super(ResPartnerBank, self).search(
  57. args, offset=offset, limit=limit, order=order, count=count)