diff options
| author | rde <rde@odoo.com> | 2017-10-24 15:17:44 +0200 |
|---|---|---|
| committer | Romain Derie <rde@odoo.com> | 2017-11-14 15:10:45 +0100 |
| commit | a9e3116cf2de527689c81381c7b38042990a4a3f (patch) | |
| tree | fd480e586a76cc6fbe8f263e78cf898486128fc4 | |
| parent | 66a82fd4e4a041e2d983184ddc3b4059e9fccc07 (diff) | |
[IMP] website_form: add state code to the created lead
Before this commit, when you had a lead coming from your website form, you
had no informations from where it was located.
It was especially painful for USA which should add customer their location to
know their timezone and know at which time they could call him.
Now, the state code is added to the created lead. It is easy to figure what
timezone the user is on without contacting him first to ask.
This closes #20424
task-29784
| -rw-r--r-- | addons/website_crm/__init__.py | 1 | ||||
| -rw-r--r-- | addons/website_crm/controllers/__init__.py | 4 | ||||
| -rw-r--r-- | addons/website_crm/controllers/main.py | 20 |
3 files changed, 25 insertions, 0 deletions
diff --git a/addons/website_crm/__init__.py b/addons/website_crm/__init__.py index dc5e6b693d1..7d34c7c054a 100644 --- a/addons/website_crm/__init__.py +++ b/addons/website_crm/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import controllers from . import models diff --git a/addons/website_crm/controllers/__init__.py b/addons/website_crm/controllers/__init__.py new file mode 100644 index 00000000000..5d4b25db9c0 --- /dev/null +++ b/addons/website_crm/controllers/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import main diff --git a/addons/website_crm/controllers/main.py b/addons/website_crm/controllers/main.py new file mode 100644 index 00000000000..ab47aaae9b1 --- /dev/null +++ b/addons/website_crm/controllers/main.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +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> + @http.route('/website_form/<string:model_name>', type='http', auth="public", methods=['POST'], website=True) + def website_form(self, model_name, **kwargs): + 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') + if geoip_country_code and geoip_state_code: + State = request.env['res.country.state'] + request.params['state_id'] = State.search([('code', '=', geoip_state_code), ('country_id.code', '=', geoip_country_code)]).id + + return super(WebsiteForm, self).website_form(model_name, **kwargs) |
