diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website/models/res_lang.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website/models/res_lang.py')
| -rw-r--r-- | addons/website/models/res_lang.py | 26 |
1 files changed, 26 insertions, 0 deletions
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() |
