From 54f43dd46e9b8a44173b7c2e6303a150cc52c353 Mon Sep 17 00:00:00 2001 From: Priyesh Date: Tue, 16 Sep 2008 19:55:47 +0530 Subject: [PATCH] modified files bzr revid: solanki.priyesh@gmail.com-20080916142547-sejpe7rcv3wg19gi --- addons/hr/hr.py | 115 +---------------------------- addons/hr/hr_demo.xml | 125 -------------------------------- addons/hr/hr_view.xml | 98 +++---------------------- addons/hr/hr_wizard.xml | 3 - addons/hr/wizard/__init__.py | 2 +- addons/hr_timesheet/__terp__.py | 2 +- 6 files changed, 12 insertions(+), 333 deletions(-) diff --git a/addons/hr/hr.py b/addons/hr/hr.py index ab75529d4b8..5926e64eae4 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -97,26 +97,6 @@ class hr_employee(osv.osv): _name = "hr.employee" _description = "Employee" - def _state(self, cr, uid, ids, name, args, context={}): - result = {} - for id in ids: - result[id] = 'absent' - cr.execute('SELECT hr_attendance.action, hr_attendance.employee_id \ - FROM ( \ - SELECT MAX(name) AS name, employee_id \ - FROM hr_attendance \ - WHERE action in (\'sign_in\', \'sign_out\') \ - GROUP BY employee_id \ - ) AS foo \ - LEFT JOIN hr_attendance \ - ON (hr_attendance.employee_id = foo.employee_id \ - AND hr_attendance.name = foo.name) \ - WHERE hr_attendance.employee_id \ - in (' + ','.join([str(x) for x in ids]) + ')') - for res in cr.fetchall(): - result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent' - return result - _columns = { 'name' : fields.char("Employee", size=128, required=True), 'active' : fields.boolean('Active'), @@ -137,55 +117,14 @@ class hr_employee(osv.osv): 'work_location': fields.char('Office Location', size=32), 'notes': fields.text('Notes'), - 'state': fields.function(_state, method=True, type='selection', selection=[('absent', 'Absent'), ('present', 'Present')], string='Attendance'), - 'parent_id': fields.many2one('hr.employee', 'Manager', select=True), 'category_id' : fields.many2one('hr.employee.category', 'Category'), - 'child_ids': fields.one2many('hr.employee', 'parent_id','Subordinates'), } _defaults = { 'active' : lambda *a: True, - 'state' : lambda *a: 'absent', } - def sign_change(self, cr, uid, ids, context={}, dt=False): - for emp in self.browse(cr, uid, ids): - if not self._action_check(cr, uid, emp.id, dt, context): - raise osv.except_osv(_('Warning'), _('You tried to sign with a date anterior to another event !\nTry to contact the administrator to correct attendances.')) - res = {'action':'action', 'employee_id':emp.id} - if dt: - res['name'] = dt - att_id = self.pool.get('hr.attendance').create(cr, uid, res, context=context) - return True - - def sign_out(self, cr, uid, ids, context={}, dt=False, *args): - id = False - for emp in self.browse(cr, uid, ids): - if not self._action_check(cr, uid, emp.id, dt, context): - raise osv.except_osv(_('Warning'), _('You tried to sign out with a date anterior to another event !\nTry to contact the administrator to correct attendances.')) - res = {'action':'sign_out', 'employee_id':emp.id} - if dt: - res['name'] = dt - att_id = self.pool.get('hr.attendance').create(cr, uid, res, context=context) - id = att_id - return id - - def _action_check(self, cr, uid, emp_id, dt=False,context={}): - cr.execute('select max(name) from hr_attendance where employee_id=%d', (emp_id,)) - res = cr.fetchone() - return not (res and (res[0]>=(dt or time.strftime('%Y-%m-%d %H:%M:%S')))) - - def sign_in(self, cr, uid, ids, context={}, dt=False, *args): - id = False - for emp in self.browse(cr, uid, ids): - if not self._action_check(cr, uid, emp.id, dt, context): - raise osv.except_osv(_('Warning'), _('You tried to sign in with a date anterior to another event !\nTry to contact the administrator to correct attendances.')) - res = {'action':'sign_in', 'employee_id':emp.id} - if dt: - res['name'] = dt - id = self.pool.get('hr.attendance').create(cr, uid, res, context=context) - return id - + hr_employee() class hr_timesheet(osv.osv): @@ -202,56 +141,4 @@ class hr_timesheet(osv.osv): _order = 'dayofweek, hour_from' hr_timesheet() -class hr_action_reason(osv.osv): - _name = "hr.action.reason" - _description = "Action reason" - _columns = { - 'name' : fields.char('Reason', size=64, required=True), - 'action_type' : fields.selection([('sign_in', 'Sign in'), ('sign_out', 'Sign out')], "Action's type"), - } - _defaults = { - 'action_type' : lambda *a: 'sign_in', - } -hr_action_reason() - -def _employee_get(obj,cr,uid,context={}): - ids = obj.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)]) - if ids: - return ids[0] - return False - -class hr_attendance(osv.osv): - _name = "hr.attendance" - _description = "Attendance" - _columns = { - 'name' : fields.datetime('Date', required=True), - 'action' : fields.selection([('sign_in', 'Sign In'), ('sign_out', 'Sign Out'),('action','Action')], 'Action', required=True), - 'action_desc' : fields.many2one("hr.action.reason", "Action reason", domain="[('action_type', '=', action)]"), - 'employee_id' : fields.many2one('hr.employee', 'Employee', required=True, select=True), - } - _defaults = { - 'name' : lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), - 'employee_id' : _employee_get, - } - - def _altern_si_so(self, cr, uid, ids): - for id in ids: - sql = ''' - select action, name - from hr_attendance as att - where employee_id = (select employee_id from hr_attendance where id=%s) - and action in ('sign_in','sign_out') - and name <= (select name from hr_attendance where id=%s) - order by name desc - limit 2 - ''' % (id, id) - cr.execute(sql) - atts = cr.fetchall() - if not ((len(atts)==1 and atts[0][0] == 'sign_in') or (atts[0][0] != atts[1][0] and atts[0][1] != atts[1][1])): - return False - return True - - _constraints = [(_altern_si_so, 'Error: Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])] - _order = 'name desc' -hr_attendance() diff --git a/addons/hr/hr_demo.xml b/addons/hr/hr_demo.xml index c83c20d5a9b..9465e57ab14 100644 --- a/addons/hr/hr_demo.xml +++ b/addons/hr/hr_demo.xml @@ -2,31 +2,6 @@ - - Start of shift - sign_in - - - End of shift - sign_out - - - Meal Break - sign_in - - - Meal Break - sign_out - - - Early exit (sick) - sign_out - - - Early exit (work injury) - sign_out - - @@ -111,105 +86,5 @@ - - - sign_in - - - - - sign_out - - - - - sign_in - - - - - sign_out - - - - - sign_in - - - - - sign_out - - - - - sign_in - - - - - sign_out - - - - - sign_in - - - - - sign_out - - - - - sign_in - - - - - sign_out - - - - - sign_in - - - - - sign_out - - - - - sign_in - - - - - sign_out - - - - - sign_in - - - - - sign_out - - - - - sign_in - - - - - sign_out - - diff --git a/addons/hr/hr_view.xml b/addons/hr/hr_view.xml index 879f4328db6..5b58d7cf448 100644 --- a/addons/hr/hr_view.xml +++ b/addons/hr/hr_view.xml @@ -49,9 +49,7 @@ - -