1 ##############################################################################
3 # Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 # Fabien Pinckaers <fp@tiny.Be>
6 # WARNING: This program as such is intended to be used by professional
7 # programmers who take the whole responsability of assessing all potential
8 # consequences resulting from its eventual inadequacies and bugs
9 # End users who are looking for a ready-to-use solution with commercial
10 # garantees and support are strongly adviced to contract a Free Software
13 # This program is Free Software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ##############################################################################
29 from osv import fields,osv
32 class groups(osv.osv):
35 'name': fields.char('Group Name', size=64, required=True),
36 'model_access': fields.one2many('ir.model.access', 'group_id', 'Access Controls'),
37 'rule_groups': fields.many2many('ir.rule.group', 'group_rule_group_rel', 'group_id', 'rule_group_id', 'Rules', domain="[('global', '<>', True)]"),
39 def write(self, cr, uid, *args, **argv):
40 res = super(groups, self).write(cr, uid, *args, **argv)
41 # Restart the cache on the company_get method
42 self.pool.get('ir.rule').domain_get()
50 'name': fields.char('Role Name', size=64, required=True),
51 'parent_id': fields.many2one('res.roles', 'Parent', select=True),
52 'child_id': fields.one2many('res.roles', 'parent_id', 'Childs')
56 def check(self, cr, uid, ids, role_id):
59 cr.execute('select parent_id from res_roles where id=%d', (role_id,))
60 roles = cr.fetchone()[0]
62 return self.check(cr, uid, ids, roles)
69 'name': fields.char('Name', size=64, required=True),
70 'code': fields.char('Code', size=5, required=True),
71 'translatable': fields.boolean('Translatable'),
72 'active': fields.boolean('Active'),
73 'direction': fields.selection([('ltr', 'Left-to-right'), ('rtl', 'Right-to-left')], 'Direction',resuired=True),
76 'active': lambda *a: 1,
77 'translatable': lambda *a: 0,
78 'direction': lambda *a: 'ltr',
86 'name': fields.char('Name', size=64, required=True, select=True),
87 'login': fields.char('Login', size=64, required=True),
88 'password': fields.char('Password', size=64, invisible=True),
89 'signature': fields.text('Signature', size=64),
90 'address_id': fields.many2one('res.partner.address', 'Address'),
91 'active': fields.boolean('Active'),
92 'action_id': fields.many2one('ir.actions.actions', 'Home Action'),
93 'menu_id': fields.many2one('ir.actions.actions', 'Menu Action'),
94 'groups_id': fields.many2many('res.groups', 'res_groups_users_rel', 'uid', 'gid', 'Groups'),
95 'roles_id': fields.many2many('res.roles', 'res_roles_users_rel', 'uid', 'rid', 'Roles'),
96 'company_id': fields.many2one('res.company', 'Company'),
97 'rule_groups': fields.many2many('ir.rule.group', 'user_rule_group_rel', 'user_id', 'rule_group_id', 'Rules', domain="[('global', '<>', True)]"),
100 ('login_key', 'UNIQUE (login)', 'You can not have two users with the same login !')
103 'password' : lambda obj,cr,uid,context={} : '',
104 'active' : lambda obj,cr,uid,context={} : True,
106 def company_get(self, cr, uid, uid2):
107 company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
109 company_get = tools.cache()(company_get)
111 def write(self, cr, uid, *args, **argv):
112 res = super(users, self).write(cr, uid, *args, **argv)
114 # Restart the cache on the company_get method
115 self.pool.get('ir.rule').domain_get()
118 def unlink(self, cr, uid, ids):
120 raise osv.except_osv('Can not remove root user !', 'You can not remove the root user as it is used internally for resources created by Tiny ERP (updates, module installation, ...)')
121 return super(users, self).unlink(cr, uid, ids)
123 def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=80):
128 ids = self.search(cr, user, [('login','=',name)]+ args, limit=limit)
130 ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit)
131 return self.name_get(cr, user, ids)
133 def copy(self, cr, uid, id, default=None, context={}):
134 login = self.read(cr, uid, [id], ['login'])[0]['login']
135 default.update({'login': login+' (copy)'})
136 return super(users, self).copy(cr, uid, id, default, context)
139 class groups2(osv.osv):
140 _inherit = 'res.groups'
142 'users': fields.many2many('res.users', 'res_groups_users_rel', 'gid', 'uid', 'Users'),