mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Add mathematical operator tags to report templates (#4443)
This commit is contained in:
		| @@ -184,3 +184,27 @@ def internal_link(link, text): | ||||
|         return text | ||||
|  | ||||
|     return mark_safe(f'<a href="{url}">{text}</a>') | ||||
|  | ||||
|  | ||||
| @register.simple_tag() | ||||
| def add(x, y, *args, **kwargs): | ||||
|     """Add two numbers together.""" | ||||
|     return x + y | ||||
|  | ||||
|  | ||||
| @register.simple_tag() | ||||
| def subtract(x, y): | ||||
|     """Subtract one number from another""" | ||||
|     return x - y | ||||
|  | ||||
|  | ||||
| @register.simple_tag() | ||||
| def multiply(x, y): | ||||
|     """Multiply two numbers together""" | ||||
|     return x * y | ||||
|  | ||||
|  | ||||
| @register.simple_tag() | ||||
| def divide(x, y): | ||||
|     """Divide one number by another""" | ||||
|     return x / y | ||||
|   | ||||
| @@ -137,6 +137,14 @@ class ReportTagTest(TestCase): | ||||
|             logo = report_tags.logo_image() | ||||
|             self.assertIn('inventree.png', logo) | ||||
|  | ||||
|     def test_maths_tags(self): | ||||
|         """Simple tests for mathematical operator tags""" | ||||
|  | ||||
|         self.assertEqual(report_tags.add(1, 2), 3) | ||||
|         self.assertEqual(report_tags.subtract(10, 4.2), 5.8) | ||||
|         self.assertEqual(report_tags.multiply(2.3, 4), 9.2) | ||||
|         self.assertEqual(report_tags.divide(100, 5), 20) | ||||
|  | ||||
|  | ||||
| class BarcodeTagTest(TestCase): | ||||
|     """Unit tests for the barcode template tags""" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user