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):