From df266afd4eb5a311140c89d28748dba771d93c65 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 22 Apr 2017 18:47:27 +0300 Subject: [PATCH] license: moved test period from status to payform; adjusted code --- project/customer/consts.py | 16 ++++++++++------ project/customer/managers.py | 4 ++-- project/customer/models.py | 12 +++++++----- project/customer/views/license.py | 12 +++++------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/project/customer/consts.py b/project/customer/consts.py index d9caf12..2596fc6 100644 --- a/project/customer/consts.py +++ b/project/customer/consts.py @@ -29,13 +29,13 @@ LICENSE_TERMS = ( (LICENSE_TEST_PERIOD_TERM, u'%s дней' % LICENSE_TEST_PERIOD_DAYS), ) + TERMS -LICENSE_TEST_PERIOD = -1 +LICENSE_INACTIVE = 1 LICENSE_ACTIVE = 2 LICENSE_EXPIRED = 3 LICENSE_STATUSES = ( - (LICENSE_TEST_PERIOD, u'Пробный период'), - (LICENSE_ACTIVE, u'Активирован'), + (LICENSE_INACTIVE, u'Ожидает активации'), + (LICENSE_ACTIVE, u'Активирована'), (LICENSE_EXPIRED, u'Срок действия истёк'), ) @@ -49,18 +49,22 @@ ORDER_STATUSES = ( (ORDER_SUSPENDED, u'Заморожен'), ) -PAYFORM_FREE = -1 +# бесплатные +PAYFORM_BONUS_PREPAID = -2 +PAYFORM_TEST_PERIOD = -1 +# платные PAYFORM_BEZNAL = 0 PAYFORM_CARD = 1 PAYFORM_SBER_KVITANZ = 2 # все возможные формы оплаты (для админки) PAYFORMS = ( - (PAYFORM_FREE, u'Бесплатно'), + (PAYFORM_BONUS_PREPAID, u'Бонус за предоплату'), + (PAYFORM_TEST_PERIOD, u'Пробный период'), (PAYFORM_BEZNAL, u'Безналичный расчёт'), (PAYFORM_CARD, u'Банковская карта'), # (PAYFORM_SBER_KVITANZ, u'Квитанция Сбербанка'), ) # отдельные формы оплаты для показа пользователям в форме покупки лицензии. бесплатные формы оплаты отбрасываются -LICENSEFORM_PAYFORMS = tuple(x for x in PAYFORMS if x[0] > PAYFORM_FREE) +LICENSEFORM_PAYFORMS = tuple(x for x in PAYFORMS if x[0] > PAYFORM_TEST_PERIOD) diff --git a/project/customer/managers.py b/project/customer/managers.py index 831686d..a490a8f 100644 --- a/project/customer/managers.py +++ b/project/customer/managers.py @@ -85,8 +85,8 @@ class LicenseManager(models.Manager): date_from = now_.today(), date_to = now_.today() + relativedelta(days = consts.LICENSE_TEST_PERIOD_DAYS - 1), term=consts.LICENSE_TEST_PERIOD_TERM, - status=consts.LICENSE_TEST_PERIOD, - payform=consts.PAYFORM_FREE + status=consts.LICENSE_INACTIVE, + payform=consts.PAYFORM_TEST_PERIOD ) license.save() return license diff --git a/project/customer/models.py b/project/customer/models.py index daf1224..e79de91 100644 --- a/project/customer/models.py +++ b/project/customer/models.py @@ -466,17 +466,18 @@ class License(models.Model): self.suspend_date = _now_.date() # TODO maybe raise ValidationError? # бесплатные лицензии - if self.payform in [consts.PAYFORM_FREE,]: + if self.payform in [consts.PAYFORM_TEST_PERIOD, consts.PAYFORM_BONUS_PREPAID]: # только если ещё не задана `дата начала` if not self.date_from: self.set_period(now_) + self.status = consts.LICENSE_INACTIVE # платные лицензии elif self.payform in [consts.PAYFORM_BEZNAL, consts.PAYFORM_CARD,]: # если `дата оплаты` задана только что if not self.__prev_paid_date and self.paid_date: self.set_period(now_) - self.order_status = consts.ORDER_PAID + self.set_paid() super(License, self).save(*args, **kwargs) @@ -499,6 +500,7 @@ class License(models.Model): def set_paid(self): self.order_status = consts.ORDER_PAID + self.status = consts.LICENSE_INACTIVE def get_company(self): return self.company.get_company_name() @@ -515,7 +517,7 @@ class License(models.Model): elif self.payform == consts.PAYFORM_SBER_KVITANZ: # не используется. однако могут быть старые лицензии с данной формой оплаты return u'Скачать квитанцию' % reverse('customer_license_get_doc', kwargs={'order_num': self.id}) - elif self.order_status == consts.ORDER_PAID: # or self.status in [consts.LICENSE_ACTIVE] + elif self.order_status == consts.ORDER_PAID or self.status == consts.LICENSE_ACTIVE: return u'История операций' else: @@ -528,10 +530,10 @@ class License(models.Model): return u'%s %s' % (self.term, numeral.choose_plural(self.term, u"месяц, месяца, месяцев"),) def get_paid_status(self): - if self.order_status == consts.ORDER_PAID: + if self.status == consts.LICENSE_INACTIVE and self.order_status == consts.ORDER_PAID: return u'Лицензия оплачена, ещё не активирована' - elif self.status in [consts.LICENSE_ACTIVE, consts.LICENSE_TEST_PERIOD]: + elif self.status == consts.LICENSE_ACTIVE: left = relativedelta(self.date_to, datetime.today()) if left.months: left_str = u'%d %s %d %s' % ( diff --git a/project/customer/views/license.py b/project/customer/views/license.py index bd4db4e..c162f84 100644 --- a/project/customer/views/license.py +++ b/project/customer/views/license.py @@ -92,14 +92,13 @@ def order_license(request): @login_required def license_list(request): - """Список счетов на лицензии + """Список лицензий """ raise_if_no_profile(request) template_name = 'customer/profile/license_list.html' - # TODO maybe explicitly list license statuses? - licenses = License.objects.filter(company=request.user.profile, status__gt=consts.LICENSE_TEST_PERIOD, deleted=False).order_by('-id') + licenses = License.objects.filter(company=request.user.profile, deleted=False).order_by('-id') return render(request, template_name, {'licenses': licenses}) @@ -112,11 +111,9 @@ def paid_list(request): template_name = 'customer/profile/paid_list.html' - # TODO почему в оплаченных лицензиях выводится пробный период и замороженные? licenses = (License.objects .filter(company=request.user.profile, deleted=False) - .filter(Q(status__in = [consts.LICENSE_TEST_PERIOD, consts.LICENSE_ACTIVE, consts.LICENSE_EXPIRED]) | - Q(order_status__in=[consts.ORDER_PAID, consts.ORDER_SUSPENDED])) + .filter(order_status__in=[consts.ORDER_PAID, consts.ORDER_SUSPENDED]) .order_by('-id') ) @@ -131,8 +128,9 @@ def delete_license(request, pk): raise_if_no_profile(request) try: + # можно удалить только если счёт не оплачен и у него не бесплатная форма оплаты license = License.objects.get(pk=pk, company=request.user.profile, - order_status=consts.ORDER_UNPAID, payform__gt=consts.PAYFORM_FREE) + order_status=consts.ORDER_UNPAID, payform__gt=consts.PAYFORM_TEST_PERIOD) if request.method == 'POST': license.deleted = True license.save()