From 20fb024a33b3ceed2a1a41f65a315477699378de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 10 Jul 2019 11:01:18 +0000 Subject: [PATCH] [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) --- addons/website_crm/__manifest__.py | 10 +++-- addons/website_crm/controllers/main.py | 31 +++++++++++++- .../website_crm_phone_validation/__init__.py | 4 -- .../__manifest__.py | 22 ---------- .../controllers/__init__.py | 4 -- .../controllers/website_form.py | 42 ------------------- 6 files changed, 37 insertions(+), 76 deletions(-) delete mode 100644 addons/website_crm_phone_validation/__init__.py delete mode 100644 addons/website_crm_phone_validation/__manifest__.py delete mode 100644 addons/website_crm_phone_validation/controllers/__init__.py delete mode 100644 addons/website_crm_phone_validation/controllers/website_form.py diff --git a/addons/website_crm/__manifest__.py b/addons/website_crm/__manifest__.py index c378953e9cb..01be0b6f77e 100644 --- a/addons/website_crm/__manifest__.py +++ b/addons/website_crm/__manifest__.py @@ -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', diff --git a/addons/website_crm/controllers/main.py b/addons/website_crm/controllers/main.py index 79cfacc8dde..7671ac7f7da 100644 --- a/addons/website_crm/controllers/main.py +++ b/addons/website_crm/controllers/main.py @@ -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 + 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 + validation phone fields @http.route('/website_form/', 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') diff --git a/addons/website_crm_phone_validation/__init__.py b/addons/website_crm_phone_validation/__init__.py deleted file mode 100644 index dd15b5c32e5..00000000000 --- a/addons/website_crm_phone_validation/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import controllers diff --git a/addons/website_crm_phone_validation/__manifest__.py b/addons/website_crm_phone_validation/__manifest__.py deleted file mode 100644 index 4d3e884efcd..00000000000 --- a/addons/website_crm_phone_validation/__manifest__.py +++ /dev/null @@ -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, -} diff --git a/addons/website_crm_phone_validation/controllers/__init__.py b/addons/website_crm_phone_validation/controllers/__init__.py deleted file mode 100644 index 25803fb1887..00000000000 --- a/addons/website_crm_phone_validation/controllers/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from . import website_form diff --git a/addons/website_crm_phone_validation/controllers/website_form.py b/addons/website_crm_phone_validation/controllers/website_form.py deleted file mode 100644 index c404bb87724..00000000000 --- a/addons/website_crm_phone_validation/controllers/website_form.py +++ /dev/null @@ -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/', 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)