Files
odoo_source/addons/phone_validation/models/phone_validation_mixin.py
T
Jérome Maes 800d54e846 [FIX] phone_validation: bad code comparison
During the formating method, the country code
was compared to the country phone code. Indeed,
phonenumbers python lib return a `PhoneNumber`
object having a `country_code` attribute
refering to the country_phone_code, and not
the country_code (like odoo means).
Consequence: changing the country on a lead
did not make the phone validation work.

Thus, it was required to give both code (country
and country phone codes) to the phonenumbers API,
in order to make a correct verification.
2017-06-20 09:00:47 +02:00

31 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from odoo.addons.phone_validation.tools import phone_validation
class PhoneValidationMixin(models.AbstractModel):
_name = 'phone.validation.mixin'
def _phone_get_country(self):
if 'country_id' in self:
return self.country_id
return self.env.user.company_id.country_id
def _phone_get_always_international(self):
if 'company_id' in self:
return self.company_id.phone_international_format
return self.env.user.company_id.phone_international_format
def phone_format(self, number, country=None, company=None):
country = country or self._phone_get_country()
always_international = company.phone_international_format if company else self._phone_get_always_international()
return phone_validation.phone_format(
number,
country.code if country else None,
country.phone_code if country else None,
always_international=always_international,
raise_exception=True
)