license: use order_status

remotes/origin/license
Andrey 9 years ago
parent fedade8bfc
commit f603c110cf
  1. 3
      project/customer/consts.py
  2. 21
      project/customer/context_processors.py
  3. 10
      project/customer/models.py
  4. 10
      project/customer/utils.py

@ -30,11 +30,8 @@ LICENSE_TERMS = (
) + TERMS
LICENSE_TEST_PERIOD = -1
LICENSE_UNPAID = 0
LICENSE_PAID = 1
LICENSE_ACTIVE = 2
LICENSE_EXPIRED = 3
LICENSE_SUSPENDED = 4
LICENSE_STATUSES = (
(LICENSE_TEST_PERIOD, u'Пробный период'),

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from django.db.models import Q
from django.core.cache import cache
from django.conf import settings
@ -25,13 +26,11 @@ def license_check_soon_ends(request):
now_ = datetime.today()
if not days_left or not cur_license:
current_licenses = License.objects.filter(
company=request.user.profile,
date_from__lte=now_,
date_to__gte=now_,
status__in=[consts.LICENSE_TEST_PERIOD, consts.LICENSE_PAID, consts.LICENSE_ACTIVE],
deleted=False
current_licenses = (License.objects
.filter(company=request.user.profile, date_from__lte=now_, date_to__gte=now_, deleted=False)
.filter(Q(status__in = [consts.LICENSE_TEST_PERIOD, consts.LICENSE_ACTIVE]) | Q(order_status=consts.ORDER_PAID))
)
if current_licenses:
cur_license = current_licenses[0]
days_left = (cur_license.date_to - now_.date()).days
@ -40,14 +39,12 @@ def license_check_soon_ends(request):
if not license_cookie:
if license_15days is None:
licenses_ends = License.objects.filter(
company=request.user.profile,
date_to__lte = now_ + timedelta(days=consts.LICENSE_DAYS_BEFORE_EXPIRE),
status__in=[consts.LICENSE_TEST_PERIOD, consts.LICENSE_PAID, consts.LICENSE_ACTIVE],
deleted=False
licenses_ends = (License.objects
.filter(company=request.user.profile, date_to__lte = now_ + timedelta(days=consts.LICENSE_DAYS_BEFORE_EXPIRE), deleted=False)
.filter(Q(status__in = [consts.LICENSE_TEST_PERIOD, consts.LICENSE_ACTIVE]) | Q(order_status=consts.ORDER_PAID))
)
next_licenses = License.objects.filter(company=request.user.profile, status=consts.LICENSE_PAID, deleted=False)
next_licenses = License.objects.filter(company=request.user.profile, order_status=consts.ORDER_PAID, deleted=False)
if licenses_ends and not next_licenses:
days_to_end = licenses_ends[0].date_to

@ -415,11 +415,15 @@ class UserProfileFilters(models.Model):
class License(models.Model):
company = models.ForeignKey(UserProfile, related_name='licenses', verbose_name=u'пользователь')
term = models.IntegerField(u'срок лицензии', choices=consts.LICENSE_TERMS)
date_from = models.DateField(u'дата начала', null=True, blank=True)
date_to = models.DateField(u'дата окончания', null=True, blank=True)
payform = models.IntegerField(u'форма оплаты', choices=consts.PAYFORMS, default=consts.PAYFORM_BEZNAL)
status = models.IntegerField(u'статус лицензии', choices=consts.LICENSE_STATUSES, blank=True, null=True, default=None)
order_status = models.IntegerField(u'статус заказа', choices=consts.ORDER_STATUSES, blank=True, null=True, default=None)
order_date = models.DateField(u'дата заказа', auto_now_add=True)
paid_date = models.DateField(u'дата оплаты', null=True, blank=True)
@ -462,7 +466,7 @@ class License(models.Model):
# если `дата оплаты` задана только что
if not self.__prev_paid_date and self.paid_date:
self.set_period(now_)
self.status = consts.LICENSE_PAID
self.order_status = consts.ORDER_PAID
super(License, self).save(*args, **kwargs)
@ -484,7 +488,7 @@ class License(models.Model):
self.date_to = self.date_from + relativedelta(months=self.term, days=-1)
def set_paid(self):
self.status = consts.LICENSE_PAID
self.order_status = consts.ORDER_PAID
def get_company(self):
return self.company.get_company_name()
@ -514,7 +518,7 @@ class License(models.Model):
return u'%s %s' % (self.term, numeral.choose_plural(self.term, u"месяц, месяца, месяцев"),)
def get_paid_status(self):
if self.status == consts.LICENSE_PAID:
if self.order_status == consts.ORDER_PAID:
return u'Лицензия оплачена, ещё не активирована'
elif self.status in [consts.LICENSE_ACTIVE, consts.LICENSE_TEST_PERIOD]:

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import timedelta
from django.db.models import Q
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from django.conf import settings
@ -14,10 +15,11 @@ SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL')
def check_one_profile(profile, License, now_, manual=False):
profile_was_active = profile.active
licenses = License.objects.filter(company=profile, date_from__lte=now_, date_to__gte=now_,
status__in=[consts.LICENSE_TEST_PERIOD, consts.LICENSE_PAID, consts.LICENSE_ACTIVE], deleted=False)
licenses = (License.objects.filter(company=profile, date_from__lte=now_, date_to__gte=now_, deleted=False)
.filter(Q(status__in = [consts.LICENSE_TEST_PERIOD, consts.LICENSE_ACTIVE]) | Q(order_status=consts.ORDER_PAID))
)
licenses.filter(status=consts.LICENSE_PAID).update(status=consts.LICENSE_ACTIVE)
licenses.filter(order_status=consts.ORDER_PAID).update(status=consts.LICENSE_ACTIVE)
profile.active = False
if licenses:
@ -43,7 +45,7 @@ def check_one_profile(profile, License, now_, manual=False):
if not manual:
licenses_remain = License.objects.filter(company=profile, date_from__gt = now_ + timedelta(days=1),
status=consts.LICENSE_PAID, deleted=False)
order_status=consts.ORDER_PAID, deleted=False)
if not licenses_remain:
licenses_to_pay = License.objects.filter(company=profile, order_status=consts.ORDER_UNPAID, deleted=False)

Loading…
Cancel
Save