From a025b7239d3e564c52d0cb1f945e4145b6de0f2d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 4 Feb 2021 15:29:46 +1100 Subject: [PATCH] Adds simple test-report template --- InvenTree/part/templatetags/report.py | 22 ---- .../report/inventree_report_base.html | 3 +- .../report/inventree_test_report.html | 105 ++++++++++++++++++ InvenTree/report/templatetags/report.py | 54 +++++++++ 4 files changed, 161 insertions(+), 23 deletions(-) delete mode 100644 InvenTree/part/templatetags/report.py create mode 100644 InvenTree/report/templates/report/inventree_test_report.html create mode 100644 InvenTree/report/templatetags/report.py diff --git a/InvenTree/part/templatetags/report.py b/InvenTree/part/templatetags/report.py deleted file mode 100644 index 32eec76db0..0000000000 --- a/InvenTree/part/templatetags/report.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -Custom template tags for report generation -""" - -import os - -from django import template -from django.conf import settings - -register = template.Library() - - -@register.simple_tag() -def asset(filename): - """ - Return fully-qualified path for an upload report asset file. - """ - - path = os.path.join(settings.MEDIA_ROOT, 'report', 'assets', filename) - path = os.path.abspath(path) - - return f"file://{path}" diff --git a/InvenTree/report/templates/report/inventree_report_base.html b/InvenTree/report/templates/report/inventree_report_base.html index afcd31f2ed..c46ddb32e6 100644 --- a/InvenTree/report/templates/report/inventree_report_base.html +++ b/InvenTree/report/templates/report/inventree_report_base.html @@ -5,7 +5,6 @@ @page { size: A4; margin: 2cm; - margin-top: 4cm; font-family: Arial, Helvetica, sans-serif; font-size: 75%; @@ -46,10 +45,12 @@ } .header { + {% block header_style %} top: 0px; left: 0px; position: fixed; width: 100%; + {% endblock %} margin-top: -2.5cm; } diff --git a/InvenTree/report/templates/report/inventree_test_report.html b/InvenTree/report/templates/report/inventree_test_report.html new file mode 100644 index 0000000000..7c99eec6ab --- /dev/null +++ b/InvenTree/report/templates/report/inventree_test_report.html @@ -0,0 +1,105 @@ +{% extends "report/inventree_report_base.html" %} + +{% load i18n %} +{% load report %} +{% load inventree_extras %} + +{% block style %} +.test-table { + width: 100%; +} + +{% block bottom_left %} +content: "{{ date.isoformat }}"; +{% endblock %} + +{% block bottom_center %} +content: "InvenTree v{% inventree_version %}"; +{% endblock %} + +{% block top_center %} +content: "{% trans 'Stock Item Test Report' %}"; +{% endblock %} + +.test-row { + padding: 3px; +} + +.test-pass { + color: #5f5; +} + +.test-fail { + color: #F55; +} + +.container { + padding: 5px; + border: 1px solid; +} + +.text-left { + display: inline-block; + width: 50%; +} + +.img-right { + display: inline; + align-content: right; + align-items: right; + width: 50%; +} + +{% endblock %} + +{% block page_content %} + +
+
+

+ {{ stock_item.part.full_name }} +

+
+
+ +
+

+ {% trans "Serial Number" %}: {{ stock_item.serial }} +

+
+
+ +

{% trans "Test Results" %}

+ + + + + + + + + + + + + + + + {% for test in result_list %} + + + {% if test.result %} + + {% else %} + + {% endif %} + + + + + {% endfor %} + + +
{% trans "Test" %}{% trans "Result" %}{% trans "Value" %}{% trans "User" %}{% trans "Date" %}

{{ test.test }}{% trans "Pass" %}{% trans "Fail" %}{{ test.value }}{{ test.user.username }}{{ test.date.date.isoformat }}
+ +{% endblock %} \ No newline at end of file diff --git a/InvenTree/report/templatetags/report.py b/InvenTree/report/templatetags/report.py new file mode 100644 index 0000000000..1867ffe032 --- /dev/null +++ b/InvenTree/report/templatetags/report.py @@ -0,0 +1,54 @@ +""" +Custom template tags for report generation +""" + +import os + +from django import template +from django.conf import settings + +from part.models import Part +from stock.models import StockItem + +register = template.Library() + + +@register.simple_tag() +def asset(filename): + """ + Return fully-qualified path for an upload report asset file. + """ + + path = os.path.join(settings.MEDIA_ROOT, 'report', 'assets', filename) + path = os.path.abspath(path) + + return f"file://{path}" + + +@register.simple_tag() +def part_image(part): + """ + Return a fully-qualified path for a part image + """ + + if type(part) is Part: + img = part.image.name + + elif type(part) is StockItem: + img = part.part.image.name + + else: + img = '' + + path = os.path.join(settings.MEDIA_ROOT, img) + path = os.path.abspath(path) + + print("Path:", path) + + if not os.path.exists(path) or not os.path.isfile(path): + # Image does not exist + # Return the 'blank' image + path = os.path.join(settings.STATIC_ROOT, 'img', 'blank_image.png') + path = os.path.abspath(path) + + return f"file://{path}"