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.

44 lines
1.7 KiB

  1. # Copyright 2016-2019 Akretion France (http://www.akretion.com/)
  2. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import api, models
  5. class ResPartner(models.Model):
  6. _name = 'res.partner'
  7. # inherit on phone.validation.mixin (same as in crm_phone_validation,
  8. # but base_phone only depends on phone_validation,
  9. # not on crm_phone_validation)
  10. _inherit = ['res.partner', 'phone.validation.mixin']
  11. _phone_name_sequence = 10
  12. _phone_name_fields = ['phone', 'mobile']
  13. def name_get(self):
  14. if self._context.get('callerid'):
  15. res = []
  16. for partner in self:
  17. if partner.parent_id and partner.parent_id.is_company:
  18. name = u'%s (%s)' % (partner.name, partner.parent_id.name)
  19. else:
  20. name = partner.name
  21. res.append((partner.id, name))
  22. return res
  23. else:
  24. return super(ResPartner, self).name_get()
  25. # These 2 onchange have the same name (and same code) than in the
  26. # module crm_phone_validation ; but we don't depend on that module
  27. # because we don't want base_phone to depend on crm.
  28. # When both base_phone AND crm_phone_validation are installed,
  29. # as the methods have the same name, only one of the 2 will be executed
  30. @api.onchange('phone', 'country_id', 'company_id')
  31. def _onchange_phone_validation(self):
  32. if self.phone:
  33. self.phone = self.phone_format(self.phone)
  34. @api.onchange('mobile', 'country_id', 'company_id')
  35. def _onchange_mobile_validation(self):
  36. if self.mobile:
  37. self.mobile = self.phone_format(self.mobile)