From dc771b1a5c1995f6a64807101a24ff961c082854 Mon Sep 17 00:00:00 2001
From: jvm-odoo <jvm@odoo.com>
Date: Mon, 25 Nov 2019 14:18:27 +0000
Subject: [PATCH] [FIX] http_routing: fix context language used when not
 available

A customer reported a problem when he deleted a language on the
website app.

In some cases, if you go on the odoo's generated website as a public
user let's imagine the following url: website.com/en_GB

The lang is saved in a cookie and sent to the context.

If you delete the language from the website languages (without
deactivating it) and you go on website.com as a public user,
the method will try to use the context or the cookie value which is
'en_GB' and it crashes.

This commit makes sure that the language is available

OPW-2129580

closes odoo/odoo#41007

X-original-commit: f3e9ca13f60ced0ec61cea0d13da45b2569da14e
Signed-off-by: Jason Van Malder <jasonvanmalder@users.noreply.github.com>
---
 addons/http_routing/models/ir_http.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py
index 6621b0a58bc9..6f1078a49958 100644
--- a/addons/http_routing/models/ir_http.py
+++ b/addons/http_routing/models/ir_http.py
@@ -391,8 +391,9 @@ class IrHttp(models.AbstractModel):
                 lang = Lang._lang_get(nearest_lang)
             else:
                 nearest_ctx_lg = not is_a_bot and cls.get_nearest_lang(request.env.context['lang'])
-                preferred_lang = Lang._lang_get(cook_lang or nearest_ctx_lg) or cls._get_default_lang()
-                lang = preferred_lang
+                nearest_ctx_lg = nearest_ctx_lg in lang_codes and nearest_ctx_lg
+                preferred_lang = Lang._lang_get(cook_lang or nearest_ctx_lg)
+                lang = preferred_lang or cls._get_default_lang()
 
             request.lang = lang
             context['lang'] = lang.code
-- 
GitLab