[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.
This commit is contained in:
@@ -61,7 +61,7 @@
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="module_crm_phone_validation"/>
|
||||
<div class="text-muted" id="module_crm_phone_validation">
|
||||
Validate and normalize phone numbers.
|
||||
Formats phone numbers
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -13,7 +13,6 @@ CRM Phone Numbers Validation
|
||||
This module allows for validate and format phone numbers for leads and contacts.""",
|
||||
'data': [
|
||||
'views/res_config_settings_views.xml',
|
||||
'views/crm_lead_views.xml'
|
||||
],
|
||||
'depends': [
|
||||
'phone_validation',
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="crm_lead_opportunity_view_form" model="ir.ui.view">
|
||||
<field name="name">crm.lead.form.opportunity.inherit.crm.phone.validation</field>
|
||||
<field name="model">crm.lead</field>
|
||||
<field name="inherit_id" ref="crm.crm_case_form_view_oppor" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='Misc']" position="inside">
|
||||
<field name="company_id" invisible="1"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -9,11 +9,12 @@ class PhoneValidationMixin(models.AbstractModel):
|
||||
_name = 'phone.validation.mixin'
|
||||
|
||||
def _phone_get_country(self):
|
||||
if 'country_id' in 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.country_id:
|
||||
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'
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
from odoo.addons.website_form.controllers.main import WebsiteForm
|
||||
from odoo.http import request, route
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class WebsiteForm(WebsiteForm):
|
||||
|
||||
@@ -32,17 +30,13 @@ class WebsiteForm(WebsiteForm):
|
||||
else:
|
||||
record = data.get('record', {})
|
||||
phone_fields = self._get_phone_fields_to_validate()
|
||||
country = self._get_country()
|
||||
invalid_fields = {}
|
||||
country = request.env['res.country'].browse(record.get('country_id'))
|
||||
contact_country = country.exists() and country or self._get_country()
|
||||
for phone_field in phone_fields:
|
||||
if not record.get(phone_field):
|
||||
continue
|
||||
number = record[phone_field]
|
||||
try:
|
||||
request.env[model_name].phone_format(number, country)
|
||||
except Exception as error:
|
||||
invalid_fields[phone_field] = error.args[0]
|
||||
if invalid_fields:
|
||||
return json.dumps({'error_fields': invalid_fields})
|
||||
fmt_number = request.env[model_name].phone_format(number, contact_country)
|
||||
request.params.update({phone_field: fmt_number})
|
||||
|
||||
return super(WebsiteForm, self).website_form(model_name, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user