mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 21:25:42 +00:00 
			
		
		
		
	Adds simple test-report template
This commit is contained in:
		| @@ -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; | ||||
|         } | ||||
|  | ||||
|   | ||||
							
								
								
									
										105
									
								
								InvenTree/report/templates/report/inventree_test_report.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								InvenTree/report/templates/report/inventree_test_report.html
									
									
									
									
									
										Normal file
									
								
							| @@ -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 %} | ||||
|  | ||||
| <div class='container'> | ||||
|     <div class='text-left'> | ||||
|         <h2> | ||||
|             {{ stock_item.part.full_name }} | ||||
|         </h2> | ||||
|     </div> | ||||
|     <div class='img-right'> | ||||
|         <img src="{% part_image part %}"> | ||||
|         <hr> | ||||
|         <h3> | ||||
|             {% trans "Serial Number" %}: {{ stock_item.serial }} | ||||
|         </h3> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| <h3>{% trans "Test Results" %}</h3> | ||||
|  | ||||
| <table class='table test-table'> | ||||
|     <thead> | ||||
|         <tr> | ||||
|             <th>{% trans "Test" %}</th> | ||||
|             <th>{% trans "Result" %}</th> | ||||
|             <th>{% trans "Value" %}</th> | ||||
|             <th>{% trans "User" %}</th> | ||||
|             <th>{% trans "Date" %}</th> | ||||
|         </tr> | ||||
|     </thead> | ||||
|     <tbody> | ||||
|         <tr> | ||||
|             <td colspan='5'><hr></td> | ||||
|         </tr> | ||||
|         {% for test in result_list %} | ||||
|         <tr class='test-row'> | ||||
|             <td>{{ test.test }}</td> | ||||
|             {% if test.result %} | ||||
|             <td class='test-pass'>{% trans "Pass" %}</td> | ||||
|             {% else %} | ||||
|             <td class='test-fail'>{% trans "Fail" %}</td> | ||||
|             {% endif %} | ||||
|             <td>{{ test.value }}</td> | ||||
|             <td>{{ test.user.username }}</td> | ||||
|             <td>{{ test.date.date.isoformat }}</td> | ||||
|         </tr> | ||||
|         {% endfor %} | ||||
|     </tbody> | ||||
|  | ||||
| </table> | ||||
|  | ||||
| {% endblock %} | ||||
							
								
								
									
										54
									
								
								InvenTree/report/templatetags/report.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								InvenTree/report/templatetags/report.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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}" | ||||
		Reference in New Issue
	
	Block a user