Functionality for retrieving test templates associated with a given part

This commit is contained in:
Oliver Walters 2020-05-22 21:29:58 +10:00
parent 7215a563b1
commit 0ec880290b
2 changed files with 17 additions and 2 deletions

View File

@ -41,6 +41,7 @@ from InvenTree.helpers import decimal2string, normalize
from InvenTree.status_codes import BuildStatus, PurchaseOrderStatus from InvenTree.status_codes import BuildStatus, PurchaseOrderStatus
from report import models as ReportModels
from build import models as BuildModels from build import models as BuildModels
from order import models as OrderModels from order import models as OrderModels
from company.models import SupplierPart from company.models import SupplierPart
@ -358,6 +359,20 @@ class Part(MPTTModel):
self.category = category self.category = category
self.save() self.save()
def get_test_report_templates(self):
"""
Return all the TestReport template objects which map to this Part.
"""
templates = []
for report in ReportModels.TestReport.objects.all():
if report.matches_part(self):
templates.append(report)
return templates
def get_absolute_url(self): def get_absolute_url(self):
""" Return the web URL for viewing this part """ """ Return the web URL for viewing this part """
return reverse('part-detail', kwargs={'pk': self.id}) return reverse('part-detail', kwargs={'pk': self.id})

View File

@ -13,7 +13,7 @@ from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from part.models import Part from part import models as PartModels
from django_tex.shortcuts import render_to_pdf from django_tex.shortcuts import render_to_pdf
from django_weasyprint import WeasyTemplateResponseMixin from django_weasyprint import WeasyTemplateResponseMixin
@ -186,7 +186,7 @@ class PartFilterMixin(models.Model):
filters = self.get_part_filters() filters = self.get_part_filters()
parts = Part.objects.filter(**filters) parts = PartModels.Part.objects.filter(**filters)
parts = parts.filter(pk=part.pk) parts = parts.filter(pk=part.pk)