From b4ba1ccb1382e402f333a155c4fbda35a360ca64 Mon Sep 17 00:00:00 2001 From: "jerome hanke (jhk)" Date: Thu, 9 Apr 2020 13:03:22 +0000 Subject: [PATCH] [FIX] website_crm: state_id=false not shown in lead description Steps to reproduce: - install website, crm - go to crm > settings > activate leads - add a contact form to your website and submit - go to the created lead Previous behavior: state_id is shown as false when geoip data is empty Current behavior: state_id is not shown if geoip is if the state found in geoip does not not exist on the Odoo instance opw-2218498 closes odoo/odoo#50055 X-original-commit: eba0eafac78adb498f8062f3490cea0847ed7927 Signed-off-by: mightyjol --- addons/website_crm/controllers/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/website_crm/controllers/main.py b/addons/website_crm/controllers/main.py index 2347d4aa838..33687e221fc 100644 --- a/addons/website_crm/controllers/main.py +++ b/addons/website_crm/controllers/main.py @@ -43,9 +43,9 @@ class WebsiteForm(WebsiteForm): 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 - + state = request.env['res.country.state'].search([('code', '=', geoip_state_code), ('country_id.code', '=', geoip_country_code)]) + if state: + request.params['state_id'] = state.id return super(WebsiteForm, self).website_form(model_name, **kwargs) def insert_record(self, request, model, values, custom, meta=None):