blob: 3c8ee9dcb520815e7f776d641625d23caa11007b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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()
|