Created
April 14, 2017 01:44
-
-
Save raiderrobert/0968cad23d282885320986ecf478eab6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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