mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
Add filtering by "completed" status for purchase order line items
This commit is contained in:
parent
5e951ef64b
commit
dd760bfecd
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
|
from django.db.models import Q, F
|
||||||
|
|
||||||
from django_filters import rest_framework as rest_filters
|
from django_filters import rest_framework as rest_filters
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
@ -251,6 +252,39 @@ class POReceive(generics.CreateAPIView):
|
|||||||
return order
|
return order
|
||||||
|
|
||||||
|
|
||||||
|
class POLineItemFilter(rest_filters.FilterSet):
|
||||||
|
"""
|
||||||
|
Custom filters for the POLineItemList endpoint
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PurchaseOrderLineItem
|
||||||
|
fields = [
|
||||||
|
'order',
|
||||||
|
'part'
|
||||||
|
]
|
||||||
|
|
||||||
|
completed = rest_filters.BooleanFilter(label='completed', method='filter_completed')
|
||||||
|
|
||||||
|
def filter_completed(self, queryset, name, value):
|
||||||
|
"""
|
||||||
|
Filter by lines which are "completed" (or "not" completed)
|
||||||
|
|
||||||
|
A line is completed when received >= quantity
|
||||||
|
"""
|
||||||
|
|
||||||
|
value = str2bool(value)
|
||||||
|
|
||||||
|
q = Q(received__gte=F('quantity'))
|
||||||
|
|
||||||
|
if value:
|
||||||
|
queryset = queryset.filter(q)
|
||||||
|
else:
|
||||||
|
queryset = queryset.exclude(q)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class POLineItemList(generics.ListCreateAPIView):
|
class POLineItemList(generics.ListCreateAPIView):
|
||||||
""" API endpoint for accessing a list of POLineItem objects
|
""" API endpoint for accessing a list of POLineItem objects
|
||||||
|
|
||||||
@ -260,6 +294,7 @@ class POLineItemList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
queryset = PurchaseOrderLineItem.objects.all()
|
queryset = PurchaseOrderLineItem.objects.all()
|
||||||
serializer_class = POLineItemSerializer
|
serializer_class = POLineItemSerializer
|
||||||
|
filterset_class = POLineItemFilter
|
||||||
|
|
||||||
def get_queryset(self, *args, **kwargs):
|
def get_queryset(self, *args, **kwargs):
|
||||||
|
|
||||||
|
@ -566,12 +566,10 @@ function loadPurchaseOrderTable(table, options) {
|
|||||||
filters[key] = options.params[key];
|
filters[key] = options.params[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
options.url = options.url || '{% url "api-po-list" %}';
|
|
||||||
|
|
||||||
setupFilterList('purchaseorder', $(table));
|
setupFilterList('purchaseorder', $(table));
|
||||||
|
|
||||||
$(table).inventreeTable({
|
$(table).inventreeTable({
|
||||||
url: options.url,
|
url: '{% url "api-po-list" %}',
|
||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
name: 'purchaseorder',
|
name: 'purchaseorder',
|
||||||
groupBy: false,
|
groupBy: false,
|
||||||
@ -667,12 +665,15 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
|
|||||||
|
|
||||||
options.params = options.params || {};
|
options.params = options.params || {};
|
||||||
|
|
||||||
|
options.params['order'] = options.order;
|
||||||
|
options.params['part_detail'] = true;
|
||||||
|
|
||||||
var filters = loadTableFilters('purchaseorderlineitem');
|
var filters = loadTableFilters('purchaseorderlineitem');
|
||||||
|
|
||||||
for (var key in options.params) {
|
for (var key in options.params) {
|
||||||
filters[key] = options.params[key];
|
filters[key] = options.params[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
var target = options.filter_target || '#filter-list-purchase-order-lines';
|
var target = options.filter_target || '#filter-list-purchase-order-lines';
|
||||||
|
|
||||||
setupFilterList('purchaseorderlineitem', $(table), target);
|
setupFilterList('purchaseorderlineitem', $(table), target);
|
||||||
@ -751,10 +752,8 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
|
|||||||
formatNoMatches: function() {
|
formatNoMatches: function() {
|
||||||
return '{% trans "No line items found" %}';
|
return '{% trans "No line items found" %}';
|
||||||
},
|
},
|
||||||
queryParams: {
|
queryParams: filters,
|
||||||
order: options.order,
|
original: options.params,
|
||||||
part_detail: true
|
|
||||||
},
|
|
||||||
url: '{% url "api-po-line-list" %}',
|
url: '{% url "api-po-line-list" %}',
|
||||||
showFooter: true,
|
showFooter: true,
|
||||||
uniqueId: 'pk',
|
uniqueId: 'pk',
|
||||||
|
@ -274,7 +274,16 @@ function getAvailableTableFilters(tableKey) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filters for the "Order" table
|
// Filters for PurchaseOrderLineItem table
|
||||||
|
if (tableKey == 'purchaseorderlineitem') {
|
||||||
|
return {
|
||||||
|
completed: {
|
||||||
|
type: 'bool',
|
||||||
|
title: '{% trans "Completed" %}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Filters for the PurchaseOrder table
|
||||||
if (tableKey == 'purchaseorder') {
|
if (tableKey == 'purchaseorder') {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user