Files
odoo_source/addons/phone_validation/models/phone_validation_mixin.py
T
Rémi Rahir 8b9bcf1b7e [FIX] crm_phone_validation: fix lead phone validation
Fixes country_id and company_id mismatch in 65832dc.

Removes the view added by said commit as it was not a true stable
fix since it required users to update the module.

This commit uses a workaround to get the missing company_id field
which is monkey-patching the fields_view_get of the model, as
suggested by rco.

This commit also removes the exception catches that were rendered
useless by the False value given to the raise_exception parameter
of phone_format, introduced in 65832dc as well.

This commits fixes the behaviour in the website form as the phone
numbers were sanitized but never saved as such on their record.

This commit also renames the Phone Validation config setting to
suit its true functionality.
2018-02-12 09:16:17 +01:00

33 lines
1.2 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 and self.country_id:
return self.country_id
return self.env.user.company_id.country_id
def _phone_get_always_international(self):
if 'company_id' in self and self.company_id:
return self.company_id.phone_international_format == 'prefix'
return self.env.user.company_id.phone_international_format == 'prefix'
def phone_format(self, number, country=None, company=None):
country = country or self._phone_get_country()
if not country:
return number
always_international = company.phone_international_format == 'prefix' 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=False
)