This commit is contained in:
mohammed-alkhazrji 2025-12-24 14:11:17 +03:00
parent 58e3de5283
commit 84b11de2a0
1 changed files with 11 additions and 4 deletions

View File

@ -140,10 +140,17 @@ class ProjectPhase(models.Model):
@api.constrains('start_date', 'end_date') @api.constrains('start_date', 'end_date')
def _check_dates(self): def _check_dates(self):
for rec in self: for rec in self:
if rec.filtered(lambda c: c.end_date and c.start_date > c.end_date): if rec.start_date and rec.end_date and rec.start_date > rec.end_date:
raise ValidationError(_('Phase start date must be earlier than Phase end date.')) raise ValidationError(_('Phase start date must be earlier than Phase end date.'))
if rec.project_id.start and rec.project_id.date and (rec.start_date < rec.project_id.start or rec.start_date > rec.project_id.date) or \
(rec.end_date < rec.project_id.start or rec.end_date > rec.project_id.date): project = rec.project_id
if not project.start or not project.date:
continue
if rec.start_date and (rec.start_date < project.start or rec.start_date > project.date):
raise ValidationError(_('Phase dates must be between project dates.'))
if rec.end_date and (rec.end_date < project.start or rec.end_date > project.date):
raise ValidationError(_('Phase dates must be between project dates.')) raise ValidationError(_('Phase dates must be between project dates.'))
def action_draft(self): def action_draft(self):