[ADD]: hr_attendance: add yaml for hr_attendance module.
bzr revid: atp@tinyerp.co.in-20100531081025-al9hw6umhed1t6vg
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
'wizard/hr_attendance_sign_in_out_view.xml',
|
||||
],
|
||||
'demo_xml': ['hr_attendance_demo.xml'],
|
||||
'test': ['test/test_hr_attendance.yml'],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
'certificate': '0063495605613',
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
- |
|
||||
In order to test hr_attendance module in OpenERP, I create new attendance and perform Sign In/Sign Out operation.
|
||||
|
||||
- |
|
||||
First I create Employee "Mark Johnson".
|
||||
-
|
||||
!record {model: hr.employee, id: hr_employee_employee0}:
|
||||
address_home_id: base.res_partner_address_1
|
||||
company_id: base.main_company
|
||||
gender: male
|
||||
name: Mark Johnson
|
||||
user_id: base.user_root
|
||||
|
||||
- |
|
||||
Given that I have Attendance Reason "Good Morning" for Sign In.
|
||||
-
|
||||
!record {model: hr.action.reason, id: hr_action_reason_goodmorning0}:
|
||||
name: Good Morning
|
||||
action_type: sign_in
|
||||
- |
|
||||
I also create another Attendance Reason for Sign Out.
|
||||
-
|
||||
!record {model: hr.action.reason, id: hr_action_reason_goodnight0}:
|
||||
name: Good Night
|
||||
action_type: sign_out
|
||||
- |
|
||||
Now , When I came in office , I create Atendances and perform "Sign In" action with proper reason.
|
||||
-
|
||||
!record {model: hr.attendance, id: hr_attendance_0}:
|
||||
action: sign_in
|
||||
action_desc: 'hr_action_reason_goodmorning0'
|
||||
employee_id: 'hr_employee_employee0'
|
||||
name: '2010-05-18 19:08:08'
|
||||
- |
|
||||
I check that Employee is in "Present" state.
|
||||
-
|
||||
!assert {model: hr.employee, id: hr_employee_employee0}:
|
||||
- state == 'present'
|
||||
|
||||
- |
|
||||
When I left office , I create attendance and perform "Sign Out".
|
||||
-
|
||||
!record {model: hr.attendance, id: hr_attendance_1}:
|
||||
action: sign_out
|
||||
employee_id: 'hr_employee_employee0'
|
||||
name: '2010-05-18 19:10:55'
|
||||
- |
|
||||
I check that Employee is in "Absent" state.
|
||||
-
|
||||
!assert {model: hr.employee, id: hr_employee_employee0}:
|
||||
- state == 'absent'
|
||||
|
||||
- |
|
||||
I can also fill my attendance using "Sign In/Sign Out" wizard.
|
||||
-
|
||||
!record {model: hr.sign.in.out, id: hr_sign_in_out_markjohnson0}:
|
||||
name: Mark Johnson
|
||||
state: absent
|
||||
|
||||
- |
|
||||
I click on "Sign In" button of this wizard to perform present action.
|
||||
-
|
||||
!python {model: hr.sign.in.out}: |
|
||||
obj_attendance = self.pool.get('hr.employee')
|
||||
emp_id = obj_attendance.search(cr, uid, [('user_id', '=', uid), ('name', '=', "Mark Johnson")])
|
||||
if emp_id:
|
||||
employee = obj_attendance.read(cr, uid, emp_id)[0]
|
||||
self.write(cr, uid, [ref('hr_sign_in_out_markjohnson0')], {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0]})
|
||||
self.si_check(cr, uid, [ref("hr_sign_in_out_markjohnson0")], {"active_id": ref("hr_employee_employee0")})
|
||||
|
||||
- |
|
||||
I check that Employee is in "Present" state.
|
||||
-
|
||||
!assert {model: hr.employee, id: hr_employee_employee0}:
|
||||
- state == 'present'
|
||||
|
||||
- |
|
||||
I forgot to "Sign Out" in Yesterday and want to sign in Today using This wizard.
|
||||
-
|
||||
!record {model: hr.sign.in.out, id: hr_sign_in_out_markjohnson0}:
|
||||
name: Mark Johnson
|
||||
state: present
|
||||
- |
|
||||
I click on "Sign In" button of this wizard. that will Open new form which ask for Last Sign Out date.
|
||||
-
|
||||
!python {model: hr.sign.in.out}: |
|
||||
obj_attendance = self.pool.get('hr.employee')
|
||||
emp_id = obj_attendance.search(cr, uid, [('user_id', '=', uid), ('name', '=', "Mark Johnson")])
|
||||
if emp_id:
|
||||
employee = obj_attendance.read(cr, uid, emp_id)[0]
|
||||
self.write(cr, uid, [ref('hr_sign_in_out_markjohnson0')], {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0]})
|
||||
self.si_check(cr, uid, [ref("hr_sign_in_out_markjohnson0")])
|
||||
- |
|
||||
I select Last Sign Out date in "hr sign out ask" wizard.
|
||||
-
|
||||
!record {model: hr.sign.in.out.ask, id: hr_sign_in_out_ask_markjohnson0}:
|
||||
last_time: !eval time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
name: Mark Johnson
|
||||
- |
|
||||
Now I click on "Sign In" button of this wizard.
|
||||
-
|
||||
!python {model: hr.sign.in.out.ask}: |
|
||||
obj_attendance = self.pool.get('hr.employee')
|
||||
emp_id = obj_attendance.search(cr, uid, [('user_id', '=', uid), ('name', '=', "Mark Johnson")])
|
||||
if emp_id:
|
||||
employee = obj_attendance.read(cr, uid, emp_id)[0]
|
||||
self.write(cr, uid, [ref('hr_sign_in_out_ask_markjohnson0')], {'emp_id': emp_id[0]})
|
||||
#self.sign_in(cr, uid, [ref("hr_sign_in_out_ask_markjohnson0")], {"active_ids": [ref("hr_attendance.menu_hr_attendance_sigh_in_out")]})
|
||||
|
||||
@@ -33,16 +33,16 @@ class hr_si_so_ask(osv.osv_memory):
|
||||
'emp_id': fields.char('Empoyee ID', size=32, required=True, readonly=True),
|
||||
}
|
||||
def _get_empname(self, cr, uid, context=None):
|
||||
service = netsvc.LocalService('object_proxy')
|
||||
emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)])
|
||||
emp_obj = self.pool.get('hr.employee')
|
||||
emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
|
||||
if emp_id:
|
||||
employee = service.execute(cr.dbname, uid, 'hr.employee', 'read', emp_id)[0]
|
||||
employee = emp_obj.read(cr, uid, emp_id)[0]
|
||||
return employee['name']
|
||||
return ''
|
||||
|
||||
def _get_empid(self, cr, uid, context=None):
|
||||
service = netsvc.LocalService('object_proxy')
|
||||
emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)])
|
||||
emp_obj = self.pool.get('hr.employee')
|
||||
emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
|
||||
if emp_id:
|
||||
return emp_id[0]
|
||||
return False
|
||||
@@ -74,10 +74,10 @@ class hr_sign_in_out(osv.osv_memory):
|
||||
}
|
||||
|
||||
def _get_empid(self, cr, uid, context=None):
|
||||
service = netsvc.LocalService('object_proxy')
|
||||
emp_id = service.execute(cr.dbname, uid, 'hr.employee', 'search', [('user_id', '=', uid)])
|
||||
emp_obj = self.pool.get('hr.employee')
|
||||
emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
|
||||
if emp_id:
|
||||
employee = service.execute(cr.dbname, uid, 'hr.employee', 'read', emp_id)[0]
|
||||
employee = emp_obj.read(cr, uid, emp_id)[0]
|
||||
return {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0]}
|
||||
return {}
|
||||
|
||||
@@ -88,12 +88,13 @@ class hr_sign_in_out(osv.osv_memory):
|
||||
return res
|
||||
|
||||
def si_check(self, cr, uid, ids, context=None):
|
||||
service = netsvc.LocalService('object_proxy')
|
||||
|
||||
att_obj = self.pool.get('hr.attendance')
|
||||
obj_model = self.pool.get('ir.model.data')
|
||||
data = self.read(cr, uid, ids, [])[0]
|
||||
emp_id = data['emp_id']
|
||||
att_id = service.execute(cr.dbname, uid, 'hr.attendance', 'search', [('employee_id', '=', emp_id)], limit=1, order='name desc')
|
||||
last_att = service.execute(cr.dbname, uid, 'hr.attendance', 'read', att_id)
|
||||
att_id = att_obj.search(cr, uid, [('employee_id', '=', emp_id)], limit=1, order='name desc')
|
||||
last_att = att_obj.read(cr, uid, att_id)
|
||||
if last_att:
|
||||
last_att = last_att[0]
|
||||
cond = not last_att or last_att['action'] == 'sign_out'
|
||||
@@ -113,12 +114,13 @@ class hr_sign_in_out(osv.osv_memory):
|
||||
}
|
||||
|
||||
def so_check(self, cr, uid, ids, context=None):
|
||||
service = netsvc.LocalService('object_proxy')
|
||||
|
||||
att_obj = self.pool.get('hr.attendance')
|
||||
obj_model = self.pool.get('ir.model.data')
|
||||
data = self.read(cr, uid, ids, [])[0]
|
||||
emp_id = data['emp_id']
|
||||
att_id = service.execute(cr.dbname, uid, 'hr.attendance', 'search', [('employee_id', '=', emp_id),('action','!=','action')], limit=1, order='name desc')
|
||||
last_att = service.execute(cr.dbname, uid, 'hr.attendance', 'read', att_id)
|
||||
att_id = att_obj.search(cr, uid, [('employee_id', '=', emp_id),('action','!=','action')], limit=1, order='name desc')
|
||||
last_att = att_obj.read(cr, uid, att_id)
|
||||
if last_att:
|
||||
last_att = last_att[0]
|
||||
if not att_id and not last_att:
|
||||
@@ -151,31 +153,31 @@ class hr_sign_in_out(osv.osv_memory):
|
||||
}
|
||||
|
||||
def sign_in(self, cr, uid, data, context=None):
|
||||
service = netsvc.LocalService('object_proxy')
|
||||
att_obj = self.pool.get('hr.attendance')
|
||||
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'))
|
||||
service.execute(cr.dbname, uid, 'hr.attendance', 'create', {
|
||||
att_obj.create(cr, uid, {
|
||||
'name': data['last_time'],
|
||||
'action': 'sign_out',
|
||||
'employee_id': emp_id
|
||||
})
|
||||
try:
|
||||
success = service.execute(cr.dbname, uid, 'hr.employee', 'attendance_action_change', [emp_id], 'sign_in')
|
||||
success = self.pool.get('hr.employee').attendance_action_change(cr, uid, [emp_id], 'sign_in')
|
||||
except:
|
||||
raise osv.except_osv(_('UserError'), _('A sign-in must be right after a sign-out !'))
|
||||
return {} # To do: Return Success message
|
||||
|
||||
def sign_out(self, cr, uid, data, context=None):
|
||||
service = netsvc.LocalService('object_proxy')
|
||||
att_obj = self.pool.get('hr_attendance')
|
||||
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'))
|
||||
service.execute(cr.dbname, uid, 'hr.attendance', 'create', {'name':data['last_time'], 'action':'sign_in', 'employee_id':emp_id})
|
||||
att_obj.create(cr, uid, {'name':data['last_time'], 'action':'sign_in', 'employee_id':emp_id})
|
||||
try:
|
||||
success = service.execute(cr.dbname, uid, 'hr.employee', 'attendance_action_change', [emp_id], 'sign_out')
|
||||
success = self.pool.get('hr.employee').attendance_action_change(cr, uid, [emp_id], 'sign_out')
|
||||
except:
|
||||
raise osv.except_osv(_('UserError'), _('A sign-out must be right after a sign-in !'))
|
||||
return {} # To do: Return Success message
|
||||
|
||||
Reference in New Issue
Block a user