You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
1.1 KiB
Python

from billing.models import *
from osinacore.models import *
from customercore.models import *
from django.db.models import Count, Q
def utilities(request):
active_subscriptions = None
customer_open_tickets = None
if request.user.is_authenticated and CustomerProfile.objects.filter(user=request.user):
customer = request.user.customerprofile
active_subscriptions = OrderItem.objects.filter(active=True, order__customer=customer)
customer_open_tickets = Ticket.objects.filter(
Q(status__in=['Open', 'Working On']) & Q(customer=request.user.customerprofile)
).order_by('-id')
for ticket in customer_open_tickets:
unread_updates_count = 0
for ticket_update in ticket.ticketupdate_set.exclude(added_by=request.user):
if not TicketRead.objects.filter(ticket_update=ticket_update, user=request.user, read=True).exists():
unread_updates_count += 1
ticket.unread_updates_count = unread_updates_count
return {'active_subscriptions': active_subscriptions, 'customer_open_tickets': customer_open_tickets}