2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-06 20:11:37 +00:00

Helper tweaks (#10131)

* Enhance report tags

* Update docs
This commit is contained in:
Oliver
2025-08-05 14:37:01 +10:00
committed by GitHub
parent fb3b1fe116
commit b31e16eb98
3 changed files with 17 additions and 9 deletions

View File

@@ -280,10 +280,13 @@ Simple mathematical operators are available, as demonstrated in the example temp
{% add 1 3 %} <!-- Add two numbers together -->
{% subtract 4 3 %} <!-- Subtract 3 from 4 -->
{% multiply 1.2 3.4 %} <!-- Multiply two numbers -->
{% divide 10 2 as division_result %} <!-- Divide 10 by 2 -->
<!-- Perform a calculation and store the result -->
{% divide 10 2 as division_result %} <!-- Divide 10 by 2 -->
Division Result: {{ division_result }}
{% endraw %}
```

View File

@@ -393,27 +393,27 @@ def internal_link(link, text) -> str:
@register.simple_tag()
def add(x, y, *args, **kwargs):
def add(x: float, y: float, *args, **kwargs) -> float:
"""Add two numbers together."""
return x + y
return float(x) + float(y)
@register.simple_tag()
def subtract(x, y):
def subtract(x: float, y: float) -> float:
"""Subtract one number from another."""
return x - y
return float(x) - float(y)
@register.simple_tag()
def multiply(x, y):
def multiply(x: float, y: float) -> float:
"""Multiply two numbers together."""
return x * y
return float(x) * float(y)
@register.simple_tag()
def divide(x, y):
def divide(x: float, y: float) -> float:
"""Divide one number by another."""
return x / y
return float(x) / float(y)
@register.simple_tag

View File

@@ -197,10 +197,15 @@ class ReportTagTest(PartImageTestMixin, InvenTreeTestCase):
def test_maths_tags(self):
"""Simple tests for mathematical operator tags."""
self.assertEqual(report_tags.add(1, 2), 3)
self.assertEqual(report_tags.add('-33', '33'), 0)
self.assertEqual(report_tags.subtract(10, 4.2), 5.8)
self.assertEqual(report_tags.multiply(2.3, 4), 9.2)
self.assertEqual(report_tags.multiply('-2', 4), -8.0)
self.assertEqual(report_tags.divide(100, 5), 20)
with self.assertRaises(ZeroDivisionError):
report_tags.divide(100, 0)
def test_number_tags(self):
"""Simple tests for number formatting tags."""
fn = report_tags.format_number