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.

25 lines
780 B

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Akretion (http://www.akretion.com)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. # @author Alexis de Lattre <alexis.delattre@akretion.com>
  5. from odoo import models, fields, api
  6. import re
  7. class ResPartner(models.Model):
  8. _inherit = 'res.partner'
  9. sanitized_vat = fields.Char(
  10. compute='compute_sanitized_vat', string='Sanitized TIN',
  11. store=True, readonly=True,
  12. help='TIN in uppercase without spaces nor special caracters.')
  13. def _sanitize_vat(self, vat):
  14. return vat and re.sub(r'\W+', '', vat).upper() or False
  15. @api.multi
  16. @api.depends('vat')
  17. def compute_sanitized_vat(self):
  18. for partner in self:
  19. partner.sanitized_vat = self._sanitize_vat(partner.vat)