diff --git a/project/customer/consts.py b/project/customer/consts.py index 5ad6e31..84ec917 100644 --- a/project/customer/consts.py +++ b/project/customer/consts.py @@ -18,7 +18,8 @@ TERMS = ( # лицензии -LICENSE_PAY_DAYS = 10 # дней на оплату счёта +ORDER_PAY_DAYS = 10 # дней на оплату счёта + LICENSE_DAYS_BEFORE_EXPIRE = 15 # осталось N дней до конца лицензии. чтобы предупреждать юзера о необходимости продления LICENSE_TEST_PERIOD_TERM = 0 # тип срока: пробный период. это особый тип, никак не связанный с моделью LicensePrice diff --git a/project/customer/models.py b/project/customer/models.py index e84ab23..6d4b5be 100644 --- a/project/customer/models.py +++ b/project/customer/models.py @@ -487,7 +487,8 @@ class License(models.Model): return self.company.get_company_name() def get_action_link(self): - if self.status == consts.LICENSE_UNPAID: + if self.order_status == consts.ORDER_UNPAID: + if self.payform == consts.PAYFORM_BEZNAL: return u'Скачать счёт' % reverse('customer_license_get_doc', kwargs={'order_num': self.id}) @@ -497,7 +498,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.status in [consts.LICENSE_PAID, consts.LICENSE_ACTIVE]: + elif self.order_status == consts.ORDER_PAID: # or self.status in [consts.LICENSE_ACTIVE] return u'История операций' else: diff --git a/project/customer/tasks.py b/project/customer/tasks.py index d67d58c..ef9f561 100644 --- a/project/customer/tasks.py +++ b/project/customer/tasks.py @@ -17,13 +17,12 @@ def check_license(): profiles = UserProfile.objects.all() now_ = datetime.today() - #licenses = License.objects.filter(date_to__lt=now_, status__in=[consts.LICENSE_TEST_PERIOD, consts.LICENSE_ACTIVE], deleted=False) - #licenses.update(status=consts.LICENSE_EXPIRED) + licenses = License.objects.filter(order_date__lte = now_ - timedelta(days=consts.ORDER_PAY_DAYS), + order_status=consts.ORDER_UNPAID, deleted=False) - licenses = License.objects.filter(order_date__lte = now_ - timedelta(days=consts.LICENSE_PAY_DAYS), - status=consts.LICENSE_UNPAID, deleted=False) - - licenses.update(status=consts.LICENSE_SUSPENDED) + # + # TODO + licenses.update(order_status=consts.ORDER_SUSPENDED) for profile in profiles: try: diff --git a/project/customer/utils.py b/project/customer/utils.py index 4f1b4ed..8c21f31 100644 --- a/project/customer/utils.py +++ b/project/customer/utils.py @@ -46,7 +46,7 @@ def check_one_profile(profile, License, now_, manual=False): status=consts.LICENSE_PAID, deleted=False) if not licenses_remain: - licenses_to_pay = License.objects.filter(company=profile, status=consts.LICENSE_UNPAID, deleted=False) + licenses_to_pay = License.objects.filter(company=profile, order_status=consts.ORDER_UNPAID, deleted=False) licenses = License.objects.filter(company=profile, date_to__lt=now_, status__in=[consts.LICENSE_TEST_PERIOD, consts.LICENSE_ACTIVE], deleted=False) @@ -82,8 +82,8 @@ def check_one_profile(profile, License, now_, manual=False): email = EmailMessage(subject=subject, to=(user_email,), body=email_body) email.send() - licenses = License.objects.filter(company=profile, order_date = now_ - timedelta(days = consts.LICENSE_PAY_DAYS - 1), - status=consts.LICENSE_UNPAID, deleted=False) + licenses = License.objects.filter(company=profile, order_date = now_ - timedelta(days = consts.ORDER_PAY_DAYS - 1), + order_status=consts.ORDER_UNPAID, deleted=False) if licenses: template_name = 'myauth/license_to_pay.txt' diff --git a/project/customer/views/license.py b/project/customer/views/license.py index 25b105e..bd4db4e 100644 --- a/project/customer/views/license.py +++ b/project/customer/views/license.py @@ -10,6 +10,7 @@ from django.contrib.auth.decorators import login_required from django.template.response import TemplateResponse from django.core.urlresolvers import reverse from django.views.decorators.csrf import csrf_protect +from django.db.models import Q from django.conf import settings from yandex_money.models import Payment @@ -111,17 +112,13 @@ def paid_list(request): template_name = 'customer/profile/paid_list.html' - licenses = License.objects.filter( - company=request.user.profile, - status__in = [ - consts.LICENSE_TEST_PERIOD, - consts.LICENSE_PAID, - consts.LICENSE_ACTIVE, - consts.LICENSE_EXPIRED, - consts.LICENSE_SUSPENDED, - ], - deleted=False - ).order_by('-id') + # 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])) + .order_by('-id') + ) return render(request, template_name, {'licenses': licenses}) @@ -134,7 +131,8 @@ def delete_license(request, pk): raise_if_no_profile(request) try: - license = License.objects.get(pk=pk, status=consts.LICENSE_UNPAID, company=request.user.profile) + license = License.objects.get(pk=pk, company=request.user.profile, + order_status=consts.ORDER_UNPAID, payform__gt=consts.PAYFORM_FREE) if request.method == 'POST': license.deleted = True license.save() diff --git a/project/templates/customer/profile/license_list.html b/project/templates/customer/profile/license_list.html index cbe2d8f..05f509d 100644 --- a/project/templates/customer/profile/license_list.html +++ b/project/templates/customer/profile/license_list.html @@ -26,7 +26,8 @@