Add mathematical operator tags to report templates (#4443)

This commit is contained in:
Oliver 2023-03-03 21:42:04 +11:00 committed by GitHub
parent cce0fe8236
commit 575d62bff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -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

View File

@ -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"""