Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raiderrobert/0968cad23d282885320986ecf478eab6 to your computer and use it in GitHub Desktop.
Save raiderrobert/0968cad23d282885320986ecf478eab6 to your computer and use it in GitHub Desktop.
def need_approval(self):
queryset = self
queryset = queryset.annotate(
conflict_group=Concat(
'employee_id', Value('|'), 'date_applied',
output_field=models.CharField()
),
paycode_count=Count('codes')
)
conflicts = queryset.values('conflict_group').annotate(
conflicts=Count('conflict_group'),
not_approved=Sum(
Case(
When(
reviewed=False,
then=Value(1)
),
default=Value(0),
output_field=models.PositiveIntegerField()
),
),
).filter(conflicts__gte=2, not_approved__gte=1).values_list('conflict_group', flat=True)
queryset = queryset.filter(
Q(codes__source='EXT')|Q(~Q(codes__code=TimeEntryCode.WORKED, paycode_count=1), reviewed=False)|Q(conflict_group__in=conflicts)
)
return queryset.order_by('conflict_group').select_related('employee', 'source').prefetch_related('codes')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment