hr module :new field added on user (parent user=>many2many) now you can put domain like : [('user_id', 'child_of', [uid])] if you want to open Departemnt tasks for current user and its child for example
bzr revid: mra@tinyerp.com-20090318104038-4kt32jemqov5dgdv
This commit is contained in:
parent
412e074980
commit
1c89d9fd13
|
@ -1,7 +1,7 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
|
@ -50,6 +50,7 @@ class hr_department(osv.osv):
|
|||
return False
|
||||
level -= 1
|
||||
return True
|
||||
|
||||
_constraints = [
|
||||
(_check_recursion, 'Error! You can not create recursive departments.', ['parent_id'])
|
||||
]
|
||||
|
@ -81,7 +82,50 @@ class ir_action_window(osv.osv):
|
|||
|
||||
ir_action_window()
|
||||
|
||||
class res_users(osv.osv):
|
||||
_inherit = 'res.users'
|
||||
_description = 'res.users'
|
||||
|
||||
def _parent_compute(self, cr, uid, ids, name, arg, context={}):
|
||||
result = {}
|
||||
obj_dept = self.pool.get('hr.department')
|
||||
for id in ids:
|
||||
ids_dept = obj_dept.search(cr, uid, [('member_ids', 'in', [id])])
|
||||
parent_ids = []
|
||||
if ids_dept:
|
||||
data_dept = obj_dept.read(cr, uid, ids_dept, ['manager_id'])
|
||||
parent_ids = map(lambda x: x['manager_id'][0], data_dept)
|
||||
result[id] = parent_ids
|
||||
return result
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
def _child_compute(self, cr, uid, ids):
|
||||
obj_dept = self.pool.get('hr.department')
|
||||
child_ids = []
|
||||
for id in ids:
|
||||
ids_dept = obj_dept.search(cr, uid, [('manager_id', '=', id)])
|
||||
if ids_dept:
|
||||
data_dept = obj_dept.read(cr, uid, ids_dept, ['member_ids'])
|
||||
childs = map(lambda x: x['member_ids'], data_dept)
|
||||
childs = tools.flatten(childs)
|
||||
if id in childs:
|
||||
childs.remove(id)
|
||||
child_ids.extend(tools.flatten(childs))
|
||||
return child_ids
|
||||
|
||||
def _parent_search(self, cr, uid, obj, name, args):
|
||||
parent = []
|
||||
for arg in args:
|
||||
if arg[0] == 'parent_id':
|
||||
parent = arg[2]
|
||||
child_ids = self._child_compute(cr, uid, parent)
|
||||
if not child_ids:
|
||||
return [('id', 'in', [0])]
|
||||
return [('id', 'in', child_ids)]
|
||||
|
||||
_columns = {
|
||||
'parent_id': fields.function(_parent_compute, relation='res.users',fnct_search=_parent_search, method=True, string="Parent Users", type='many2many'),
|
||||
}
|
||||
|
||||
res_users()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
<!--
|
||||
======================
|
||||
department
|
||||
|
@ -48,14 +48,29 @@
|
|||
<field name="domain">[('parent_id','=',False)]</field>
|
||||
</record>
|
||||
<menuitem action="open_module_tree_department_tree" id="menu_department_tree" parent="base.menu_users"/>
|
||||
|
||||
|
||||
<record id="open_module_tree_department" model="ir.actions.act_window">
|
||||
<field name="name">Departments</field>
|
||||
<field name="res_model">hr.department</field>
|
||||
<field name="view_type">form</field>
|
||||
</record>
|
||||
|
||||
|
||||
<menuitem action="open_module_tree_department" id="menu_department_def" parent="hr.menu_department_tree"/>
|
||||
|
||||
|
||||
<!-- res.users inherit -->
|
||||
<record model="ir.ui.view" id="view_users_form_inherit">
|
||||
<field name="name">res.users.form</field>
|
||||
<field name="type">form</field>
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base.view_users_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<notebook position="inside">
|
||||
<page string="Parents">
|
||||
<field name="parent_id" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue