Răsfoiți Sursa

Update project_task.py

erickabrego 9 luni în urmă
părinte
comite
728e124904
1 a modificat fișierele cu 9 adăugiri și 1 ștergeri
  1. 9 1
      custom_project/models/project_task.py

+ 9 - 1
custom_project/models/project_task.py

@@ -14,7 +14,15 @@ class ProjectTask(models.Model):
     def compute_days_duration(self):
         for rec in self:
             if rec.x_start_date and rec.x_end_date:
-                rec.x_days_duration = (rec.x_end_date - rec.x_start_date).days
+                days = (rec.x_end_date - rec.x_start_date).days
+                day_date = rec.x_start_date
+                duration = 0
+                for day in range(days + 1):
+                    weekday =  day_date.weekday()
+                    if weekday not in [5,6]:
+                        duration += 1
+                    day_date += timedelta(days=1)
+                rec.x_days_duration = duration
             else:
                 rec.x_days_duration = 0