Add option for user_detail in stockitemtestresult serializer

This commit is contained in:
Oliver Walters 2020-05-16 23:36:03 +10:00
parent e02b692ab2
commit 608057da69
2 changed files with 22 additions and 1 deletions

View File

@ -692,6 +692,16 @@ class StockItemTestResultList(generics.ListCreateAPIView):
'value', 'value',
] ]
def get_serializer(self, *args, **kwargs):
try:
kwargs['user_detail'] = str2bool(self.request.query_params.get('user_detail', False))
except:
pass
kwargs['context'] = self.get_serializer_context()
return self.serializer_class(*args, **kwargs)
def perform_create(self, serializer): def perform_create(self, serializer):
""" """
Create a new test result object. Create a new test result object.

View File

@ -194,7 +194,7 @@ class LocationSerializer(InvenTreeModelSerializer):
class StockItemAttachmentSerializer(InvenTreeModelSerializer): class StockItemAttachmentSerializer(InvenTreeModelSerializer):
""" Serializer for StockItemAttachment model """ """ Serializer for StockItemAttachment model """
def __init_(self, *args, **kwargs): def __init__(self, *args, **kwargs):
user_detail = kwargs.pop('user_detail', False) user_detail = kwargs.pop('user_detail', False)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -221,6 +221,16 @@ class StockItemAttachmentSerializer(InvenTreeModelSerializer):
class StockItemTestResultSerializer(InvenTreeModelSerializer): class StockItemTestResultSerializer(InvenTreeModelSerializer):
""" Serializer for the StockItemTestResult model """ """ Serializer for the StockItemTestResult model """
user_detail = UserSerializerBrief(source='user', read_only=True)
def __init__(self, *args, **kwargs):
user_detail = kwargs.pop('user_detail', False)
super().__init__(*args, **kwargs)
if user_detail is not True:
self.fields.pop('user_detail')
class Meta: class Meta:
model = StockItemTestResult model = StockItemTestResult
@ -233,6 +243,7 @@ class StockItemTestResultSerializer(InvenTreeModelSerializer):
'attachment', 'attachment',
'notes', 'notes',
'user', 'user',
'user_detail',
'date' 'date'
] ]