[IMP] hr.department cleanup
- Consolidate multiple hr.departement definition into hr.py file - Remove ulgy department_users_get() domain hack on act_window - Add the jobs_ids inverse relationship from departement to jobs bzr revid: al@openerp.com-20140129002913-5qgq10jy9u3xn74e
This commit is contained in:
parent
802d64ca92
commit
da020d326d
|
@ -19,7 +19,6 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import hr_department
|
|
||||||
import hr
|
import hr
|
||||||
|
|
||||||
import res_config
|
import res_config
|
||||||
|
|
|
@ -54,7 +54,6 @@ You can manage:
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'board_hr_view.xml',
|
'board_hr_view.xml',
|
||||||
'hr_view.xml',
|
'hr_view.xml',
|
||||||
'hr_department_view.xml',
|
|
||||||
'process/hr_process.xml',
|
'process/hr_process.xml',
|
||||||
'hr_installer.xml',
|
'hr_installer.xml',
|
||||||
'hr_data.xml',
|
'hr_data.xml',
|
||||||
|
|
|
@ -330,13 +330,58 @@ class hr_employee(osv.osv):
|
||||||
|
|
||||||
|
|
||||||
class hr_department(osv.osv):
|
class hr_department(osv.osv):
|
||||||
_description = "Department"
|
|
||||||
_inherit = 'hr.department'
|
def _dept_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
|
||||||
|
res = self.name_get(cr, uid, ids, context=context)
|
||||||
|
return dict(res)
|
||||||
|
|
||||||
|
_name = "hr.department"
|
||||||
_columns = {
|
_columns = {
|
||||||
|
'name': fields.char('Department Name', size=64, required=True),
|
||||||
|
'complete_name': fields.function(_dept_name_get_fnc, type="char", string='Name'),
|
||||||
|
'company_id': fields.many2one('res.company', 'Company', select=True, required=False),
|
||||||
|
'parent_id': fields.many2one('hr.department', 'Parent Department', select=True),
|
||||||
|
'child_ids': fields.one2many('hr.department', 'parent_id', 'Child Departments'),
|
||||||
'manager_id': fields.many2one('hr.employee', 'Manager'),
|
'manager_id': fields.many2one('hr.employee', 'Manager'),
|
||||||
'member_ids': fields.one2many('hr.employee', 'department_id', 'Members', readonly=True),
|
'member_ids': fields.one2many('hr.employee', 'department_id', 'Members', readonly=True),
|
||||||
|
'jobs_ids': fields.one2many('hr.job', 'department_id', 'Jobs'),
|
||||||
|
'note': fields.text('Note'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_defaults = {
|
||||||
|
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr.department', context=c),
|
||||||
|
}
|
||||||
|
|
||||||
|
def _check_recursion(self, cr, uid, ids, context=None):
|
||||||
|
if context is None:
|
||||||
|
context = {}
|
||||||
|
level = 100
|
||||||
|
while len(ids):
|
||||||
|
cr.execute('select distinct parent_id from hr_department where id IN %s',(tuple(ids),))
|
||||||
|
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
|
||||||
|
if not level:
|
||||||
|
return False
|
||||||
|
level -= 1
|
||||||
|
return True
|
||||||
|
|
||||||
|
_constraints = [
|
||||||
|
(_check_recursion, 'Error! You cannot create recursive departments.', ['parent_id'])
|
||||||
|
]
|
||||||
|
|
||||||
|
def name_get(self, cr, uid, ids, context=None):
|
||||||
|
if context is None:
|
||||||
|
context = {}
|
||||||
|
if not ids:
|
||||||
|
return []
|
||||||
|
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
|
||||||
|
res = []
|
||||||
|
for record in reads:
|
||||||
|
name = record['name']
|
||||||
|
if record['parent_id']:
|
||||||
|
name = record['parent_id'][1]+' / '+name
|
||||||
|
res.append((record['id'], name))
|
||||||
|
return res
|
||||||
|
|
||||||
def copy(self, cr, uid, ids, default=None, context=None):
|
def copy(self, cr, uid, ids, default=None, context=None):
|
||||||
if default is None:
|
if default is None:
|
||||||
default = {}
|
default = {}
|
||||||
|
@ -344,6 +389,7 @@ class hr_department(osv.osv):
|
||||||
default['member_ids'] = []
|
default['member_ids'] = []
|
||||||
return super(hr_department, self).copy(cr, uid, ids, default, context=context)
|
return super(hr_department, self).copy(cr, uid, ids, default, context=context)
|
||||||
|
|
||||||
|
|
||||||
class res_users(osv.osv):
|
class res_users(osv.osv):
|
||||||
_name = 'res.users'
|
_name = 'res.users'
|
||||||
_inherit = 'res.users'
|
_inherit = 'res.users'
|
||||||
|
@ -353,5 +399,4 @@ class res_users(osv.osv):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -1,107 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# OpenERP, Open Source Management Solution
|
|
||||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
from openerp.osv import fields, osv
|
|
||||||
from openerp import tools
|
|
||||||
|
|
||||||
class hr_department(osv.osv):
|
|
||||||
def name_get(self, cr, uid, ids, context=None):
|
|
||||||
if context is None:
|
|
||||||
context = {}
|
|
||||||
if not ids:
|
|
||||||
return []
|
|
||||||
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
|
|
||||||
res = []
|
|
||||||
for record in reads:
|
|
||||||
name = record['name']
|
|
||||||
if record['parent_id']:
|
|
||||||
name = record['parent_id'][1]+' / '+name
|
|
||||||
res.append((record['id'], name))
|
|
||||||
return res
|
|
||||||
|
|
||||||
def _dept_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
|
|
||||||
res = self.name_get(cr, uid, ids, context=context)
|
|
||||||
return dict(res)
|
|
||||||
|
|
||||||
_name = "hr.department"
|
|
||||||
_columns = {
|
|
||||||
'name': fields.char('Department Name', size=64, required=True),
|
|
||||||
'complete_name': fields.function(_dept_name_get_fnc, type="char", string='Name'),
|
|
||||||
'company_id': fields.many2one('res.company', 'Company', select=True, required=False),
|
|
||||||
'parent_id': fields.many2one('hr.department', 'Parent Department', select=True),
|
|
||||||
'child_ids': fields.one2many('hr.department', 'parent_id', 'Child Departments'),
|
|
||||||
'note': fields.text('Note'),
|
|
||||||
}
|
|
||||||
|
|
||||||
_defaults = {
|
|
||||||
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr.department', context=c),
|
|
||||||
}
|
|
||||||
|
|
||||||
def _get_members(self, cr, uid, context=None):
|
|
||||||
mids = self.search(cr, uid, [('manager_id', '=', uid)], context=context)
|
|
||||||
result = {uid: 1}
|
|
||||||
for m in self.browse(cr, uid, mids, context=context):
|
|
||||||
for user in m.member_ids:
|
|
||||||
result[user.id] = 1
|
|
||||||
return result.keys()
|
|
||||||
|
|
||||||
def _check_recursion(self, cr, uid, ids, context=None):
|
|
||||||
if context is None:
|
|
||||||
context = {}
|
|
||||||
level = 100
|
|
||||||
while len(ids):
|
|
||||||
cr.execute('select distinct parent_id from hr_department where id IN %s',(tuple(ids),))
|
|
||||||
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
|
|
||||||
if not level:
|
|
||||||
return False
|
|
||||||
level -= 1
|
|
||||||
return True
|
|
||||||
|
|
||||||
_constraints = [
|
|
||||||
(_check_recursion, 'Error! You cannot create recursive departments.', ['parent_id'])
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class ir_action_window(osv.osv):
|
|
||||||
_inherit = 'ir.actions.act_window'
|
|
||||||
|
|
||||||
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
|
|
||||||
if context is None:
|
|
||||||
context = {}
|
|
||||||
obj_dept = self.pool.get('hr.department')
|
|
||||||
select = ids
|
|
||||||
if isinstance(ids, (int, long)):
|
|
||||||
select = [ids]
|
|
||||||
res = super(ir_action_window, self).read(cr, uid, select, fields=fields, context=context, load=load)
|
|
||||||
for r in res:
|
|
||||||
mystring = 'department_users_get()'
|
|
||||||
if mystring in (r.get('domain', '[]') or ''):
|
|
||||||
r['domain'] = r['domain'].replace(mystring, str(obj_dept._get_members(cr, uid)))
|
|
||||||
if isinstance(ids, (int, long)):
|
|
||||||
if res:
|
|
||||||
return res[0]
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
@ -1,64 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<openerp>
|
|
||||||
<data>
|
|
||||||
|
|
||||||
<!-- Department -->
|
|
||||||
<record id="view_department_form" model="ir.ui.view">
|
|
||||||
<field name="name">hr.department.form</field>
|
|
||||||
<field name="model">hr.department</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<form string="department" version="7.0">
|
|
||||||
<sheet>
|
|
||||||
<group col="4">
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="manager_id"/>
|
|
||||||
<field name="parent_id"/>
|
|
||||||
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
|
||||||
</group>
|
|
||||||
</sheet>
|
|
||||||
</form>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
<record id="view_department_tree" model="ir.ui.view">
|
|
||||||
<field name="name">hr.department.tree</field>
|
|
||||||
<field name="model">hr.department</field>
|
|
||||||
<field name="field_parent">child_ids</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<tree string="Companies">
|
|
||||||
<field name="complete_name"/>
|
|
||||||
<field name="company_id" groups="base.group_multi_company"/>
|
|
||||||
<field name="manager_id"/>
|
|
||||||
</tree>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
<record id="view_department_filter" model="ir.ui.view">
|
|
||||||
<field name="name">Departments</field>
|
|
||||||
<field name="model">hr.department</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<search string="Departments">
|
|
||||||
<field name="name" string="Department"/>
|
|
||||||
<field name="manager_id" />
|
|
||||||
</search>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<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>
|
|
||||||
<field name="search_view_id" ref="view_department_filter"/>
|
|
||||||
<field name="help" type="html">
|
|
||||||
<p class="oe_view_nocontent_create">
|
|
||||||
Click to create a department.
|
|
||||||
</p><p>
|
|
||||||
OpenERP's department structure is used to manage all documents
|
|
||||||
related to employees by departments: expenses, timesheets,
|
|
||||||
leaves and holidays, recruitments, etc.
|
|
||||||
</p>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<menuitem action="open_module_tree_department" id="menu_hr_department_tree" parent="hr.menu_hr_configuration" sequence="5"/>
|
|
||||||
|
|
||||||
</data>
|
|
||||||
</openerp>
|
|
|
@ -326,6 +326,7 @@
|
||||||
<field eval="'ir.actions.act_window,%d'%hr_employee_normal_action_tree" name="value"/>
|
<field eval="'ir.actions.act_window,%d'%hr_employee_normal_action_tree" name="value"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<!-- hr.job -->
|
||||||
<record id="view_hr_job_form" model="ir.ui.view">
|
<record id="view_hr_job_form" model="ir.ui.view">
|
||||||
<field name="name">hr.job.form</field>
|
<field name="name">hr.job.form</field>
|
||||||
<field name="model">hr.job</field>
|
<field name="model">hr.job</field>
|
||||||
|
@ -442,5 +443,61 @@
|
||||||
<menuitem name="Recruitment" id="base.menu_crm_case_job_req_main" parent="menu_hr_root" groups="base.group_hr_user"/>
|
<menuitem name="Recruitment" id="base.menu_crm_case_job_req_main" parent="menu_hr_root" groups="base.group_hr_user"/>
|
||||||
<menuitem parent="hr.menu_hr_configuration" id="menu_hr_job" action="action_hr_job" sequence="6"/>
|
<menuitem parent="hr.menu_hr_configuration" id="menu_hr_job" action="action_hr_job" sequence="6"/>
|
||||||
|
|
||||||
|
<!-- hr.department -->
|
||||||
|
<record id="view_department_form" model="ir.ui.view">
|
||||||
|
<field name="name">hr.department.form</field>
|
||||||
|
<field name="model">hr.department</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="department" version="7.0">
|
||||||
|
<sheet>
|
||||||
|
<group col="4">
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="manager_id"/>
|
||||||
|
<field name="parent_id"/>
|
||||||
|
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||||
|
</group>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<record id="view_department_tree" model="ir.ui.view">
|
||||||
|
<field name="name">hr.department.tree</field>
|
||||||
|
<field name="model">hr.department</field>
|
||||||
|
<field name="field_parent">child_ids</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="Companies">
|
||||||
|
<field name="complete_name"/>
|
||||||
|
<field name="company_id" groups="base.group_multi_company"/>
|
||||||
|
<field name="manager_id"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<record id="view_department_filter" model="ir.ui.view">
|
||||||
|
<field name="name">Departments</field>
|
||||||
|
<field name="model">hr.department</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<search string="Departments">
|
||||||
|
<field name="name" string="Department"/>
|
||||||
|
<field name="manager_id" />
|
||||||
|
</search>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<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>
|
||||||
|
<field name="search_view_id" ref="view_department_filter"/>
|
||||||
|
<field name="help" type="html">
|
||||||
|
<p class="oe_view_nocontent_create">
|
||||||
|
Click to create a department.
|
||||||
|
</p><p>
|
||||||
|
OpenERP's department structure is used to manage all documents
|
||||||
|
related to employees by departments: expenses, timesheets,
|
||||||
|
leaves and holidays, recruitments, etc.
|
||||||
|
</p>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<menuitem action="open_module_tree_department" id="menu_hr_department_tree" parent="hr.menu_hr_configuration" sequence="5"/>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
||||||
|
|
Loading…
Reference in New Issue