Merge pull request #1857 from SchrodingersGat/part-parameters-in-reports

Part parameters in reports
This commit is contained in:
Oliver 2021-07-21 22:33:39 +10:00 committed by GitHub
commit 2bf7b61668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -296,7 +296,9 @@ class StockItemLabel(LabelTemplate):
'uid': stock_item.uid,
'qr_data': stock_item.format_barcode(brief=True),
'qr_url': stock_item.format_barcode(url=True, request=request),
'tests': stock_item.testResultMap()
'tests': stock_item.testResultMap(),
'parameters': stock_item.part.parameters_map(),
}
@ -398,4 +400,5 @@ class PartLabel(LabelTemplate):
'revision': part.revision,
'qr_data': part.format_barcode(brief=True),
'qr_url': part.format_barcode(url=True, request=request),
'parameters': part.parameters_map(),
}

View File

@ -1904,6 +1904,23 @@ class Part(MPTTModel):
return self.parameters.order_by('template__name')
def parameters_map(self):
"""
Return a map (dict) of parameter values assocaited with this Part instance,
of the form:
{
"name_1": "value_1",
"name_2": "value_2",
}
"""
params = {}
for parameter in self.parameters.all():
params[parameter.template.name] = parameter.data
return params
@property
def has_variants(self):
""" Check if this Part object has variants underneath it. """

View File

@ -356,6 +356,7 @@ class TestReport(ReportTemplateBase):
'stock_item': stock_item,
'serial': stock_item.serial,
'part': stock_item.part,
'parameters': stock_item.part.parameters_map(),
'results': stock_item.testResultMap(include_installed=self.include_installed),
'result_list': stock_item.testResultList(include_installed=self.include_installed),
'installed_items': stock_item.get_installed_items(cascade=True),