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
769 B

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