add domain for only start date

This commit is contained in:
pawan.sharma 2022-08-31 14:34:41 +05:30
parent 42e652ecd4
commit 5cf7fdf87c
2 changed files with 24 additions and 14 deletions

View File

@ -329,16 +329,24 @@ class InheritProjectProductEmployeeMap(models.Model):
@api.constrains('start_date', 'end_date')
def _check_dates(self):
for val in self:
if val.end_date and val.start_date:
if val.end_date < val.start_date:
raise ValidationError(_('Start date must be earlier than end date.'))
domain = [
('start_date', '<=', val.end_date),
('end_date', '>=', val.start_date),
('project_id', '=', val.project_id.id),
('employee_id', '=', val.employee_id.id),
('id', '!=', val.id)
]
if val.start_date:
if val.end_date:
if val.end_date < val.start_date:
raise ValidationError(_('Start date must be earlier than end date.'))
domain = [
('start_date', '<=', val.end_date),
('end_date', '>=', val.start_date),
('project_id', '=', val.project_id.id),
('employee_id', '=', val.employee_id.id),
('id', '!=', val.id)
]
else:
domain = [
('end_date', '>=', val.start_date),
('project_id', '=', val.project_id.id),
('employee_id', '=', val.employee_id.id),
('id', '!=', val.id)
]
res = self.search_count(domain)
if res > 0:
raise ValidationError(_('Same Consultant can not have 2 same date that overlaps on same day!'))

View File

@ -30,6 +30,12 @@ class ProjectResourceWizard(models.TransientModel):
def action_add_project_lines(self):
record = self.env['project.sale.line.employee.map']
for val in self.add_project_resource:
############
if self.project_id.sale_line_employee_ids:
for emp in self.project_id.sale_line_employee_ids:
if emp.employee_id == val.employee_id and emp.end_date == False and val.start_date:
emp.write({'end_date': val.start_date - relativedelta.relativedelta(days=1)})
#################
values = {
'project_id': self.project_id.id,
'employee_id': val.employee_id.id,
@ -44,10 +50,6 @@ class ProjectResourceWizard(models.TransientModel):
if self.project_id.hour_distribution == 'Percentage':
values.update({'distribution_per': val.distribution_per})
record.create(values)
############
for emp in self.project_id.sale_line_employee_ids:
if emp.employee_id == val.employee_id and emp.end_date == False and val.start_date:
emp.write({'end_date': val.start_date - relativedelta.relativedelta(days=1)})
return True