diff --git a/project/customer/models.py b/project/customer/models.py index 6af77f3..15d65d1 100644 --- a/project/customer/models.py +++ b/project/customer/models.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import os +from datetime import datetime from PIL import Image from pytils import numeral @@ -386,6 +387,7 @@ class License(models.Model): def get_email(self): return self.user.email + def get_action(self): if self.status == 0: if self.payform == 0: @@ -399,11 +401,51 @@ class License(models.Model): else: return '' + def get_term(self): + if self.term == 0: + return u'45 дней' + else: + return u'%s %s' % (self.term, + numeral.choose_plural(self.term, u"месяц, месяца, месяцев"), + ) + + def get_action(self): + if self.status == -1: + return '' + if self.status == 0: + if self.payform == 0: + #return reverse() + return u'Скачать счёт' + elif self.payform == 1: + return u'Оплатить счёт' + elif self.payform == 2: + return u'Скачать квитанцию' + if self.status == 1: + return u'История операций' + else: + return '' + def get_paid_status(self): if self.status == 1: return u'Лицензия оплачена, ещё не активирована' - elif self.status == 2: - return u'Лицензия оплачена: осталось %d дней.' + elif self.status in [2, -1]: + left = relativedelta(self.date_to, datetime.today()) + if left.months: + left_str = '%d %s %d %s' % (left.months, + numeral.choose_plural(left.months, u"месяц, месяца, месяцев"), + left.days, + numeral.choose_plural(left.days, u"день, дня, дней"), + ) + else: + left_str = '%d %s' % ( + left.days, + numeral.choose_plural(left.days, u"день, дня, дней"), + ) + return u'Лицензия активирована: осталось %s' % left_str + elif self.status == 3: + return u'Время истекло' + else: + return None class LicensePrice(models.Model): diff --git a/project/customer/tasks.py b/project/customer/tasks.py index 221890c..3a2a644 100644 --- a/project/customer/tasks.py +++ b/project/customer/tasks.py @@ -20,5 +20,8 @@ def check_license(): profile.save() licenses.filter(status=1).update(status=2) + licenses = License.objects.filter(user=profile.user, date_to__lt=now, status__in=[-1, 2]) + licenses.update(status=3) + return None diff --git a/project/customer/views/license.py b/project/customer/views/license.py index 6ff6b31..9935884 100644 --- a/project/customer/views/license.py +++ b/project/customer/views/license.py @@ -57,7 +57,7 @@ def license_list(request): """Список счетов на лицензии """ template_name = 'customer/profile/license_list.html' - licenses = License.objects.filter(user=request.user, deleted=False).order_by('-id') + licenses = License.objects.filter(user=request.user, deleted=False, status__gt=-1).order_by('-id') dictionary = { 'licenses': licenses, } diff --git a/project/static/css/style.css b/project/static/css/style.css index b5e1bd9..d0cb266 100644 --- a/project/static/css/style.css +++ b/project/static/css/style.css @@ -203,5 +203,6 @@ table.list td { word-break: break-all; padding: 5px 0; } /* blockUI */ div.blockOverlay { background: url('../img/ajax-loader.gif') no-repeat center center; z-index: 99999; } div.blockMsg { width: 100%; height: 100%; top: 0; left: 0; text-align: center; } -.w100 {width:100px;} -.w200 {width:200px;} +.w100 {width:100px;min-height:5px;} +.w200 {width:200px;min-height:5px;} +.header {font-weight:bold; } diff --git a/project/templates/customer/profile/license_list.html b/project/templates/customer/profile/license_list.html index 11a9a75..e973a67 100644 --- a/project/templates/customer/profile/license_list.html +++ b/project/templates/customer/profile/license_list.html @@ -1,16 +1,28 @@ {% extends "base.html" %} {% load pytils_numeral %} -{% block title %}Купить лицензию{% endblock %} +{% block title %}Мои счета{% endblock %} {% block content %} Купить лицензию

Оплаченные лицензии

Выписанные счета

+
+
Номер
+
Дата счёта
+
Срок лицензии
+
Сумма
+
Вид платежа
+
Статус
+
Действия
+
Отменить заявку
+
+
{% for license in licenses %}
{{ license.id }}
{{ license.order_date }}
-
{{ license.term }}
+
{{ license.get_term }}
+
{{ license.pay_sum|get_plural:"рубль,рубля,рублей" }}
{{ license.get_payform_display }}
{{ license.get_status_display }}
{{ license.get_action }}
diff --git a/project/templates/customer/profile/paid_list.html b/project/templates/customer/profile/paid_list.html index 9d58da1..3f5ae6d 100644 --- a/project/templates/customer/profile/paid_list.html +++ b/project/templates/customer/profile/paid_list.html @@ -1,19 +1,30 @@ {% extends "base.html" %} {% load pytils_numeral %} -{% block title %}Купить лицензию{% endblock %} +{% block title %}История расчётов{% endblock %} {% block content %} Купить лицензию

Все счета

История оплат

+
+
Дата оплаты
+
По счёту
+
Сумма
+
Срок лицензии
+
Период действия лицензии
+
Статус лицензии
+
Закрывающие документы
+
+
{% for license in licenses %}
-
{{ license.paid_date }}
+
{{ license.paid_date|default:license.date_from }}
{{ license.id }}
{{ license.pay_sum }}
-
{{ license.term }}
+
{{ license.get_term }}
{{ license.date_from }} - {{ license.date_to }}
-
{{ license.get_status_display }}
+
{{ license.get_status_display }}
{{ license.get_paid_status|default:'' }}
+
Разные документы
{% endfor %}