Coalesce baby, yeah!

This commit is contained in:
Oliver Walters 2020-04-11 23:05:07 +10:00
parent 2560613e36
commit de6f2d37e5

View File

@ -225,8 +225,8 @@ class PartList(generics.ListCreateAPIView):
).annotate( ).annotate(
# Quantity of items which are "in stock" # Quantity of items which are "in stock"
in_stock=Coalesce(Sum('stock_items__quantity', filter=stock_filter), Decimal(0)), in_stock=Coalesce(Sum('stock_items__quantity', filter=stock_filter), Decimal(0)),
on_order=Sum('supplier_parts__purchase_order_line_items__quantity', filter=order_filter), on_order=Coalesce(Sum('supplier_parts__purchase_order_line_items__quantity', filter=order_filter), Decimal(0)),
building=Sum('builds__quantity', filter=build_filter), building=Coalesce(Sum('builds__quantity', filter=build_filter), Decimal(0)),
) )
# If we are filtering by 'has_stock' status # If we are filtering by 'has_stock' status