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

@ -136,14 +136,21 @@ class ProjectPhase(models.Model):
progress = ((sum([x.weight * x.task_progress for x in done_task])) / 100)
# progress = round(100.0 * float((len(done_task) / len(rec.task_ids))), 2)
rec.progress = progress
@api.constrains('start_date', 'end_date')
def _check_dates(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.'))
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.'))
def action_draft(self):