-
-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* API fixes for SupplierPart - Move API filtering into SupplierPartFilter class - Correct field annotation for detail view * Add "in stock" and "no stock" badges to SupplierPart detail * Update details * Annotate 'on_order' quantity for SupplierPart * Add "has_stock" filter to SupplierPart API * Improve API query efficiency * Add 'has_stock' filter to table * Update <SupplierPartDetail> * Bump API version
- Loading branch information
1 parent
9ab18f1
commit 1a8b030
Showing
7 changed files
with
137 additions
and
36 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Custom query filters for the Company app.""" | ||
|
||
from decimal import Decimal | ||
|
||
from django.db.models import DecimalField, ExpressionWrapper, F, Q | ||
from django.db.models.functions import Coalesce | ||
|
||
from sql_util.utils import SubquerySum | ||
|
||
from order.status_codes import PurchaseOrderStatusGroups | ||
|
||
|
||
def annotate_on_order_quantity(): | ||
"""Annotate the 'on_order' quantity for each SupplierPart in a queryset. | ||
- This is the total quantity of parts on order from all open purchase orders | ||
- Takes into account the 'received' quantity for each order line | ||
""" | ||
# Filter only 'active' purhase orders | ||
# Filter only line with outstanding quantity | ||
order_filter = Q( | ||
order__status__in=PurchaseOrderStatusGroups.OPEN, quantity__gt=F('received') | ||
) | ||
|
||
return Coalesce( | ||
SubquerySum( | ||
ExpressionWrapper( | ||
F('purchase_order_line_items__quantity') | ||
- F('purchase_order_line_items__received'), | ||
output_field=DecimalField(), | ||
), | ||
filter=order_filter, | ||
), | ||
Decimal(0), | ||
output_field=DecimalField(), | ||
) |
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
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
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
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