1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 from osv import fields,osv
26 class hr_department(osv.osv):
27 _name = "hr.department"
29 'name': fields.char('Department Name', size=64, required=True),
30 'company_id': fields.many2one('res.company', 'Company', select=True, required=True),
31 'parent_id': fields.many2one('hr.department', 'Parent Department', select=True),
32 'child_ids': fields.one2many('hr.department', 'parent_id', 'Childs Departments'),
33 'note': fields.text('Note'),
34 'manager_id': fields.many2one('res.users', 'Manager', required=True),
35 'member_ids': fields.many2many('res.users', 'hr_department_user_rel', 'department_id', 'user_id', 'Members'),
37 def _get_members(self,cr, uid, context={}):
38 mids = self.search(cr, uid, [('manager_id','=',uid)])
40 for m in self.browse(cr, uid, mids, context):
41 for user in m.member_ids:
44 def _check_recursion(self, cr, uid, ids):
47 cr.execute('select distinct parent_id from hr_department where id in ('+','.join(map(str,ids))+')')
48 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
54 (_check_recursion, 'Error! You can not create recursive departments.', ['parent_id'])
60 class ir_action_window(osv.osv):
61 _inherit = 'ir.actions.act_window'
63 def read(self, cr, uid, ids, fields=None, context=None,
64 load='_classic_read'):
66 if isinstance(ids, (int, long)):
68 res = super(ir_action_window, self).read(cr, uid, select, fields=fields,
69 context=context, load=load)
71 mystring = 'department_users_get()'
72 if mystring in (r.get('domain', '[]') or ''):
73 r['domain'] = r['domain'].replace(mystring, str(
74 self.pool.get('hr.department')._get_members(cr, uid)))
75 if isinstance(ids, (int, long)):
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: