Fix BuildLineFilter.filter_allocated
- Required for mysql backend
This commit is contained in:
parent
ec845c61cd
commit
7102ea4d6e
|
|
@ -494,9 +494,23 @@ class BuildLineFilter(FilterSet):
|
|||
|
||||
def filter_allocated(self, queryset, name, value):
|
||||
"""Filter by whether each BuildLine is fully allocated."""
|
||||
allocated_subquery = (
|
||||
BuildItem.objects
|
||||
.filter(build_line=OuterRef('pk'))
|
||||
.values('build_line')
|
||||
.annotate(total=Sum('quantity'))
|
||||
.values('total')
|
||||
)
|
||||
|
||||
queryset = queryset.alias(
|
||||
allocated_quantity=Coalesce(Subquery(allocated_subquery), 0)
|
||||
)
|
||||
|
||||
if str2bool(value):
|
||||
return queryset.filter(allocated__gte=F('quantity') - F('consumed'))
|
||||
return queryset.filter(allocated__lt=F('quantity') - F('consumed'))
|
||||
return queryset.filter(
|
||||
allocated_quantity__gte=F('quantity') - F('consumed')
|
||||
)
|
||||
return queryset.filter(allocated_quantity__lt=F('quantity') - F('consumed'))
|
||||
|
||||
consumed = rest_filters.BooleanFilter(label=_('Consumed'), method='filter_consumed')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue