license: use order status

remotes/origin/license
Andrey 9 years ago
parent 877cedf058
commit 05ffbe65db
  1. 3
      project/customer/consts.py
  2. 5
      project/customer/models.py
  3. 11
      project/customer/tasks.py
  4. 6
      project/customer/utils.py
  5. 22
      project/customer/views/license.py
  6. 3
      project/templates/customer/profile/license_list.html

@ -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

@ -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'<a href="%s">Скачать счёт</a>' % 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'<a href="%s">Скачать квитанцию</a>' % 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:

@ -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:

@ -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'

@ -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()

@ -26,7 +26,8 @@
<td>{{ license.get_payform_display }}</td>
<td>{{ license.get_status_display }}</td>
<td>{{ license.get_action_link|safe }}</td>
<td>{% if license.status == 0 %}<a href='#' class='delete_license' data-id='{{ license.pk }}'>Удалить</a>{% endif %}</td>
{# можно удалить только если счёт не оплачен и у него не бесплатная форма оплаты #}
<td>{% if license.order_status == 0 and license.payform > -1 %}<a href='#' class='delete_license' data-id='{{ license.pk }}'>Удалить</a>{% endif %}</td>
</tr>
{% endfor %}
</table>

Loading…
Cancel
Save