[IMP] res_lang: don't allow unactivating of a used language

Unactivating the preferred language of a user will prevent him from
logging in.
This commit is contained in:
Joren Van Onder
2015-07-29 20:19:35 +02:00
committed by Antony Lesuisse
parent 60af9986ed
commit a0857f13eb
+11
View File
@@ -176,6 +176,17 @@ class lang(osv.osv):
return grouping, thousands_sep, decimal_point
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
if vals.get('active') == False:
users = self.pool.get('res.users')
for current_id in ids:
current_language = self.browse(cr, uid, current_id, context=context)
if users.search(cr, uid, [('lang', '=', current_language.code)], context=context):
raise UserError(_("Cannot unactivate a language that is currently used by users."))
self._lang_get.clear_cache(self)
self._lang_data_get.clear_cache(self)
return super(lang, self).write(cr, uid, ids, vals, context)