[REF] website_crm: include website_crm_phone_validation

Website crm phone validation does not hold code that cannot be located in
website_crm as dependencies are now the same. Let us merge those two
modules !

Linked to task 2033777

closes odoo/odoo#34744

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Thibault Delavallée
2019-07-15 08:29:50 +00:00
parent 35b600cd37
commit 20fb024a33
6 changed files with 37 additions and 76 deletions
+7 -3
View File
@@ -1,12 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Contact Form',
'category': 'Website',
'sequence': 54,
'summary': 'Generate leads from a contact form',
'version': '2.0',
'version': '2.1',
'description': """
Generate leads or opportunities in the CRM app from a contact form published on the Contact us page of your website. This form can be customized thanks to the *Form Builder* module (available in Odoo Enterprise).
""",
Generate leads or opportunities in the CRM app from a contact form published on the Contact us page of your website.
This form can be customized thanks to the *Form Builder* module (available in Odoo Enterprise).
This module includes contact phone and mobile numbers validation.""",
'depends': ['website_form', 'crm'],
'data': [
'data/website_crm_data.xml',
+30 -1
View File
@@ -5,11 +5,40 @@ from odoo import http
from odoo.http import request
from odoo.addons.website_form.controllers.main import WebsiteForm
class WebsiteForm(WebsiteForm):
# Check and insert values from the form on the model <model>
def _get_country(self):
country_code = request.session.geoip and request.session.geoip.get('country_code') or False
if country_code:
return request.env['res.country'].sudo().search([('code', '=', country_code)], limit=1)
return request.env['res.country']
def _get_phone_fields_to_validate(self):
return ['phone', 'mobile']
# Check and insert values from the form on the model <model> + validation phone fields
@http.route('/website_form/<string:model_name>', type='http', auth="public", methods=['POST'], website=True)
def website_form(self, model_name, **kwargs):
model_record = request.env['ir.model'].sudo().search([('model', '=', model_name), ('website_form_access', '=', True)])
if model_record and hasattr(request.env[model_name], 'phone_format'):
try:
data = self.extract_data(model_record, request.params)
except:
# no specific management, super will do it
pass
else:
record = data.get('record', {})
phone_fields = self._get_phone_fields_to_validate()
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]
fmt_number = request.env[model_name].phone_format(number, contact_country)
request.params.update({phone_field: fmt_number})
if model_name == 'crm.lead' and not request.params.get('state_id'):
geoip_country_code = request.session.get('geoip', {}).get('country_code')
geoip_state_code = request.session.get('geoip', {}).get('region')
@@ -1,4 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import controllers
@@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Contact Form Number Validation',
'summary': 'Validate and format contact form numbers',
'sequence': '9999',
'category': 'Hidden',
'description': """
Contact Number Validation on Website
====================================
Validate contact (phone,mobile) numbers and normalize them on leads and contacts:
- use the national format for your company country
- use the international format for all others
""",
'data': [],
'depends': [
'website_crm',
'website_form',
],
'auto_install': True,
}
@@ -1,4 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import website_form
@@ -1,42 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.website_form.controllers.main import WebsiteForm
from odoo.http import request, route
class WebsiteForm(WebsiteForm):
def _get_country(self):
country_code = request.session.geoip and request.session.geoip.get('country_code') or False
if country_code:
return request.env['res.country'].sudo().search([('code', '=', country_code)], limit=1)
return request.env['res.country']
def _get_phone_fields_to_validate(self):
return ['phone', 'mobile']
@route('/website_form/<string:model_name>', type='http', auth="public", methods=['POST'], website=True)
def website_form(self, model_name, **kwargs):
model_record = request.env['ir.model'].sudo().search([('model', '=', model_name), ('website_form_access', '=', True)])
if not model_record or not hasattr(request.env[model_name], 'phone_format'):
return super(WebsiteForm, self).website_form(model_name, **kwargs)
try:
data = self.extract_data(model_record, request.params)
except:
# no specific management, super will do it
pass
else:
record = data.get('record', {})
phone_fields = self._get_phone_fields_to_validate()
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]
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)