diff --git a/timesheet_block/models/res_config_settings.py b/timesheet_block/models/res_config_settings.py
index 4ab38b0..99459f2 100644
--- a/timesheet_block/models/res_config_settings.py
+++ b/timesheet_block/models/res_config_settings.py
@@ -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')
diff --git a/timesheet_block/models/timesheet.py b/timesheet_block/models/timesheet.py
index ea6c667..5f96324 100755
--- a/timesheet_block/models/timesheet.py
+++ b/timesheet_block/models/timesheet.py
@@ -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')
+
diff --git a/timesheet_block/views/res_config_settings.xml b/timesheet_block/views/res_config_settings.xml
index cc83bd6..85f53a1 100644
--- a/timesheet_block/views/res_config_settings.xml
+++ b/timesheet_block/views/res_config_settings.xml
@@ -17,12 +17,12 @@