From 9052ccc1810a4bf35bc572052e5fa69bb2d5b982 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 23 May 2019 22:44:37 +1000 Subject: [PATCH] Make 'part_detail' field in SupplierPart serializer optional --- InvenTree/company/api.py | 12 ++++++++++++ InvenTree/company/serializers.py | 9 +++++++++ InvenTree/company/templates/company/detail_part.html | 5 ++++- InvenTree/company/templates/company/index.html | 1 + InvenTree/part/templates/part/build.html | 1 + InvenTree/static/script/inventree/stock.js | 3 ++- 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/InvenTree/company/api.py b/InvenTree/company/api.py index 7bb40f7269..c9e1aa7cdb 100644 --- a/InvenTree/company/api.py +++ b/InvenTree/company/api.py @@ -11,6 +11,8 @@ from rest_framework import generics, permissions from django.conf.urls import url, include +from InvenTree.helpers import str2bool + from .models import Company from .models import SupplierPart, SupplierPriceBreak @@ -84,6 +86,16 @@ class SupplierPartList(generics.ListCreateAPIView): 'supplier', 'pricebreaks') + def get_serializer(self, *args, **kwargs): + + # Do we wish to include extra detail? + part_detail = str2bool(self.request.GET.get('part_detail', None)) + + kwargs['part_detail'] = part_detail + kwargs['context'] = self.get_serializer_context() + + return self.serializer_class(*args, **kwargs) + serializer_class = SupplierPartSerializer permission_classes = [ diff --git a/InvenTree/company/serializers.py b/InvenTree/company/serializers.py index 5d1ac2ba9d..775a273248 100644 --- a/InvenTree/company/serializers.py +++ b/InvenTree/company/serializers.py @@ -64,6 +64,15 @@ class SupplierPartSerializer(serializers.ModelSerializer): pricing = serializers.CharField(source='unit_pricing', read_only=True) + def __init__(self, *args, **kwargs): + + part_detail = kwargs.pop('part_detail', False) + + super(SupplierPartSerializer, self).__init__(*args, **kwargs) + + if part_detail is not True: + self.fields.pop('part_detail') + class Meta: model = SupplierPart fields = [ diff --git a/InvenTree/company/templates/company/detail_part.html b/InvenTree/company/templates/company/detail_part.html index b3213d5993..48e9cb1a77 100644 --- a/InvenTree/company/templates/company/detail_part.html +++ b/InvenTree/company/templates/company/detail_part.html @@ -47,10 +47,13 @@ $("#part-table").bootstrapTable({ sortable: true, search: true, + pagination: true, + pageSize: 50, formatNoMatches: function() { return "No supplier parts found for {{ company.name }}"; }, queryParams: function(p) { return { - supplier: {{ company.id }} + supplier: {{ company.id }}, + part_detail: true, } }, columns: [ diff --git a/InvenTree/company/templates/company/index.html b/InvenTree/company/templates/company/index.html index cea452fdc1..54a9d53213 100644 --- a/InvenTree/company/templates/company/index.html +++ b/InvenTree/company/templates/company/index.html @@ -45,6 +45,7 @@ InvenTree | Supplier List sortable: true, search: true, pagination: true, + pageSize: 50, formatNoMatches: function() { return "No company information found"; }, columns: [ { diff --git a/InvenTree/part/templates/part/build.html b/InvenTree/part/templates/part/build.html index 84642f4de8..958a057409 100644 --- a/InvenTree/part/templates/part/build.html +++ b/InvenTree/part/templates/part/build.html @@ -35,6 +35,7 @@ sortable: true, search: true, pagination: true, + pageSize: 50, queryParams: function(p) { return { part: {{ part.id }}, diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js index d34ed9beee..94eb7ce6df 100644 --- a/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/static/script/inventree/stock.js @@ -377,7 +377,7 @@ function loadStockTable(table, options) { search: true, method: 'get', pagination: true, - pageSize: 25, + pageSize: 50, rememberOrder: true, queryParams: options.params, columns: [ @@ -558,6 +558,7 @@ function loadStockTrackingTable(table, options) { queryParams: options.params, columns: cols, pagination: true, + pageSize: 50, url: options.url, });