1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO Consulting, MSF
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
from osv import fields
25
from tools.translate import _
28
class lang_setup(osv.osv_memory):
30
_inherit = 'res.config'
33
'lang_id': fields.many2one('res.lang', string='Language', required=True),
36
def default_get(self, cr, uid, fields, context=None):
38
Display the default value for system language
40
setup_id = self.pool.get('unifield.setup.configuration').get_config(cr, uid)
41
res = super(lang_setup, self).default_get(cr, uid, fields, context=context)
43
lang_ids = self.pool.get('res.lang').search(cr, uid, [('code', '=', setup_id.lang_id)], context=context)
45
res['lang_id'] = lang_ids[0]
47
res['lang_id'] = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'lang_en')[1]
52
def execute(self, cr, uid, ids, context=None):
54
Fill the default lang on the configuration and for the current user
56
assert len(ids) == 1, "We should only get one object from the form"
57
payload = self.browse(cr, uid, ids[0], context=context)
59
setup_obj = self.pool.get('unifield.setup.configuration')
60
user_obj = self.pool.get('res.users')
62
setup_id = setup_obj.get_config(cr, uid)
65
user_obj.write(cr, uid, uid, {'context_lang': payload.lang_id.code}, context=context)
67
setup_obj.write(cr, uid, [setup_id.id], {'lang_id': payload.lang_id.code}, context=context)
72
class config_users(osv.osv):
73
_name = 'res.config.users'
74
_inherit = 'res.config.users'
76
def default_get(self, cr, uid, fields, context=False):
78
If no lang defined, get this of the configuration setup
80
setup_id = self.pool.get('unifield.setup.configuration').get_config(cr, uid)
82
res = super(config_users, self).default_get(cr, uid, fields, context=context)
85
res['context_lang'] = 'en_MF'
87
res['context_lang'] = setup_id.lang_id
b'\\ No newline at end of file'