diff --git a/addons/hr_timesheet/security/ir.model.access.csv b/addons/hr_timesheet/security/ir.model.access.csv index ca5bf104fe8..171fabeb67a 100644 --- a/addons/hr_timesheet/security/ir.model.access.csv +++ b/addons/hr_timesheet/security/ir.model.access.csv @@ -1,4 +1,6 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "access_hr_analytic_timesheet","hr.analytic.timesheet","model_hr_analytic_timesheet","hr.group_hr_user",1,1,1,1 "access_hr_account_analytic_line","account.account.analytic.line","account.model_account_analytic_line","hr.group_hr_user",1,1,1,0 -"access_account_analytic_journal","account.account.analytic.journal","account.model_account_analytic_journal","hr.group_hr_user",1,0,0,0 \ No newline at end of file +"access_account_analytic_journal","account.account.analytic.journal","account.model_account_analytic_journal","hr.group_hr_user",1,0,0,0 +"access_hr_sign_in_project","hr.sign.in.project","model_hr_sign_in_project","hr.group_hr_user",1,1,1,1 +"access_hr_sign_out_project","hr.sign.out.project","model_hr_sign_out_project","hr.group_hr_user",1,1,1,1 diff --git a/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out.py b/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out.py index dc1a6723786..6fc19a83b5d 100644 --- a/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out.py +++ b/addons/hr_timesheet/wizard/hr_timesheet_sign_in_out.py @@ -35,22 +35,26 @@ class hr_so_project(osv.osv_memory): 'name': fields.char('Employees name', size=32, required=True, readonly=True), 'state': fields.char('Current state', size=32, required=True, readonly=True), 'server_date': fields.datetime('Current Date', required=True, readonly=True), - 'emp_id': fields.char('Employee ID', size=256, required=False), + 'emp_id': fields.many2one('hr.employee', 'Employee ID') } - + def _get_empid(self, cr, uid, context=None): emp_obj = self.pool.get('hr.employee') emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)]) if emp_id: - employee = emp_obj.read(cr, uid, emp_id)[0] - return {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0], 'server_date':time.strftime('%Y-%m-%d %H:%M:%S')} - raise osv.except_osv(_('UserError'), _('No employee defined for your user !')) + for employee in emp_obj.browse(cr, uid, emp_id): + return {'name': employee.name, 'state': employee.state, 'emp_id': emp_id[0], 'server_date':time.strftime('%Y-%m-%d %H:%M:%S')} def _get_empid2(self, cr, uid, context): + res = self._get_empid(cr, uid, context) cr.execute('select name,action from hr_attendance where employee_id=%s order by name desc limit 1', (res['emp_id'],)) + res['server_date'] = time.strftime('%Y-%m-%d %H:%M:%S') - res['date_start'] = cr.fetchone()[0] + date_start = cr.fetchone() + + if date_start: + res['date_start'] = date_start[0] return res def default_get(self, cr, uid, fields_list, context=None): @@ -67,11 +71,13 @@ class hr_so_project(osv.osv_memory): if minimum: hour = round(round((hour + minimum / 2) / minimum) * minimum, 2) res = timesheet_obj.default_get(cr, uid, ['product_id','product_uom_id']) + if not res['product_uom_id']: raise osv.except_osv(_('UserError'), _('No cost unit defined for this employee !')) up = timesheet_obj.on_change_unit_amount(cr, uid, False, res['product_id'], hour, res['product_uom_id'])['value'] + res['name'] = data['info'] - res['account_id'] = data['account_id'] + res['account_id'] = data['account_id'].id res['unit_amount'] = hour emp_journal = emp_obj.browse(cr, uid, emp_id, context).journal_id res['journal_id'] = emp_journal and emp_journal.id or False @@ -79,39 +85,60 @@ class hr_so_project(osv.osv_memory): up = timesheet_obj.on_change_account_id(cr, uid, [], res['account_id']).get('value', {}) res.update(up) return timesheet_obj.create(cr, uid, res, context=context) - + def sign_out_result_end(self, cr, uid, ids, context=None): + emp_obj = self.pool.get('hr.employee') - data = self.read(cr, uid, ids, [])[0] - emp_id = data['emp_id'] - emp_obj.attendance_action_change(cr, uid, [emp_id], type='sign_out',dt=data['date']) - self._write(cr, uid, data, emp_id, context=context) + + for data in self.browse(cr, uid, ids): + emp_id = data.emp_id.id + emp_obj.attendance_action_change(cr, uid, [emp_id], type='sign_out',dt=data.date) + self._write(cr, uid, data, emp_id, context=context) return {} def sign_out_result(self, cr, uid, ids, context=None): emp_obj = self.pool.get('hr.employee') - data = self.read(cr, uid, ids, [])[0] - emp_id = data['emp_id'] - emp_obj.attendance_action_change(cr, uid, [emp_id], type='action', dt=data['date']) - self._write(cr, uid, data, emp_id, context=context) + + for data in self.browse(cr, uid, ids): + emp_id = data.emp_id.id + emp_obj.attendance_action_change(cr, uid, [emp_id], type='action', dt=data.date) + self._write(cr, uid, data, emp_id, context=context) return {} hr_so_project() class hr_si_project(osv.osv_memory): + _name = 'hr.sign.in.project' _description = 'Sign In By Project' _columns = { - 'name': fields.char('Employees name', size=32, required=True, readonly=True), - 'state': fields.char('Current state', size=32, required=True, readonly=True), + 'name': fields.char('Employees name', size=32, readonly=True), + 'state': fields.char('Current state', size=32, readonly=True), 'date': fields.datetime('Starting Date'), - 'server_date': fields.datetime('Current Date', required=True, readonly=True), - 'emp_id': fields.char('Employee ID', size=512, required=False), + 'server_date': fields.datetime('Current Date', readonly=True), + # 'emp_id': fields.char('Employee ID', size=512, required=False), + 'emp_id': fields.many2one('hr.employee', 'Employee ID') } + + def view_init(self, cr, uid, fields, context=None): + """ + This function checks for precondition before wizard executes + @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 fields: List of fields for default value + @param context: A standard dictionary for contextual values + """ + emp_obj = self.pool.get('hr.employee') + emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)]) + if not emp_id: + raise osv.except_osv(_('UserError'), _('No employee defined for your user !')) + return False def check_state(self, cr, uid, ids, context=None): + obj_model = self.pool.get('ir.model.data') - emp_id = self._get_empid(cr, uid, context)['emp_id'] + emp_id = self.default_get(cr, uid, context)['emp_id'] # get the latest action (sign_in or out) for this employee cr.execute('select action from hr_attendance where employee_id=%s and action in (\'sign_in\',\'sign_out\') order by name desc limit 1', (emp_id,)) res = (cr.fetchone() or ('sign_out',))[0] @@ -129,24 +156,20 @@ class hr_si_project(osv.osv_memory): 'target': 'new' } - def _get_empid(self, cr, uid, context=None): - emp_obj = self.pool.get('hr.employee') - emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)]) - if emp_id: - employee = emp_obj.read(cr, uid, emp_id)[0] - return {'name': employee['name'], 'state': employee['state'], 'emp_id': emp_id[0], 'server_date':time.strftime('%Y-%m-%d %H:%M:%S')} - raise osv.except_osv(_('UserError'), _('No employee defined for your user !')) - def sign_in_result(self, cr, uid, ids, context): emp_obj = self.pool.get('hr.employee') - data = self.read(cr, uid, ids, [], context)[0] - emp_id = data['emp_id'] - success = emp_obj.attendance_action_change(cr, uid, [emp_id], type = 'sign_in' ,dt=data['date'] or False) + for data in self.browse(cr, uid, ids, context): + emp_id = data.emp_id.id + success = emp_obj.attendance_action_change(cr, uid, [emp_id], type = 'sign_in' ,dt=data.date or False) return {} def default_get(self, cr, uid, fields_list, context=None): res = super(hr_si_project, self).default_get(cr, uid, fields_list, context=context) - res.update(self._get_empid(cr, uid, context=context)) + emp_obj = self.pool.get('hr.employee') + emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)]) + if emp_id: + for employee in emp_obj.browse(cr, uid, emp_id): + res.update({'emp_id': employee.name, 'state': employee.state, 'emp_id': emp_id[0], 'server_date':time.strftime('%Y-%m-%d %H:%M:%S')}) return res hr_si_project()