X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/65c9feda79d2b2c94cb7dcd561318a83fd796f0a..0a637ce4b427eb7376f3902ab0e51cf274a8b1da:/src/club/models.py diff --git a/src/club/models.py b/src/club/models.py index 1f47d587b..40a413849 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -1,3 +1,6 @@ +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from datetime import datetime, timedelta from django.conf import settings from django.contrib.sites.models import Site @@ -67,6 +70,7 @@ class Schedule(models.Model): amount = models.DecimalField(_('amount'), max_digits=10, decimal_places=2) method = models.CharField(_('method'), max_length=255, choices=[(method.slug, method.name) for method in methods]) is_cancelled = models.BooleanField(_('cancelled'), default=False) + payed_at = models.DateTimeField(_('payed at'), null=True, blank=True) started_at = models.DateTimeField(_('started at'), auto_now_add=True) expires_at = models.DateTimeField(_('expires_at'), null=True, blank=True) email_sent = models.BooleanField(default=False) @@ -102,7 +106,7 @@ class Schedule(models.Model): return self.expires_at is not None and self.expires_at <= now() def is_active(self): - return self.expires_at is not None and self.expires_at > now() + return self.payed_at is not None and (self.expires_at is None or self.expires_at > now()) def send_email(self): ctx = {'schedule': self} @@ -126,7 +130,7 @@ class Membership(models.Model): verbose_name_plural = _('memberships') def __str__(self): - return u'tow. ' + str(self.user) + return str(self.user) @classmethod def is_active_for(cls, user): @@ -200,8 +204,12 @@ class PayUOrder(payu_models.Order): def status_updated(self): if self.status == 'COMPLETED': - since = self.schedule.expires_at or now() + since = self.schedule.expires_at + if since is None or since < self.received_at: + since = self.received_at new_exp = self.schedule.plan.get_next_installment(since) + if self.schedule.payed_at is None: + self.schedule.payed_at = self.received_at if self.schedule.expires_at is None or self.schedule.expires_at < new_exp: self.schedule.expires_at = new_exp self.schedule.save()