API changes

- Allow SupplierPart to be filtered by 'company' in addition to 'supplier' and 'manufacturer'
- Stock can now also be filtered by 'company'

(cherry picked from commit 1b1cd944be)
This commit is contained in:
Oliver Walters
2020-04-13 18:50:59 +10:00
parent 696c101628
commit 2506aa110b
10 changed files with 81 additions and 43 deletions

View File

@ -81,12 +81,19 @@ class SupplierPartList(generics.ListCreateAPIView):
queryset = SupplierPart.objects.all().prefetch_related(
'part',
'part__category',
'part__stock_items',
'part__bom_items',
'part__builds',
'supplier',
'pricebreaks')
'manufacturer'
)
def get_queryset(self):
queryset = super().get_queryset()
# Filter by EITHER manufacturer or supplier
company = self.request.query_params.get('company', None)
if company is not None:
queryset = queryset.filter(Q(manufacturer=company) | Q(supplier=company))
def get_serializer(self, *args, **kwargs):