X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d7b89d3f41ba44a7f327652014e6baff6999f70e..f59de09387c7ceb7d6ab2ccf6ea25cb4be8dacb5:/src/annoy/models.py diff --git a/src/annoy/models.py b/src/annoy/models.py index 6af1cc045..638da5e86 100644 --- a/src/annoy/models.py +++ b/src/annoy/models.py @@ -120,20 +120,26 @@ class Banner(models.Model): return int(self.progress_percent) def update_progress(self): - # Total of new payments during the action. - # This definition will need to change for longer timespans. if not self.since or not self.until or not self.target: return Schedule = apps.get_model('club', 'Schedule') - self.progress = Schedule.objects.filter( - payed_at__gte=self.since, - payed_at__lte=self.until, - ).aggregate(c=models.Sum('amount'))['c'] + PayUOrder = apps.get_model('club', 'PayUOrder') + progress = PayUOrder.objects.filter( + completed_at__gte=self.since, + completed_at__lte=self.until, + ).aggregate(c=models.Sum('schedule__amount'))['c'] + + for schedule in Schedule.objects.filter( + method='paypal', + expires_at__gt=self.since + ): + progress += schedule.n_paypal_payments(self.since, self.until) * schedule.amount + self.progress = progress self.save(update_fields=['progress']) @classmethod def update_all_progress(cls): - for obj in cls.objects.exclude(target=None): + for obj in cls.objects.exclude(target=None).exclude(until__lt=now()): obj.update_progress()