diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 64cf656f36..2cb893b304 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -105,9 +105,11 @@ class PartBriefSerializer(InvenTreeModelSerializer): 'thumbnail', 'active', 'assembly', + 'is_template', 'purchaseable', 'salable', 'stock', + 'trackable', 'virtual', ] diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 93cf9067f3..9972b1c982 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -80,21 +80,10 @@ class StockDetail(generics.RetrieveUpdateDestroyAPIView): def get_serializer(self, *args, **kwargs): - try: - kwargs['part_detail'] = str2bool(self.request.query_params.get('part_detail', False)) - except AttributeError: - pass - - try: - kwargs['location_detail'] = str2bool(self.request.query_params.get('location_detail', False)) - except AttributeError: - pass - - try: - kwargs['supplier_part_detail'] = str2bool(self.request.query_params.get('supplier_detail', False)) - except AttributeError: - pass - + kwargs['part_detail'] = True + kwargs['location_detail'] = True + kwargs['supplier_part_detail'] = True + kwargs['test_detail'] = True kwargs['context'] = self.get_serializer_context() return self.serializer_class(*args, **kwargs) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index f34344383a..468f72df37 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -1007,6 +1007,10 @@ class StockItem(MPTTModel): 'failed': failed, } + @property + def required_test_count(self): + return self.part.getRequiredTests().count() + def hasRequiredTests(self): return self.part.getRequiredTests().count() > 0 diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 865a63a2c2..a84ea92540 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -108,11 +108,14 @@ class StockItemSerializer(InvenTreeModelSerializer): quantity = serializers.FloatField() allocated = serializers.FloatField() + required_tests = serializers.IntegerField(source='required_test_count', read_only=True) + def __init__(self, *args, **kwargs): part_detail = kwargs.pop('part_detail', False) location_detail = kwargs.pop('location_detail', False) supplier_part_detail = kwargs.pop('supplier_part_detail', False) + test_detail = kwargs.pop('test_detail', False) super(StockItemSerializer, self).__init__(*args, **kwargs) @@ -125,6 +128,9 @@ class StockItemSerializer(InvenTreeModelSerializer): if supplier_part_detail is not True: self.fields.pop('supplier_part_detail') + if test_detail is not True: + self.fields.pop('required_tests') + class Meta: model = StockItem fields = [ @@ -141,6 +147,7 @@ class StockItemSerializer(InvenTreeModelSerializer): 'part_detail', 'pk', 'quantity', + 'required_tests', 'sales_order', 'serial', 'supplier_part',