summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Rahir <rar@odoo.com>2018-02-09 15:24:54 +0100
committerRémi Rahir <rar@odoo.com>2018-02-12 09:16:17 +0100
commit8b9bcf1b7efff6423763f69aad171c7c98dce5bc (patch)
tree601d8b39d888b1559cf2683eaa366f3d8d9778b9
parent26468bfaba1dacd05e9bdc534c98fbcc4076eae4 (diff)
[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.
-rw-r--r--addons/crm/views/res_config_settings_views.xml2
-rw-r--r--addons/crm_phone_validation/__manifest__.py1
-rw-r--r--addons/crm_phone_validation/views/crm_lead_views.xml13
-rw-r--r--addons/phone_validation/models/phone_validation_mixin.py5
-rw-r--r--addons/website_crm_phone_validation/controllers/website_form.py14
5 files changed, 8 insertions, 27 deletions
diff --git a/addons/crm/views/res_config_settings_views.xml b/addons/crm/views/res_config_settings_views.xml
index e06b7c9f7ec..43c7207d5d1 100644
--- a/addons/crm/views/res_config_settings_views.xml
+++ b/addons/crm/views/res_config_settings_views.xml
@@ -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>
diff --git a/addons/crm_phone_validation/__manifest__.py b/addons/crm_phone_validation/__manifest__.py
index 72a21dbfcfa..7c729bfae3e 100644
--- a/addons/crm_phone_validation/__manifest__.py
+++ b/addons/crm_phone_validation/__manifest__.py
@@ -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',
diff --git a/addons/crm_phone_validation/views/crm_lead_views.xml b/addons/crm_phone_validation/views/crm_lead_views.xml
deleted file mode 100644
index bcf1840bd7a..00000000000
--- a/addons/crm_phone_validation/views/crm_lead_views.xml
+++ /dev/null
@@ -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>
diff --git a/addons/phone_validation/models/phone_validation_mixin.py b/addons/phone_validation/models/phone_validation_mixin.py
index 4cd9d8eb2bb..02e4c6aa82a 100644
--- a/addons/phone_validation/models/phone_validation_mixin.py
+++ b/addons/phone_validation/models/phone_validation_mixin.py
@@ -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'
diff --git a/addons/website_crm_phone_validation/controllers/website_form.py b/addons/website_crm_phone_validation/controllers/website_form.py
index 3713fe86f9e..c404bb87724 100644
--- a/addons/website_crm_phone_validation/controllers/website_form.py
+++ b/addons/website_crm_phone_validation/controllers/website_form.py
@@ -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)