change date conf.
This commit is contained in:
parent
214ed7e7d4
commit
9d0385eb6b
|
@ -5,7 +5,7 @@ class ResConfigSettingsTimesheet(models.TransientModel):
|
|||
|
||||
timesheet_edit_create_limit = fields.Integer('No. of days',default=0, config_parameter='timesheet_block.timesheet_edit_create_limit')
|
||||
|
||||
timesheet_edit_create_months = fields.Integer('No. of months',default=1, config_parameter='timesheet_block.timesheet_edit_create_months')
|
||||
# timesheet_edit_create_months = fields.Integer('No. of months',default=1, config_parameter='timesheet_block.timesheet_edit_create_months')
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ class TimehseetBlock(models.Model):
|
|||
def create(self, values):
|
||||
current_date = datetime.today().date()
|
||||
entry_date = datetime.strptime(values['date'], "%Y-%m-%d").date()
|
||||
# values['date'] = datetime.strptime(values['date'], "%Y-%m-%d %H:%M:%S")
|
||||
months_diff = current_date.month - entry_date.month
|
||||
employee_object = self.env['hr.employee'].sudo().search([('user_id', '=', self.env.uid)])
|
||||
project_manager_group = self.env.ref('hr_timesheet.group_timesheet_manager')
|
||||
|
@ -38,44 +39,75 @@ class TimehseetBlock(models.Model):
|
|||
config_days_limit = float(config.get_param('timesheet_block.timesheet_edit_create_limit'))
|
||||
if entry_date <= current_date:
|
||||
if self.env.uid not in project_manager_group.users.ids:
|
||||
if months_diff == 0:
|
||||
res = super(TimehseetBlock, self).create(values)
|
||||
elif months_diff == 1:
|
||||
if employee_object.allow_to_create == 'always' and current_date.day <= config_days_limit:
|
||||
if employee_object.allow_to_create == False:
|
||||
if months_diff == 0:
|
||||
res = super(TimehseetBlock, self).create(values)
|
||||
return res
|
||||
else:
|
||||
raise AccessError('You can not create your backdate entry please connect to Hr/Department Head')
|
||||
raise AccessError('You can not create your backdate entry')
|
||||
elif employee_object.allow_to_create == 'always':
|
||||
res = super(TimehseetBlock, self).create(values)
|
||||
return res
|
||||
else:
|
||||
raise AccessError('You can not create your backdate entry please connect to Hr/Department Head')
|
||||
if months_diff == 0:
|
||||
res = super(TimehseetBlock, self).create(values)
|
||||
return res
|
||||
if months_diff == 1:
|
||||
if current_date.day <= config_days_limit:
|
||||
res = super(TimehseetBlock, self).create(values)
|
||||
return res
|
||||
else:
|
||||
raise AccessError('You can not create your backdate entry ')
|
||||
else:
|
||||
raise AccessError('You can not create your backdate entry ')
|
||||
else:
|
||||
res = super(TimehseetBlock, self).create(values)
|
||||
return res
|
||||
else:
|
||||
raise AccessError('You can not create future entry')
|
||||
return res
|
||||
|
||||
|
||||
|
||||
def write(self, values):
|
||||
current_date = datetime.today().date()
|
||||
if 'date' in values:
|
||||
entry_date = datetime.strptime(values['date'], "%Y-%m-%d").date()
|
||||
# values['date'] = datetime.strptime(values['date'], "%Y-%m-%d %H:%M:%S")
|
||||
else:
|
||||
res_date = str(self.date).split('.', 1)[0]
|
||||
entry_date = datetime.strptime(str(res_date), '%Y-%m-%d %H:%M:%S').date()
|
||||
entry_date = datetime.strptime(str(res_date), '%Y-%m-%d').date()
|
||||
months_diff = current_date.month - entry_date.month
|
||||
employee_object = self.env['hr.employee'].sudo().search([('user_id', '=', self.env.uid)])
|
||||
project_manager_group = self.env.ref('hr_timesheet.group_timesheet_manager')
|
||||
config = self.env['ir.config_parameter'].sudo()
|
||||
config_days_limit = float(config.get_param('timesheet_block.timesheet_edit_create_limit'))
|
||||
if self.env.uid not in project_manager_group.users.ids:
|
||||
if months_diff == 0:
|
||||
res = super(TimehseetBlock, self).write(values)
|
||||
elif months_diff == 1:
|
||||
if employee_object.allow_to_edit == 'always' and current_date.day <= config_days_limit:
|
||||
if entry_date <= current_date:
|
||||
if self.env.uid not in project_manager_group.users.ids:
|
||||
if employee_object.allow_to_edit == False:
|
||||
if months_diff == 0:
|
||||
res = super(TimehseetBlock, self).write(values)
|
||||
return res
|
||||
else:
|
||||
raise AccessError('You can not edit your backdate entry ')
|
||||
elif employee_object.allow_to_edit == 'always':
|
||||
res = super(TimehseetBlock, self).write(values)
|
||||
return res
|
||||
else:
|
||||
raise AccessError('You can not edit your backdate entry please connect to Hr/Department Head')
|
||||
if months_diff == 0:
|
||||
res = super(TimehseetBlock, self).write(values)
|
||||
return res
|
||||
if months_diff == 1:
|
||||
if current_date.day <= config_days_limit:
|
||||
res = super(TimehseetBlock, self).write(values)
|
||||
return res
|
||||
else:
|
||||
raise AccessError(
|
||||
'You can not edit your backdate entry ')
|
||||
else:
|
||||
raise AccessError('You can not edit your backdate entry ')
|
||||
else:
|
||||
raise AccessError('You can not edit your backdate entry please connect to Hr/Department Head')
|
||||
res = super(TimehseetBlock, self).write(values)
|
||||
return res
|
||||
else:
|
||||
res = super(TimehseetBlock, self).write(values)
|
||||
return res
|
||||
raise AccessError('You can not create future entry')
|
||||
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
<field name="timesheet_edit_create_limit"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="timesheet_edit_create_months"/>
|
||||
<div >
|
||||
<field name="timesheet_edit_create_months"/>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="o_setting_right_pane">-->
|
||||
<!-- <label for="timesheet_edit_create_months"/>-->
|
||||
<!-- <div >-->
|
||||
<!-- <field name="timesheet_edit_create_months"/>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue