Skip to content

Commit

Permalink
fix: queries
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Oct 18, 2024
1 parent 64e8169 commit 2902c3b
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions uniticket/uni_ticket/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,28 +1200,26 @@ def get_ticket_per_structure(structure,
""" """
q_base = Q(office__organizational_structure=structure,
office__is_active=True)
q_follow = Q(follow=True) if follow_check else Q()

q_closed = Q()
if closed == True: q_closed = Q(ticket__is_closed=True)
elif closed == False: q_closed = Q(ticket__is_closed=False)
if follow_check:
q_base &= Q(follow=True)

q_taken = Q()
if taken == True: q_taken = Q(taken_date__isnull=False)
elif taken == False: q_taken = Q(taken_date__isnull=True)
if closed is not None:
q_base &= Q(ticket__is_closed=closed)

q_taken_by = Q(taken_by=taken_by) if taken_by else Q()
if taken is not None:
q_base &= Q(taken_date__isnull=not taken)

if taken_by:
q_base &= Q(taken_by=taken_by)

ordering_list = ["ticket__priority", "-ticket__created"]
if not priority_first:
ordering_list.remove("ticket__priority")

ticket_assignments = TicketAssignment.objects.filter(
q_base,
q_follow,
q_closed,
q_taken,
q_taken_by,
ticket_assignments = TicketAssignment.objects\
.filter(
q_base
).values_list("ticket__pk", flat=True)\
.order_by(*ordering_list)\
.distinct()
Expand Down

0 comments on commit 2902c3b

Please sign in to comment.