Include 'key' field in StockItemTestResult serializer

This commit is contained in:
Oliver Walters 2020-05-24 20:04:34 +10:00
parent 01481ef5c9
commit e4d10279fa
3 changed files with 10 additions and 1 deletions

View File

@ -687,6 +687,8 @@ class StockItemTestResultList(generics.ListCreateAPIView):
'value',
]
ordering = 'date'
def get_serializer(self, *args, **kwargs):
try:
kwargs['user_detail'] = str2bool(self.request.query_params.get('user_detail', False))

View File

@ -1129,7 +1129,7 @@ class StockItemTestResult(models.Model):
super().clean()
# If this test result corresponds to a template, check the requirements of the template
key = helpers.generateTestKey(self.test)
key = self.key
templates = self.stock_item.part.getTestTemplates()
@ -1150,6 +1150,10 @@ class StockItemTestResult(models.Model):
break
@property
def key(self):
return helpers.generateTestKey(self.test)
stock_item = models.ForeignKey(
StockItem,
on_delete=models.CASCADE,

View File

@ -230,6 +230,8 @@ class StockItemTestResultSerializer(InvenTreeModelSerializer):
user_detail = UserSerializerBrief(source='user', read_only=True)
key = serializers.CharField(read_only=True)
def __init__(self, *args, **kwargs):
user_detail = kwargs.pop('user_detail', False)
@ -244,6 +246,7 @@ class StockItemTestResultSerializer(InvenTreeModelSerializer):
fields = [
'pk',
'stock_item',
'key',
'test',
'result',
'value',