add timesheet validations

This commit is contained in:
pawan.sharma 2022-08-29 17:00:58 +05:30
parent b30542408c
commit 150562ea65
3 changed files with 35 additions and 26 deletions

View File

@ -54,7 +54,6 @@ class TimehseetBlock(models.Model):
permission_untill = False
if len(permission_list) != 0:
permission_untill = datetime.strptime(str(max(permission_list)), "%Y-%m-%d").date()
# permission_untill = datetime.strptime(max(permission_list), "%Y-%m-%d").date()
if permission_untill:
if permission_untill < entry_date:
raise AccessError('You can not create the backdate entry please contact to HR')
@ -62,40 +61,48 @@ class TimehseetBlock(models.Model):
raise AccessError('You can not create the backdate entry please contact to HR')
return super(TimehseetBlock, self).create(values)
def write(self, record):
current_date = datetime.today().date()
if 'start_datetime' in record:
entry_date = datetime.strptime(record['start_datetime'],"%Y-%m-%d %H:%M:%S").date()
else:
res_date = str(self.start_datetime).split('.', 1)[0]
entry_date = datetime.strptime(str(res_date), '%Y-%m-%d %H:%M:%S').date()
if 'start_datetime' in record or 'end_datetime' in record or 'project_id' in record or 'sub_project' in record or 'task_id' in record or 'description' in record:
if 'start_datetime' in record:
entry_date = datetime.strptime(record['start_datetime'],"%Y-%m-%d %H:%M:%S").date()
else:
res_date = str(self.start_datetime).split('.', 1)[0]
entry_date = datetime.strptime(str(res_date), '%Y-%m-%d %H:%M:%S').date()
if current_date != entry_date:
employee_object = self.env['hr.employee'].search([('user_id', '=', self.env.uid)])
if employee_object.allow_to_edit != 'always' or employee_object.allow_to_edit == False:
permission_list = []
permission_object = employee_object.permission_history.search([('permission_type', '=', 'edit'),('employee_id', '=', employee_object.id)])
for permission in permission_object:
permission_list.append(permission.date)
permission_untill =False
if len(permission_list) != 0:
permission_untill = datetime.strptime(str(max(permission_list)), "%Y-%m-%d").date()
# project = False
if self.user_id.id == self.env.uid:
if permission_untill:
if permission_untill < entry_date:
if current_date != entry_date:
employee_object = self.env['hr.employee'].search([('user_id', '=', self.env.uid)])
if employee_object.allow_to_edit != 'always' or employee_object.allow_to_edit == False:
permission_list = []
permission_object = employee_object.permission_history.search([('permission_type', '=', 'edit'),('employee_id', '=', employee_object.id)])
for permission in permission_object:
permission_list.append(permission.date)
permission_untill =False
if len(permission_list) != 0:
permission_untill = datetime.strptime(str(max(permission_list)), "%Y-%m-%d").date()
# project = False
if self.user_id.id == self.env.uid:
if permission_untill:
if permission_untill < entry_date:
raise AccessError(
'You can not edit your backdate entry please connect to HR/Department Head/Project Manager')
else:
raise AccessError(
'You can not edit your backdate entry please connect to HR/Department Head/Project Manager')
else:
raise AccessError(
'You can not edit your backdate entry please connect to HR/Department Head/Project Manager')
return super(TimehseetBlock, self).write(record)
@api.onchange('end_datetime')
@api.onchange('end_datetime' ,'start_datetime')
def _onchange_end_datetime(self):
if self.end_datetime:
current_date = datetime.today().date()
end_date = datetime.strptime(str(self.end_datetime), "%Y-%m-%d %H:%M:%S").date()
if end_date > current_date:
raise AccessError('End date cannot be a future date!')
if self.end_datetime and self.start_datetime:
end_date = datetime.strptime(str(self.end_datetime), "%Y-%m-%d %H:%M:%S").date()
start_date = datetime.strptime(str(self.start_datetime), "%Y-%m-%d %H:%M:%S").date()
if start_date > end_date:
raise AccessError('End date should be greater than start date!')

View File

@ -1,2 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_timesheet_permission_history_user,access.timesheet.block.history.user,model_timesheet_block_history,,1,1,0,0
access_timesheet_permission_history_manager,access.timesheet.block.history.manager,model_timesheet_block_history,hr_timesheet.group_timesheet_manager,1,1,1,1
access_timesheet_permission_history_user,access.timesheet.block.history.user,model_timesheet_block_history,hr_timesheet.group_hr_timesheet_user,1,1,1,0
access_back_date_assign_user,access.back.date.assign.user,model_back_date_assign,hr_timesheet.group_timesheet_manager,1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_timesheet_permission_history_user access_timesheet_permission_history_manager access.timesheet.block.history.user access.timesheet.block.history.manager model_timesheet_block_history hr_timesheet.group_timesheet_manager 1 1 0 1 0 1
3 access_timesheet_permission_history_user access.timesheet.block.history.user model_timesheet_block_history hr_timesheet.group_hr_timesheet_user 1 1 1 0
4 access_back_date_assign_user access.back.date.assign.user model_back_date_assign hr_timesheet.group_timesheet_manager 1 1 1 1

View File

@ -20,7 +20,7 @@
type="action" groups="hr.group_hr_manager"
class="oe_highlight"/>
<group/>
<field name="permission_history" readonly="1">
<field name="permission_history" readonly="1" groups="hr_timesheet.group_timesheet_manager">
<tree editable="bottom">
<field name="date"/>
<field name="reason"/>