Skip to content

Commit

Permalink
Merge pull request #143 from vtemian/none-on-missing-subtasks
Browse files Browse the repository at this point in the history
Allow updating task's total progress, for tasks without any children
  • Loading branch information
KrzysztofMadejski authored Mar 8, 2020
2 parents 1d77c1f + baf9746 commit d03b965
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion moonsheep/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import psycopg2
from django.db import connections
from django.db.models import F, Avg, Count
from django.db.models.functions import Coalesce

from moonsheep import models
from moonsheep.models import Task
Expand Down Expand Up @@ -31,7 +32,7 @@ def update_total_progress(task: models.Task):
else:
# own_progress == 100, so there might be subtasks
subtasks = Task.objects.filter(parent=task) \
.aggregate(average_progress=Avg('total_progress'), count=Count('id'))
.aggregate(average_progress=Coalesce(Avg('total_progress'), 0), count=Count('id'))

task.total_progress = Decimal(
subtasks['average_progress'] * subtasks['count'] + 100) / (
Expand Down

0 comments on commit d03b965

Please sign in to comment.