You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
58 lines
1.7 KiB
# coding=utf-8
|
|
from django.db.models import Q
|
|
import datetime
|
|
from finance.models import Bill, Price
|
|
from courses.models import CourseMap
|
|
|
|
|
|
def system_check_bill(token, user, theme_type='B'):
|
|
if user.is_admin:
|
|
return True
|
|
|
|
# Проверка счета, как подписки
|
|
__point = CourseMap.objects.get(token=token)
|
|
course = __point.course
|
|
if user in course.teachers.all():
|
|
return True
|
|
|
|
prices = Price.objects.filter(included=__point).values_list('id', flat=True)
|
|
for b in Bill.objects.filter(service__id__in=prices, user=user, status='F'):
|
|
if b:
|
|
if b.service.by_time:
|
|
if b.finish_date + datetime.timedelta(days=b.service.by_time) > datetime.datetime.now():
|
|
return True
|
|
else:
|
|
return False
|
|
else:
|
|
return True
|
|
|
|
m_type = []
|
|
if theme_type == 'B' or theme_type == 'M':
|
|
m_type = ['B', 'E', 'P']
|
|
|
|
elif theme_type == 'E':
|
|
m_type = ['E', 'P']
|
|
|
|
elif theme_type == 'P':
|
|
m_type = ['P']
|
|
|
|
if m_type:
|
|
bill = Bill.objects.filter(service__included=None, service__course=course, user=user, status='F', service__m_type__in=m_type)
|
|
if bill.exists():
|
|
check = []
|
|
for b in bill:
|
|
if b.service.by_time:
|
|
check.append(b)
|
|
if not check:
|
|
return True
|
|
|
|
else:
|
|
result = False
|
|
for b in check:
|
|
if b.finish_date + datetime.timedelta(days=b.service.by_time) > datetime.datetime.now():
|
|
result = True
|
|
if result:
|
|
return True
|
|
else:
|
|
return False
|
|
return False
|
|
|