Browse Source

added property _ItemCollection.items_total_price_brutto

Fabian Peter Hammerle 6 years ago
parent
commit
b883236772
2 changed files with 43 additions and 0 deletions
  1. 4 0
      finoex/__init__.py
  2. 39 0
      tests/test_item_collection.py

+ 4 - 0
finoex/__init__.py

@@ -141,6 +141,10 @@ class _ItemCollection():
         else:
             self.items = []
 
+    @property
+    def items_total_price_brutto(self):
+        return sum([i.total_price_brutto for i in self.items])
+
 
 class Invoice(_Object, _ItemCollection, _YamlInitConstructor, _YamlVarsRepresenter):
 

+ 39 - 0
tests/test_item_collection.py

@@ -0,0 +1,39 @@
+import pytest
+
+import finoex
+import ioex.calcex
+
+
+def get_item_a(currency='EUR'):
+    return finoex.Item(
+        name='a',
+        price_brutto=finoex.Sum(2.0, currency),
+    )
+
+
+def get_item_b():
+    return finoex.Item(
+        name='b',
+        price_brutto=finoex.Sum(3.0, 'EUR'),
+        sub_items=[get_item_a(), get_item_a()],
+    )
+
+
+@pytest.mark.parametrize(('items', 'expected_total'), [
+    [[], 0],
+    [[get_item_a()], finoex.Sum(2.0, 'EUR')],
+    [[get_item_b()], finoex.Sum(7.0, 'EUR')],
+    [[get_item_a(), get_item_b()], finoex.Sum(9.0, 'EUR')],
+])
+def test_get_items_total_price_brutto(items, expected_total):
+    c = finoex._ItemCollection(items=items)
+    assert expected_total == c.items_total_price_brutto
+
+
+@pytest.mark.parametrize(('items'), [
+    [get_item_a(currency='EUR'), get_item_a(currency='USD')],
+])
+def test_get_items_total_price_brutto_fail(items):
+    c = finoex._ItemCollection(items=items)
+    with pytest.raises(ioex.calcex.UnitMismatchError):
+        c.items_total_price_brutto