diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-07-10 11:01:18 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-07-15 08:29:50 +0000 |
| commit | 20fb024a33b3ceed2a1a41f65a315477699378de (patch) | |
| tree | 46816fa66272c9d51e8dbfd40f3e3ca40b8f398e /addons/website_crm/controllers | |
| parent | 35b600cd37b1204b4e7d9c57e1e69b3ec06d75b5 (diff) | |
[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>
Diffstat (limited to 'addons/website_crm/controllers')
| -rw-r--r-- | addons/website_crm/controllers/main.py | 31 |
1 files changed, 30 insertions, 1 deletions
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 <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') |
