From 8bdaefd12e5d6e7f774662cdfeb756d822f0f27b Mon Sep 17 00:00:00 2001 From: Date: Wed, 6 Jul 2011 09:47:31 +0200 Subject: [PATCH 1/2] [IMP] hr_timesheet_sheet: sign-in and sign-out buttons on the sheet use the same attendances wizard which asks for the last sign-in/sign-out if it is missing instead of raising an error bzr revid: guewen.baconnier@camptocamp.com-20110706074731-8v14k99lcgmipm4y --- .../hr_timesheet_sheet/hr_timesheet_sheet.py | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index cf4351112a4..0cc0fbc11f7 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -245,23 +245,29 @@ class hr_timesheet_sheet(osv.osv): self.write(cr, uid, [sheet.id], {'date_current': sheet.date_to,}, context=context) return True - def sign(self, cr, uid, ids, typ, context=None): - emp_obj = self.pool.get('hr.employee') + def check_sign(self, cr, uid, ids, typ, context=None): sheet = self.browse(cr, uid, ids, context=context)[0] - if context is None: - context = {} if not sheet.date_current == time.strftime('%Y-%m-%d'): raise osv.except_osv(_('Error !'), _('You cannot sign in/sign out from an other date than today')) - emp_id = sheet.employee_id.id - context['sheet_id']=ids[0] - emp_obj.attendance_action_change(cr, uid, [emp_id], type=typ, context=context,) return True + def sign(self, cr, uid, ids, typ, context=None): + self.check_sign(cr, uid, ids, typ, context=context) + sign_obj = self.pool.get('hr.sign.in.out') + sign_id = sign_obj.create(cr, uid, {}, context=context) + methods = {'sign_in': sign_obj.si_check, + 'sign_out': sign_obj.so_check} + wizard_result = methods[typ](cr, uid, [sign_id], context=context) + if wizard_result.get('type', False) == 'ir.actions.act_window_close': + return True # ensure we do not close the main window ! + wizard_result['nodestroy'] = True # do not destroy the main window ! + return wizard_result + def sign_in(self, cr, uid, ids, context=None): - return self.sign(cr,uid,ids,'sign_in',context=None) + return self.sign(cr, uid, ids, 'sign_in', context=context) def sign_out(self, cr, uid, ids, context=None): - return self.sign(cr,uid,ids,'sign_out',context=None) + return self.sign(cr, uid, ids, 'sign_out', context=context) _columns = { 'name': fields.char('Description', size=64, select=1, From 95a2d179308a2c9b5c86ec4bc8601434a880890e Mon Sep 17 00:00:00 2001 From: Date: Thu, 7 Jul 2011 14:27:59 +0200 Subject: [PATCH 2/2] [FIX] of last commit: allow to sign in / sign out on the sheet of an other employee bzr revid: guewen.baconnier@camptocamp.com-20110707122759-3919twq9v9sznuo4 --- .../wizard/hr_attendance_sign_in_out.py | 17 ++++++++++++++--- addons/hr_timesheet_sheet/hr_timesheet_sheet.py | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) 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 7a51c2b9e1e..89ca5148bbb 100644 --- a/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py +++ b/addons/hr_attendance/wizard/hr_attendance_sign_in_out.py @@ -33,14 +33,20 @@ class hr_si_so_ask(osv.osv_memory): } def _get_empname(self, cr, uid, context=None): - emp_id = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) + if context.get('emp_id', False): + emp_id = context['emp_id'] + else: + 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].name return employee return '' def _get_empid(self, cr, uid, context=None): - emp_id = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) + if context.get('emp_id', False): + emp_id = context['emp_id'] + else: + emp_id = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) if emp_id: return emp_id[0] return False @@ -72,7 +78,10 @@ class hr_sign_in_out(osv.osv_memory): } def _get_empid(self, cr, uid, context=None): - emp_id = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context) + if context.get('emp_id', False): + emp_id = context['emp_id'] + else: + 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] return {'name': employee.name, 'state': employee.state, 'emp_id': emp_id[0]} @@ -106,6 +115,7 @@ class hr_sign_in_out(osv.osv_memory): 'res_model': 'hr.sign.in.out.ask', 'views': [(resource_id,'form')], 'type': 'ir.actions.act_window', + 'context': context, 'target': 'new', } @@ -128,6 +138,7 @@ class hr_sign_in_out(osv.osv_memory): 'res_model': 'hr.sign.in.out', 'views': [(resource_id,'form')], 'type': 'ir.actions.act_window', + 'context': context, 'target': 'new', } diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index 0cc0fbc11f7..7ba824814cf 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -254,6 +254,8 @@ class hr_timesheet_sheet(osv.osv): def sign(self, cr, uid, ids, typ, context=None): self.check_sign(cr, uid, ids, typ, context=context) sign_obj = self.pool.get('hr.sign.in.out') + sheet = self.browse(cr, uid, ids, context=context)[0] + context['emp_id'] = [sheet.employee_id.id] sign_id = sign_obj.create(cr, uid, {}, context=context) methods = {'sign_in': sign_obj.si_check, 'sign_out': sign_obj.so_check}