[IMP] hr and its related modules improvements

bzr revid: mra@mra-laptop-20100721123948-r2fi24sbelnfk7pr
This commit is contained in:
PSI (Openerp) 2010-07-21 18:09:48 +05:30 committed by Mustufa Rangwala
parent 224319dd51
commit 9c0ae10d6a
14 changed files with 191 additions and 94 deletions

View File

@ -48,9 +48,9 @@
],
'demo_xml': [
'hr_demo.xml',
'hr_department_demo.xml'
],
'test': ['test/test_hr.yml'],
'hr_department_demo.xml',
],
'test': ['test/test_hr.yml'],
'installable': True,
'active': False,
'certificate': '0086710558965',

View File

@ -78,7 +78,7 @@ class hr_job(osv.osv):
'requirements': fields.text('Requirements'),
'department_id': fields.many2one('hr.department', 'Department'),
'company_id': fields.many2one('res.company', 'Company'),
'state': fields.selection([('open', 'Open'),('old', 'Old'),('recruit', 'In Recruitement')], 'State', required=True),
'state': fields.selection([('open', 'Open'),('old', 'Old'),('recruit', 'In Recruitement')], 'State', readonly=True, required=True),
}
_defaults = {
'expected_employees': 1,
@ -86,6 +86,18 @@ class hr_job(osv.osv):
'state': 'open'
}
def job_old(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state': 'old'})
return True
def job_recruitement(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state': 'recruit'})
return True
def job_open(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state': 'open'})
return True
hr_job()
class hr_employee(osv.osv):
@ -102,7 +114,7 @@ class hr_employee(osv.osv):
'marital': fields.many2one('hr.employee.marital.status', 'Marital Status'),
'bank_account': fields.char('Bank Account', size=64),
'partner_id': fields.related('company_id', 'partner_id', type='many2one', relation='res.partner', readonly=True),
'department_id':fields.many2one('hr.department','Department'),
'department_id':fields.many2one('hr.department', 'Department'),
'address_id': fields.many2one('res.partner.address', 'Working Address'),
'address_home_id': fields.many2one('res.partner.address', 'Home Address'),
'work_phone': fields.related('address_id', 'phone', type='char', string='Work Phone', readonly=True),
@ -110,10 +122,12 @@ class hr_employee(osv.osv):
'work_location': fields.char('Office Location', size=32),
'notes': fields.text('Notes'),
'parent_id': fields.many2one('hr.employee', 'Manager', select=True),
'category_id': fields.many2one('hr.employee.category', 'Category'),
# 'parent_id': fields.related('department_id', 'manager_id', string='Manager', type='many2one'),
# 'category_id': fields.many2one('hr.employee.category', 'Category'),
'category_ids': fields.many2many('hr.employee.category', 'employee_category_rel','category_id','emp_id','Category'),
'child_ids': fields.one2many('hr.employee', 'parent_id', 'Subordinates'),
'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade'),
'coach_id': fields.many2one('res.users', 'Coach'),
'coach_id': fields.many2one('hr.employee', 'Coach'),
'job_id': fields.many2one('hr.job', 'Job'),
'photo': fields.binary('Photo')
}
@ -129,6 +143,8 @@ class hr_employee(osv.osv):
}
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_employee where id IN %s',(tuple(ids),))
@ -144,4 +160,17 @@ class hr_employee(osv.osv):
hr_employee()
class hr_department(osv.osv):
_description = "Department"
_inherit = 'hr.department'
_columns = {
'manager_id': fields.many2one('hr.employee', 'Manager'),
# 'member_ids': fields.many2many('hr.employee', 'hr_department_user_rel', 'department_id', 'user_id', 'Members'),
'member_ids': fields.one2many('hr.employee', 'department_id', 'Members'),
# finding problem to implement one2many field as "hr_departmen_user_rel" is used in another module query
}
hr_department()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -4,38 +4,38 @@
<!-- Employee Category -->
<record id="category1" model="hr.employee.category">
<record id="category_ceo" model="hr.employee.category">
<field name="name">CEO</field>
</record>
<record id="category2" model="hr.employee.category">
<record id="category_cto" model="hr.employee.category">
<field name="name">CTO</field>
<field name="parent_id" ref="category1"/>
<field name="parent_id" ref="category_ceo"/>
</record>
<record id="category3" model="hr.employee.category">
<record id="category_managers" model="hr.employee.category">
<field name="name">Managers(Tech. Heads)</field>
<field name="parent_id" ref="category2"/>
<field name="parent_id" ref="category_cto"/>
</record>
<record id="category4" model="hr.employee.category">
<record id="category_project_managers" model="hr.employee.category">
<field name="name">Project Managers</field>
<field name="parent_id" ref="category3"/>
<field name="parent_id" ref="category_managers"/>
</record>
<record id="category5" model="hr.employee.category">
<record id="category_sr_exec" model="hr.employee.category">
<field name="name">Sr. Executives(Team Leads)</field>
<field name="parent_id" ref="category4"/>
<field name="parent_id" ref="category_project_managers"/>
</record>
<record id="category6" model="hr.employee.category">
<record id="category_jr_exec" model="hr.employee.category">
<field name="name">Jr. Executives(Developers)</field>
<field name="parent_id" ref="category5"/>
<field name="parent_id" ref="category_sr_exec"/>
</record>
<record id="category7" model="hr.employee.category">
<record id="category_trainee" model="hr.employee.category">
<field name="name">Trainee(Intership)</field>
<field name="parent_id" ref="category6"/>
<field name="parent_id" ref="category_jr_exec"/>
</record>
@ -46,9 +46,10 @@
<field name="calendar_id" ref="resource.timesheet_group1"/>
<!--<field name="regime">45</field>-->
<field name="user_id" ref="base.user_root"/>
<field name="category_id" ref="hr.category1"/>
<field name="category_id" ref="hr.category_ceo"/>
<!--<field name="holiday_max">25</field>-->
</record>
</data>
</openerp>

View File

@ -50,8 +50,8 @@ class hr_department(osv.osv):
'parent_id': fields.many2one('hr.department', 'Parent Department', select=True),
'child_ids': fields.one2many('hr.department', 'parent_id', 'Child Departments'),
'note': fields.text('Note'),
'manager_id': fields.many2one('res.users', 'Manager', required=True),
'member_ids': fields.many2many('res.users', 'hr_department_user_rel', 'department_id', 'user_id', 'Members'),
# 'manager_id': fields.many2one('res.users', 'Manager'),
# 'member_ids': fields.many2many('res.users', 'hr_department_user_rel', 'department_id', 'user_id', 'Members'),
}
_defaults = {

View File

@ -5,57 +5,105 @@
<record id="dep_management" model="hr.department">
<field name="name">Management</field>
<field name="company_id" ref="base.main_company"/>
<field name="manager_id" ref="base.user_root"/>
<field name="manager_id" ref="employee1"/>
</record>
<record id="dep_administration" model="hr.department">
<field name="name">Administration</field>
<field name="parent_id" ref="dep_management"/>
<field name="company_id" ref="base.main_company"/>
<field name="manager_id" ref="base.user_root"/>
<field name="manager_id" ref="employee1"/>
</record>
<record id="dep_technical" model="hr.department">
<field name="name">Technical department</field>
<field name="parent_id" ref="dep_management"/>
<field name="company_id" ref="base.main_company"/>
<field name="manager_id" ref="base.user_root"/>
<field name="manager_id" ref="employee1"/>
</record>
<record id="dep_it" model="hr.department">
<field name="name">IT</field>
<field name="parent_id" ref="dep_technical"/>
<field name="company_id" ref="base.main_company"/>
<field name="manager_id" ref="base.user_root"/>
<field name="manager_id" ref="employee1"/>
</record>
<record id="dep_marketing" model="hr.department">
<field name="name">Marketing</field>
<field name="parent_id" ref="dep_management"/>
<field name="company_id" ref="base.main_company"/>
<field name="manager_id" ref="base.user_root"/>
<field name="manager_id" ref="employee1"/>
</record>
<record id="dep_sales" model="hr.department">
<field name="name">Sales</field>
<field name="company_id" ref="base.main_company"/>
<field name="manager_id" ref="base.user_root"/>
<field name="manager_id" ref="employee1"/>
<field name="parent_id" ref="dep_management"/>
</record>
<record id="dep_sales_europe" model="hr.department">
<field name="name">Sales Europe</field>
<field name="company_id" ref="base.main_company"/>
<field name="manager_id" ref="base.user_root"/>
<field name="manager_id" ref="employee1"/>
<field name="parent_id" ref="dep_sales"/>
</record>
<record id="dep_sales_america" model="hr.department">
<field name="name">Sales America</field>
<field name="company_id" ref="base.main_company"/>
<field name="manager_id" ref="base.user_root"/>
<field name="manager_id" ref="employee1"/>
<field name="parent_id" ref="dep_sales"/>
</record>
<!-- HR Jobs -->
<record id="job_ceo" model="hr.job">
<field name="name">CEO</field>
<field name="department_id" ref="dep_management"/>
</record>
<record id="job_cto" model="hr.job">
<field name="name">CTO</field>
<field name="department_id" ref="dep_technical"/>
</record>
<record id="job_hr_manager" model="hr.job">
<field name="name">HR Manager</field>
<field name="department_id" ref="dep_management"/>
</record>
<record id="job_project_managers" model="hr.job">
<field name="name">Project Managers</field>
<field name="department_id" ref="dep_it"/>
</record>
<record id="job_sr_appli" model="hr.job">
<field name="name">Senior Application Analyst</field>
<field name="department_id" ref="dep_it"/>
</record>
<record id="job_jr_appli" model="hr.job">
<field name="name">Junior Application Analyst</field>
<field name="department_id" ref="dep_it"/>
</record>
<record id="job_sr_developers" model="hr.job">
<field name="name">Senior Developers</field>
<field name="department_id" ref="dep_it"/>
</record>
<record id="job_jr_developers" model="hr.job">
<field name="name">Junior Developers</field>
<field name="department_id" ref="dep_it"/>
</record>
<record id="job_trainee" model="hr.job">
<field name="name">Trainee</field>
<field name="department_id" ref="dep_it"/>
</record>
</data>
</openerp>

View File

@ -62,12 +62,14 @@
<separator string="Position" colspan="2"/>
<field name="job_id" widget="selection"/>
<field name="department_id" widget="selection"/>
<field name="category_id" widget="selection"/>
<!--<separator string="Managers" colspan="2"/>
<field name="parent_id" />
<field name="coach_id" />-->
</group>
</page>
<page string="Categories">
<field name="category_ids" nolabel="1"/>
</page>
<page string="Notes">
<field colspan="4" nolabel="1" name="notes"/>
</page>
@ -88,7 +90,6 @@
<field name="work_email"/>
<field name="department_id"/>
<field name="job_id"/>
<field name="category_id"/>
<field name="parent_id"/>
<field name="coach_id" invisible="1" />
</tree>
@ -341,7 +342,12 @@
<field name="employee_ids" colspan='4' nolabel="1" mode="tree,form"/>
</page>
</notebook>
<field name="state"/>
<group col="6" colspan="4">
<field name="state"/>
<button name="job_recruitement" string="In Recruitement" states="open" type="object" icon="gtk-go-forward"/>
<button name="job_open" string="Open" states="old" type="object" icon="terp-camera_test"/>
<button name="job_old" string="Old" states="open,recruit" type="object" icon="gtk-cancel"/>
</group>
</form>
</field>
</record>

View File

@ -1,68 +1,63 @@
- |
-
In order to test hr module in OpenERP, I will create new Employee , Department and Job Position.
-
|
I create "R & D" Department in Department form.
-
I create "R&D Department" in Department form.
-
!record {model: hr.department, id: hr_department_rd0}:
manager_id: base.user_root
name: 'R & D '
-
|
Now, I create a new employee “Mark Johnson”.
select "R & D" Department which I had created.
name: 'R & D'
-
!record {model: hr.employee, id: hr_employee_employee0}:
Now, I create a new employee “Mark Johnson”, and select department as "R&D Department".
-
!record {model: hr.employee, id: hr_employee_mark}:
address_home_id: base.res_partner_address_1
company_id: base.main_company
gender: male
marital: hr.hr_employee_marital_status_single
name: employee1
name: Mark Johnson
user_id: base.user_root
department_id: 'hr_department_rd0'
- |
In order to check the wizard “Employee Hierarchy” , I will create new employee “Phil Graves ” and select "Mark Johnson" as
Manager.
-
!record {model: hr.employee, id: hr_employee_employee1}:
-
In order to check the wizard “Employee Hierarchy” , I will create new employee “Phil Graves ” and select "Mark Johnson" as
Manager.
-
!record {model: hr.employee, id: hr_employee_phil}:
address_home_id: base.res_partner_address_3000
company_id: base.main_company
gender: male
name: employee2
name: Phil Graves
user_id: base.user_demo
parent_id: 'hr_employee_employee0'
- |
parent_id: 'hr_employee_mark'
-
I will open up form view of “Mark Johnson” and test the wizard “Employee Hierarchy” so it display the employee
hierarchy starting from “Mark Johnson”.
- |
hierarchy starting from “Mark Johnson”.
-
I will create new Job Position. I will check successfull creation of new Job Position by adding the information.
-
-
!record {model: hr.job, id: hr_job_jea0}:
department_id: 'hr_department_rd0'
description: 'Position of Junier Application Engineer '
description: 'Position of Junior Application Engineer'
expected_employees: 5
name: 'JEA '
- |
name: 'JAE'
-
I check that Employee form is in "Open" state.
-
!assert {model: hr.job, id: hr_job_jea0}:
- state == 'open'
- |
- state == 'open'
-
I create Employee for job position.
-
-
!record {model: hr.job, id: hr_job_jea0}:
employee_ids:
- address_home_id: base.res_partner_address_1
name: Manuel Lehba
department_id: 'hr_department_rd0'
gender: male
parent_id: 'hr_employee_employee0'
- |
I check that "Number of Employees" field have some value.
parent_id: 'hr_employee_mark'
-
I check that "Number of Employees" field have some value.
-
!assert {model: hr.job, id: hr_job_jea0}:
- no_of_employee != False
- no_of_employee != False

View File

@ -88,6 +88,8 @@ def emp_create_xml(self, cr, uid, dept, holiday_type, row_id, empid, name, som,
class report_custom(report_rml):
def create_xml(self, cr, uid, ids, data, context):
obj_dept = pooler.get_pool(cr.dbname).get('hr.department')
obj_emp = pooler.get_pool(cr.dbname).get('hr.employee')
depts=[]
emp_id={}
# done={}
@ -211,31 +213,24 @@ class report_custom(report_rml):
if data['model']=='hr.employee':
for id in data['form']['emp']:
items = pooler.get_pool(cr.dbname).get('hr.employee').read(cr, uid, id, ['id','name'])
items = obj_emp.read(cr, uid, id, ['id','name'])
emp_xml += emp_create_xml(self, cr, uid, 0, holiday_type, row_id, items['id'], items['name'], som, eom)
row_id = row_id +1
elif data['model']=='ir.ui.menu':
for id in data['form']['depts']:
dept = pooler.get_pool(cr.dbname).get('hr.department').browse(cr, uid, id, context.copy())
depts.append(dept)
dept_ids = tuple(data['form']['depts'])
cr.execute("""select dept_user.user_id \
from hr_department_user_rel dept_user \
where dept_user.department_id = %s\
union\
select dept.manager_id from hr_department dept\
where dept.id = %s""", (id, id))
dept = obj_dept.browse(cr, uid, id, context=context)
cr.execute("""select dept.manager_id from hr_department dept\
where dept.id = %s""", (id,))
result=cr.fetchall()
if result==[]:
continue
dept_done=0
for d in range(0,len(result)):
emp_id[d]=pooler.get_pool(cr.dbname).get('hr.employee').search(cr, uid, [('user_id', '=', result[d][0])])
items = pooler.get_pool(cr.dbname).get('hr.employee').read(cr, uid, emp_id[d], ['id', 'name'])
emp_id[d] = obj_emp.search(cr, uid, [('user_id', '=', result[d][0])])
items = obj_emp.read(cr, uid, emp_id[d], ['id', 'name'])
for item in items:
# if item['id'] in done:
# continue
@ -244,11 +239,9 @@ class report_custom(report_rml):
emp_xml += emp_create_xml(self, cr, uid, 1, holiday_type, row_id, dept.id, dept.name, som, eom)
row_id = row_id +1
dept_done=1
# done[item['id']] = 1
emp_xml += emp_create_xml(self, cr, uid, 0, holiday_type, row_id, item['id'], item['name'], som, eom)
row_id = row_id +1
# Computing the xml
xml='''<?xml version="1.0" encoding="UTF-8" ?>
<report>

View File

@ -39,6 +39,8 @@ class hr_holidays_summary_dept(osv.osv_memory):
}
def print_report(self, cr, uid, ids, context=None):
if context is None:
context = {}
data = self.read(cr, uid, ids, [])[0]
if not data['depts']:
raise osv.except_osv(_('Error'), _('You have to select at least 1 Department. And try again'))
@ -51,7 +53,6 @@ class hr_holidays_summary_dept(osv.osv_memory):
'type': 'ir.actions.report.xml',
'report_name': 'holidays.summary',
'datas': datas,
'nodestroy': True,
}
hr_holidays_summary_dept()

View File

@ -38,6 +38,8 @@ class hr_holidays_summary_employee(osv.osv_memory):
}
def print_report(self, cr, uid, ids, context=None):
if context is None:
context = {}
data = self.read(cr, uid, ids, [])[0]
data['emp'] = context['active_ids']
datas = {

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="product_consultant" model="product.product">
<field name="default_code">DEV</field>
<field name="list_price">75.0</field>
@ -15,11 +15,25 @@
<field name="procure_method">make_to_order</field>
<field eval="False" name="purchase_ok"/>
</record>
<!-- complete our example employee -->
<record id="hr.employee1" model="hr.employee">
<field name="product_id" ref="product_consultant"/>
<field name="journal_id" ref="analytic_journal"/>
</record>
<record id="working_hours" model="hr.analytic.timesheet">
<field name="name">Working Hours For OpenERP SA</field>
<field name="user_id" ref="base.user_root"/>
<field eval="time.strftime('%Y-%m-%d')" name="date"/>
<field eval="0.00" name="unit_amount"/>
<field name="product_id" ref="product_consultant"/>
<field name="product_uom_id" ref="product.uom_hour"/>
<field name="account_id" model="account.analytic.account" search="[('code','=','1')]"></field>
<field eval="0.00" name="amount"/>
<field name="general_account_id" model="account.account" ref="account.a_expense"/>
<field name="journal_id" ref="analytic_journal"/>
</record>
</data>
</openerp>

View File

@ -254,9 +254,9 @@ class report_random_timsheet(osv.osv):
line.id as id, line.account_id as analytic_account_id, line.name as name,
line.unit_amount as quantity, line.date as date, line.user_id as user_id
from
account_analytic_line line, hr_department dept,hr_department_user_rel dept_user
account_analytic_line line, hr_department dept,hr_employee dept_user
where
(dept.id = dept_user.department_id AND dept_user.user_id=line.user_id AND line.user_id is not null)
(dept.id = dept_user.department_id AND dept_user.id=line.user_id AND line.user_id is not null)
AND (dept.manager_id = """ + str(uid) + """ )
AND (line.date <= CURRENT_DATE AND line.date > (CURRENT_DATE-3))
LIMIT 10

View File

@ -95,8 +95,10 @@ class hr_timesheet_sheet(osv.osv):
_table = 'hr_timesheet_sheet_sheet'
_order = "id desc"
def _total_day(self, cr, uid, ids, name, args, context):
def _total_day(self, cr, uid, ids, name, args, context=None):
res = {}
if context is None:
context = {}
cr.execute('SELECT sheet.id, day.total_attendance, day.total_timesheet, day.total_difference\
FROM hr_timesheet_sheet_sheet AS sheet \
LEFT JOIN hr_timesheet_sheet_sheet_day AS day \
@ -564,7 +566,9 @@ class hr_attendance(osv.osv):
'name': _get_default_date,
}
def create(self, cr, uid, vals, context={}):
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
if 'sheet_id' in context:
ts = self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, context['sheet_id'])
if ts.state not in ('draft', 'new'):
@ -581,6 +585,8 @@ class hr_attendance(osv.osv):
return super(hr_attendance,self).unlink(cr, uid, ids,*args, **kwargs)
def write(self, cr, uid, ids, vals, context={}):
if context is None:
context = {}
self._check(cr, uid, ids)
res = super(hr_attendance,self).write(cr, uid, ids, vals, context=context)
if 'sheet_id' in context:

View File

@ -422,9 +422,11 @@ class stock_sale_forecast(osv.osv):
dept_id = obj.analyzed_dept_id.id and [obj.analyzed_dept_id.id] or []
dept_ids = dept_obj.search(cr,uid,[('parent_id','child_of',dept_id)])
# dept_ids_set = ','.join(map(str,dept_ids))
cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" ,(tuple(dept_ids),))
# cr.execute("SELECT user_id FROM hr_department_user_rel WHERE (department_id IN %s)" ,(tuple(dept_ids),))
cr.execute("SELECT id FROM hr_employee WHERE (department_id IN %s)" ,(tuple(dept_ids),))
dept_users = [x for x, in cr.fetchall()]
dept_users_set = ','.join(map(str,dept_users))
# dept_users_set = ','.join(map(str,dept_users))
dept_users_set = map(str,dept_users)
else:
dept_users = False
factor, round_value = self._from_default_uom_factor(cr, uid, obj, obj.product_uom.id, context=context)