From 595fdbde610ae81f7e986b5185d82b16dc560776 Mon Sep 17 00:00:00 2001 From: "PSI (Openerp)" <> Date: Mon, 26 Jul 2010 11:45:27 +0530 Subject: [PATCH] [IMP] hr related modules improvements bzr revid: mra@mra-laptop-20100726061527-xftwpfuimrs2bbo8 --- addons/hr/hr.py | 6 ++ addons/hr/hr_department.py | 35 ++++--- addons/hr_attendance/hr_attendance.py | 15 ++- .../wizard/hr_attendance_byweek.py | 2 + .../wizard/hr_attendance_error.py | 4 +- .../wizard/hr_attendance_sign_in_out.py | 34 +++++-- addons/hr_recruitment/__openerp__.py | 2 +- addons/hr_recruitment/hr_recruitment.py | 39 +++++--- addons/hr_recruitment/hr_recruitment_data.xml | 12 +-- addons/hr_recruitment/hr_recruitment_demo.xml | 14 +-- addons/hr_recruitment/hr_recruitment_menu.xml | 4 +- addons/hr_recruitment/hr_recruitment_view.xml | 99 ++++++++++++++++--- .../report/hr_recruitment_report_view.xml | 6 +- ...hr_recruitment_create_partner_job_view.xml | 4 +- addons/hr_timesheet/hr_timesheet.py | 24 +++-- .../wizard/hr_timesheet_print_employee.py | 5 + .../wizard/hr_timesheet_print_users.py | 2 + .../wizard/hr_timesheet_sign_in_out.py | 88 ++++++++++------- .../wizard/hr_timesheet_sign_in_out_view.xml | 8 +- .../board_hr_timesheet_invoice.xml | 16 +-- 20 files changed, 294 insertions(+), 125 deletions(-) diff --git a/addons/hr/hr.py b/addons/hr/hr.py index ab7d6189621..a10c7cc29b1 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -34,6 +34,8 @@ class hr_employee_category(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_category where id IN %s', (tuple(ids), )) @@ -62,6 +64,8 @@ hr_employee_marital_status() class hr_job(osv.osv): def _no_of_employee(self, cr, uid, ids, name, args, context=None): + if context is None: + context = {} res = {} for emp in self.browse(cr, uid, ids): res[emp.id] = len(emp.employee_ids or []) @@ -133,6 +137,8 @@ class hr_employee(osv.osv): } def _get_photo(self, cr, uid, context=None): + if context is None: + context = {} return open(os.path.join( tools.config['addons_path'], 'hr/image', 'photo.png'), 'rb') .read().encode('base64') diff --git a/addons/hr/hr_department.py b/addons/hr/hr_department.py index 47c4c0e0fc7..f304e994a1f 100644 --- a/addons/hr/hr_department.py +++ b/addons/hr/hr_department.py @@ -29,7 +29,7 @@ class hr_department(osv.osv): context = {} if not len(ids): return [] - reads = self.read(cr, uid, ids, ['name','parent_id'], context) + reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) res = [] for record in reads: name = record['name'] @@ -39,6 +39,8 @@ class hr_department(osv.osv): return res def _dept_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): + if context is None: + context = {} res = self.name_get(cr, uid, ids, context=context) return dict(res) @@ -59,7 +61,9 @@ class hr_department(osv.osv): } def _get_members(self,cr, uid, context=None): - mids = self.search(cr, uid, [('manager_id', '=', uid)]) + if context is None: + context = {} + 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: @@ -67,6 +71,8 @@ class hr_department(osv.osv): 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),)) @@ -89,6 +95,7 @@ class ir_action_window(osv.osv): 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] @@ -96,7 +103,7 @@ class ir_action_window(osv.osv): for r in res: mystring = 'department_users_get()' if mystring in (r.get('domain', '[]') or ''): - r['domain'] = r['domain'].replace(mystring, str(self.pool.get('hr.department')._get_members(cr, uid))) + r['domain'] = r['domain'].replace(mystring, str(obj_dept._get_members(cr, uid))) if isinstance(ids, (int, long)): if res: return res[0] @@ -111,18 +118,22 @@ class res_users(osv.osv): _description = 'User' def _parent_compute(self, cr, uid, ids, name, args, context=None): + if context is None: + context = {} result = {} obj_dept = self.pool.get('hr.department') for user_id in ids: - ids_dept = obj_dept.search(cr, uid, [('member_ids', 'in', [user_id])]) + ids_dept = obj_dept.search(cr, uid, [('member_ids', 'in', [user_id])], context=context) parent_ids = [] if ids_dept: - data_dept = obj_dept.read(cr, uid, ids_dept, ['manager_id']) + data_dept = obj_dept.read(cr, uid, ids_dept, ['manager_id'], context=context) parent_ids = map(lambda x: x['manager_id'][0], data_dept) result[user_id] = parent_ids return result def _parent_search(self, cr, uid, obj, name, args, context=None): + if context is None: + context = {} parent = [] for arg in args: if arg[0] == 'parent_id': @@ -133,20 +144,20 @@ class res_users(osv.osv): return [('id', 'in', child_ids.get(uid,[]))] def _child_compute(self, cr, uid, ids, name, args, context=None): + if context is None: + context = {} obj_dept = self.pool.get('hr.department') obj_user = self.pool.get('res.users') result = {} - if context is None: - context = {} for manager_id in ids: child_ids = [] - mgnt_dept_ids = obj_dept.search(cr, uid, [('manager_id', '=', manager_id)]) - ids_dept = obj_dept.search(cr, uid, [('id', 'child_of', mgnt_dept_ids)]) + mgnt_dept_ids = obj_dept.search(cr, uid, [('manager_id', '=', manager_id)], context=context) + ids_dept = obj_dept.search(cr, uid, [('id', 'child_of', mgnt_dept_ids)], context=context) if ids_dept: - data_dept = obj_dept.read(cr, uid, ids_dept, ['member_ids']) + data_dept = obj_dept.read(cr, uid, ids_dept, ['member_ids'], context=context) childs = map(lambda x: x['member_ids'], data_dept) childs = tools.flatten(childs) - childs = obj_user.search(cr, uid, [('id', 'in', childs),('active', '=', True)]) + childs = obj_user.search(cr, uid, [('id', 'in', childs),('active', '=', True)], context=context) if manager_id in childs: childs.remove(manager_id) child_ids.extend(tools.flatten(childs)) @@ -159,6 +170,8 @@ class res_users(osv.osv): return result def _child_search(self, cr, uid, obj, name, args, context=None): + if context is None: + context = {} parent = [] for arg in args: if arg[0] == 'child_ids': diff --git a/addons/hr_attendance/hr_attendance.py b/addons/hr_attendance/hr_attendance.py index d5667051ae1..938df72d4e9 100644 --- a/addons/hr_attendance/hr_attendance.py +++ b/addons/hr_attendance/hr_attendance.py @@ -37,7 +37,9 @@ class hr_action_reason(osv.osv): hr_action_reason() def _employee_get(obj, cr, uid, context=None): - ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)]) + if context is None: + context = {} + ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) if ids: return ids[0] return False @@ -47,6 +49,8 @@ class hr_attendance(osv.osv): _description = "Attendance" def _day_compute(self, cr, uid, ids, fieldnames, args, context=None): + if context is None: + context = {} res = dict.fromkeys(ids, '') for obj in self.browse(cr, uid, ids, context=context): res[obj.id] = time.strftime('%Y-%m-%d', time.strptime(obj.name, '%Y-%m-%d %H:%M:%S')) @@ -89,6 +93,8 @@ class hr_employee(osv.osv): _description = "Employee" def _state(self, cr, uid, ids, name, args, context=None): + if context is None: + context = {} result = {} for id in ids: result[id] = 'absent' @@ -112,11 +118,16 @@ class hr_employee(osv.osv): } def _action_check(self, cr, uid, emp_id, dt=False, context=None): + if context is None: + context = {} cr.execute('select max(name) from hr_attendance where employee_id=%s', (emp_id,)) res = cr.fetchone() return not (res and (res[0]>=(dt or time.strftime('%Y-%m-%d %H:%M:%S')))) def attendance_action_change(self, cr, uid, ids, type='action', context=None, dt=False, *args): + obj_attendance = self.pool.get('hr.attendance') + if context is None: + context = {} id = False warning_sign = 'sign' res = {} @@ -136,7 +147,7 @@ class hr_employee(osv.osv): if dt: res['name'] = dt - id = self.pool.get('hr.attendance').create(cr, uid, res, context=context) + id = obj_attendance.create(cr, uid, res, context=context) if type != 'action': return id diff --git a/addons/hr_attendance/wizard/hr_attendance_byweek.py b/addons/hr_attendance/wizard/hr_attendance_byweek.py index 9ef48f29fff..175ebf8a228 100644 --- a/addons/hr_attendance/wizard/hr_attendance_byweek.py +++ b/addons/hr_attendance/wizard/hr_attendance_byweek.py @@ -35,6 +35,8 @@ class hr_attendance_byweek(osv.osv_memory): } def print_report(self, cr, uid, ids, context=None): + if context is None: + context = {} datas = { 'ids': [], 'model': 'hr.employee', diff --git a/addons/hr_attendance/wizard/hr_attendance_error.py b/addons/hr_attendance/wizard/hr_attendance_error.py index 62689705c17..449fc4ca5c2 100644 --- a/addons/hr_attendance/wizard/hr_attendance_error.py +++ b/addons/hr_attendance/wizard/hr_attendance_error.py @@ -42,14 +42,14 @@ class hr_attendance_error(osv.osv_memory): if context is None: context = {} emp_ids = [] - data_error = self.read(cr, uid, ids)[0] + data_error = self.read(cr, uid, ids, context=context)[0] date_from = data_error['init_date'] date_to = data_error['end_date'] cr.execute("select id from hr_attendance where employee_id IN %s and to_char(name,'YYYY-mm-dd')<=%s and to_char(name,'YYYY-mm-dd')>=%s and action IN %s order by name" ,(tuple(context['active_ids']), date_to, date_from, tuple(['sign_in','sign_out']))) attendance_ids = [x[0] for x in cr.fetchall()] if not attendance_ids: raise osv.except_osv(_('No Data Available'), _('No records found for your selection!')) - attendance_records = self.pool.get('hr.attendance').browse(cr, uid, attendance_ids) + attendance_records = self.pool.get('hr.attendance').browse(cr, uid, attendance_ids, context=context) for rec in attendance_records: if rec.employee_id.id not in emp_ids: diff --git a/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py b/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py index 7ffd94dbca5..5ac041d7a42 100644 --- a/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py +++ b/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py @@ -53,11 +53,15 @@ class hr_si_so_ask(osv.osv_memory): } def sign_in(self, cr, uid, ids, context=None): - data = self.read(cr, uid, ids, [])[0] + if context is None: + context = {} + data = self.read(cr, uid, ids, [], context=context)[0] return self.pool.get('hr.sign.in.out').sign_in(cr, uid, data, context) def sign_out(self, cr, uid, ids, context=None): - data = self.read(cr, uid, ids, [])[0] + if context is None: + context = {} + data = self.read(cr, uid, ids, [], context=context)[0] return self.pool.get('hr.sign.in.out').sign_out(cr, uid, data, context) hr_si_so_ask() @@ -74,6 +78,8 @@ class hr_sign_in_out(osv.osv_memory): } def _get_empid(self, cr, uid, context=None): + if context is None: + context = {} emp_id = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) if emp_id: employee = self.pool.get('hr.employee').browse(cr, uid, emp_id, context=context)[0] @@ -81,6 +87,8 @@ class hr_sign_in_out(osv.osv_memory): return {} def default_get(self, cr, uid, fields_list, context=None): + if context is None: + context = {} res = super(hr_sign_in_out, self).default_get(cr, uid, fields_list, context=context) res_emp = self._get_empid(cr, uid, context=context) res.update(res_emp) @@ -89,10 +97,12 @@ class hr_sign_in_out(osv.osv_memory): def si_check(self, cr, uid, ids, context=None): obj_model = self.pool.get('ir.model.data') att_obj = self.pool.get('hr.attendance') - data = self.read(cr, uid, ids, [])[0] + if context is None: + context = {} + data = self.read(cr, uid, ids, [], context=context)[0] emp_id = data['emp_id'] att_id = att_obj.search(cr, uid, [('employee_id', '=', emp_id)], limit=1, order='name desc') - last_att = att_obj.browse(cr, uid, att_id) + last_att = att_obj.browse(cr, uid, att_id, context=context) if last_att: last_att = last_att[0] cond = not last_att or last_att.action == 'sign_out' @@ -113,8 +123,10 @@ class hr_sign_in_out(osv.osv_memory): def so_check(self, cr, uid, ids, context=None): obj_model = self.pool.get('ir.model.data') - data = self.read(cr, uid, ids, [])[0] att_obj = self.pool.get('hr.attendance') + if context is None: + context = {} + data = self.read(cr, uid, ids, [], context=context)[0] emp_id = data['emp_id'] att_id = att_obj.search(cr, uid, [('employee_id', '=', emp_id),('action', '!=', 'action')], limit=1, order='name desc') last_att = att_obj.browse(cr, uid, att_id, context=context) @@ -137,8 +149,8 @@ class hr_sign_in_out(osv.osv_memory): if cond: return self.sign_out(cr, uid, data, context) else: - model_data_ids = self.pool.get('ir.model.data').search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_hr_attendance_si_ask')], context=context) - resource_id = self.pool.get('ir.model.data').read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] + model_data_ids = att_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_hr_attendance_si_ask')], context=context) + resource_id = att_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] return { 'name': _('Sign in / Sign out'), 'view_type': 'form', @@ -150,12 +162,14 @@ class hr_sign_in_out(osv.osv_memory): } def sign_in(self, cr, uid, data, context=None): + if context is None: + context = {} emp_id = data['emp_id'] if 'last_time' in data: if data['last_time'] > time.strftime('%Y-%m-%d %H:%M:%S'): raise osv.except_osv(_('UserError'), _('The sign-out date must be in the past')) self.pool.get('hr.attendance').create(cr, uid, {'name': data['last_time'], 'action': 'sign_out', - 'employee_id': emp_id}) + 'employee_id': emp_id}, context=context) try: success = self.pool.get('hr.employee').attendance_action_change(cr, uid, [emp_id], 'sign_in') except: @@ -163,11 +177,13 @@ class hr_sign_in_out(osv.osv_memory): return {} # To do: Return Success message def sign_out(self, cr, uid, data, context=None): + if context is None: + context = {} emp_id = data['emp_id'] if 'last_time' in data: if data['last_time'] > time.strftime('%Y-%m-%d %H:%M:%S'): raise osv.except_osv(_('UserError'), _('The Sign-in date must be in the past')) - self.pool.get('hr.attendance').create(cr, uid, {'name':data['last_time'], 'action':'sign_in', 'employee_id':emp_id}) + self.pool.get('hr.attendance').create(cr, uid, {'name':data['last_time'], 'action':'sign_in', 'employee_id':emp_id}, context=context) try: success = self.pool.get('hr.employee').attendance_action_change(cr, uid, [emp_id], 'sign_out') except: diff --git a/addons/hr_recruitment/__openerp__.py b/addons/hr_recruitment/__openerp__.py index 0d10ba0f248..7779a1db90d 100644 --- a/addons/hr_recruitment/__openerp__.py +++ b/addons/hr_recruitment/__openerp__.py @@ -36,6 +36,7 @@ system to store and search in your CV base. 'depends': ['hr','survey','crm'], 'update_xml': [ 'wizard/hr_recruitment_phonecall_view.xml', + 'wizard/hr_recruitment_create_partner_job_view.xml', 'hr_recruitment_view.xml', 'hr_recruitment_menu.xml', # 'report_hr_recruitment_view.xml', @@ -43,7 +44,6 @@ system to store and search in your CV base. 'security/ir.model.access.csv', 'board_hr_recruitment_statistical_view.xml', 'report/hr_recruitment_report_view.xml', - 'wizard/hr_recruitment_create_partner_job_view.xml', ], 'init_xml': [ 'hr_recruitment_data.xml' diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 178fdbffb09..4297f8eb6c5 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -59,6 +59,19 @@ class hr_recruitment_stage(osv.osv): } hr_recruitment_stage() +class hr_recruitment_degree(osv.osv): + """ Degree of HR Recruitment """ + _name = "hr.recruitment.degree" + _description = "Degree of Recruitment" + _columns = { + 'name': fields.char('Name', size=64, required=True, translate=True), + 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of degrees."), + } + _defaults = { + 'sequence': 1, + } +hr_recruitment_degree() + class hr_applicant(osv.osv, crm.crm_case): _name = "hr.applicant" _description = "Applicant" @@ -88,6 +101,8 @@ class hr_applicant(osv.osv, crm.crm_case): # Applicant Columns 'date_closed': fields.datetime('Closed', readonly=True), 'date': fields.datetime('Date'), + 'date_action': fields.date('Next Action Date'), + 'title_action': fields.char('Next Action', size=64), 'priority': fields.selection(AVAILABLE_PRIORITIES, 'Appreciation'), 'job_id': fields.many2one('hr.job', 'Applied Job'), 'salary_proposed': fields.float('Proposed Salary', help="Salary Proposed by the Organisation"), @@ -96,7 +111,7 @@ class hr_applicant(osv.osv, crm.crm_case): 'partner_name': fields.char("Applicant's Name", size=64), 'partner_phone': fields.char('Phone', size=32), 'partner_mobile': fields.char('Mobile', size=32), - 'type_id': fields.many2one('crm.case.resource.type', 'Degree', domain="[('object_id.model', '=', 'hr.applicant')]"), + 'type_id': fields.many2one('hr.recruitment.degree', 'Degree'), 'department_id':fields.many2one('hr.department', 'Department'), 'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True), 'survey' : fields.related('job_id', 'survey_id', type='many2one', relation='survey', string='Survey'), @@ -237,7 +252,7 @@ class hr_applicant(osv.osv, crm.crm_case): def message_new(self, cr, uid, msg, context): """ Automatically calls when new email message arrives - + @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks @@ -249,7 +264,7 @@ class hr_applicant(osv.osv, crm.crm_case): body = msg.get('body') msg_from = msg.get('from') priority = msg.get('priority') - + vals = { 'name': subject, 'email_from': msg_from, @@ -259,15 +274,15 @@ class hr_applicant(osv.osv, crm.crm_case): } if msg.get('priority', False): vals['priority'] = priority - + res = mailgate_pool.get_partner(cr, uid, msg.get('from')) if res: vals.update(res) res = self.create(cr, uid, vals, context) - + message = _('A Job Request created') + " '" + subject + "' " + _("from Mailgate.") self.log(cr, uid, res, message) - + attachents = msg.get('attachments', []) for attactment in attachents or []: data_attach = { @@ -283,16 +298,16 @@ class hr_applicant(osv.osv, crm.crm_case): return res def message_update(self, cr, uid, ids, vals={}, msg="", default_act='pending', context={}): - """ + """ @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, - @param ids: List of update mail’s IDs + @param ids: List of update mail’s IDs """ - + if isinstance(ids, (str, int, long)): ids = [ids] - + msg_from = msg['from'] vals.update({ 'description': msg['body'] @@ -312,7 +327,7 @@ class hr_applicant(osv.osv, crm.crm_case): if res and maps.get(res.group(1).lower(), False): key = maps.get(res.group(1).lower()) vls[key] = res.group(2).lower() - + vals.update(vls) res = self.write(cr, uid, ids, vals) return res @@ -328,7 +343,7 @@ class hr_applicant(osv.osv, crm.crm_case): @param **args: Return Dictionary of Keyword Value """ return True - + def case_open(self, cr, uid, ids, *args): """ @param self: The object pointer diff --git a/addons/hr_recruitment/hr_recruitment_data.xml b/addons/hr_recruitment/hr_recruitment_data.xml index 8a4ddb93428..aaa386356c5 100644 --- a/addons/hr_recruitment/hr_recruitment_data.xml +++ b/addons/hr_recruitment/hr_recruitment_data.xml @@ -17,17 +17,17 @@ - + Graduate - + 1 - + Licenced - + 2 - + > Bac +5 - + 3 diff --git a/addons/hr_recruitment/hr_recruitment_demo.xml b/addons/hr_recruitment/hr_recruitment_demo.xml index 3eba3bc17de..52603d7b8fa 100644 --- a/addons/hr_recruitment/hr_recruitment_demo.xml +++ b/addons/hr_recruitment/hr_recruitment_demo.xml @@ -9,7 +9,7 @@ - + @@ -29,7 +29,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -68,7 +68,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -121,7 +121,7 @@ - + diff --git a/addons/hr_recruitment/hr_recruitment_menu.xml b/addons/hr_recruitment/hr_recruitment_menu.xml index 971423d45a7..ec6b719c973 100644 --- a/addons/hr_recruitment/hr_recruitment_menu.xml +++ b/addons/hr_recruitment/hr_recruitment_menu.xml @@ -7,9 +7,9 @@ Applicants hr.applicant - tree,form,graph + tree,form,graph,calendar - {"search_default_user_id":uid} + {"search_default_user_id":uid, 'search_default_current': 1} diff --git a/addons/hr_recruitment/hr_recruitment_view.xml b/addons/hr_recruitment/hr_recruitment_view.xml index b4b1a434700..6a622a09ddf 100644 --- a/addons/hr_recruitment/hr_recruitment_view.xml +++ b/addons/hr_recruitment/hr_recruitment_view.xml @@ -55,6 +55,8 @@