From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/website/models/res_lang.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 addons/website/models/res_lang.py (limited to 'addons/website/models/res_lang.py') diff --git a/addons/website/models/res_lang.py b/addons/website/models/res_lang.py new file mode 100644 index 00000000..3c8ee9dc --- /dev/null +++ b/addons/website/models/res_lang.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models, tools, _ +from odoo.addons.website.models import ir_http +from odoo.exceptions import UserError +from odoo.http import request + + +class Lang(models.Model): + _inherit = "res.lang" + + def write(self, vals): + if 'active' in vals and not vals['active']: + if self.env['website'].search([('language_ids', 'in', self._ids)]): + raise UserError(_("Cannot deactivate a language that is currently used on a website.")) + return super(Lang, self).write(vals) + + @api.model + @tools.ormcache_context(keys=("website_id",)) + def get_available(self): + website = ir_http.get_request_website() + if not website: + return super().get_available() + # Return the website-available ones in this case + return request.website.language_ids.get_sorted() -- cgit v1.2.3