update changes

This commit is contained in:
pawan.sharma 2022-08-31 14:21:25 +05:30
parent df0cc07911
commit 42e652ecd4
1 changed files with 30 additions and 15 deletions

View File

@ -41,7 +41,7 @@ class TimehseetBlock(models.Model):
current_date = datetime.today().date()
config = self.env['ir.config_parameter'].sudo()
config_days_limit = float(config.get_param('timesheet_block.timesheet_edit_create_limit'))
entry_start_date = datetime.strptime(values['start_datetime'],"%Y-%m-%d %H:%M:%S").date()
entry_start_date = datetime.strptime(str(values['start_datetime']),"%Y-%m-%d %H:%M:%S").date()
# entry_end_date = datetime.strptime(values['end_datetime'],"%Y-%m-%d %H:%M:%S").date()
days = (current_date - entry_start_date).days
employee_object = self.env['hr.employee'].search([('user_id', '=', self.env.uid)])
@ -63,7 +63,7 @@ class TimehseetBlock(models.Model):
current_date = datetime.today().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_start_date = datetime.strptime(record['start_datetime'],"%Y-%m-%d %H:%M:%S").date()
entry_start_date = datetime.strptime(str(record['start_datetime']),"%Y-%m-%d %H:%M:%S").date()
# entry_end_date = datetime.strptime(record['end_datetime'],"%Y-%m-%d %H:%M:%S").date()
else:
res_start_date = str(self.start_datetime).split('.', 1)[0]
@ -88,18 +88,33 @@ class TimehseetBlock(models.Model):
@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()
total_hours = (self.end_datetime - self.start_datetime).total_seconds() / 3600
self.unit_amount = total_hours
if start_date > end_date:
# @api.onchange('end_datetime' ,'start_datetime')
# def _check_end_datetime(self):
# if self.end_datetime and self.start_datetime:
# current_date = datetime.today().date()
# 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 end_date > current_date:
# self.end_datetime = False
# self.start_datetime = False
# raise AccessError('End date cannot be a future date!')
# if start_date > end_date:
# self.end_datetime = False
# self.start_datetime = False
# raise AccessError('End date should be greater than start date!')
@api.constrains('unit_amount')
def _check_unit_amount(self):
for rec in self:
if rec.unit_amount < 0.0:
raise AccessError('End date should be greater than start date!')
@api.constrains('end_datetime')
def _check_end_datetime(self):
current_date = datetime.today().date()
for rec in self:
if rec.end_datetime:
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!')