Permalink
Browse files

Merge pull request #42 from jespino/master

Fixing recalculation of user stories status changes
  • Loading branch information...
jespino committed May 29, 2012
2 parents 96fbfb0 + 9d7b1d1 commit 822e2df021c5b0906db2cdcd31de2c9ee24941c1
Showing with 22 additions and 11 deletions.
  1. +15 −0 src/greenmine/models.py
  2. +1 −11 src/greenmine/views/api.py
  3. +6 −0 src/greenmine/views/main.py
View
@@ -640,6 +640,21 @@ def tasks_completed(self):
def tasks_closed(self):
return self.tasks.filter(status__in=['workaround', 'needinfo','closed', 'posponed'])
+ def update_status(self):
+ total_tasks_count = self.tasks.count()
+
+ if total_tasks_count == 0:
+ self.status = 'open'
+ elif self.tasks.filter(status__in=['closed','completed']).count() == total_tasks_count:
+ self.status = 'completed'
+ elif self.tasks.filter(status='open').count() == total_tasks_count:
+ self.status = 'open'
+ else:
+ self.status = 'progress'
+
+ self.modified_date = timezone.now()
+ self.save()
+
class Change(models.Model):
change_type = models.IntegerField(choices=TASK_CHANGE_CHOICES)
View
@@ -139,17 +139,7 @@ def post(self, request, pslug, taskref):
# Automatic control of user story status.
for us in set(us_for_update):
- total_tasks_count = us.tasks.count()
-
- if us.tasks.filter(status__in=['closed','completed']).count() == total_tasks_count:
- us.status = 'completed'
- elif us.tasks.filter(status='open').count() == total_tasks_count:
- us.status = 'open'
- else:
- us.status = 'progress'
-
- us.modified_date = now()
- us.save()
+ us.update_status()
return self.render_to_ok()
@@ -1337,6 +1337,7 @@ def post(self, request, pslug, tref):
next_url = request.GET.get('next', None)
_old_assigned_to_pk = task.assigned_to.pk if task.assigned_to else None
+ _old_us = task.user_story
if form.is_valid():
task = form.save(commit=True)
@@ -1345,6 +1346,11 @@ def post(self, request, pslug, tref):
if task.assigned_to and task.assigned_to.pk != _old_assigned_to_pk:
signals.mail_task_assigned.send(sender=self, task=task, user=request.user)
+ if _old_us and not task.user_story:
+ _old_us.update_status()
+ elif not _old_us and task.user_story:
+ task.user_story.update_status()
+
messages.info(request, _(u"The task has been saved!"))
if next_url:
return self.render_redirect(next_url)

0 comments on commit 822e2df

Please sign in to comment.