Browse Source

Item: added property total_price_brutto

Fabian Peter Hammerle 6 years ago
parent
commit
96a15c31a3
3 changed files with 31 additions and 3 deletions
  1. 6 1
      finoex/__init__.py
  2. 2 2
      setup.py
  3. 23 0
      tests/test_item.py

+ 6 - 1
finoex/__init__.py

@@ -267,6 +267,11 @@ class Item(_Object, _YamlInitConstructor, _YamlVarsRepresenter):
             self.sub_items = sub_items
         self.price_brutto = price_brutto
 
+    @property
+    def total_price_brutto(self):
+        return self.price_brutto \
+            + sum([s.price_brutto for s in self.sub_items])
+
 
 class Campaign(_Object, _YamlInitConstructor):
 
@@ -477,7 +482,7 @@ class Transportation(Item):
         super(Transportation, self).__init__(**kwargs)
         if arrival_time is not None:
             assert isinstance(arrival_time, datetime.datetime) \
-                    or isinstance(arrival_time, ioex.datetimeex.Period)
+                or isinstance(arrival_time, ioex.datetimeex.Period)
             self.arrival_time = arrival_time
         if departure_point is not None:
             assert type(departure_point) is str

+ 2 - 2
setup.py

@@ -4,7 +4,7 @@ import glob
 
 setup(
     name = 'finoex',
-    version = '0.12.2',
+    version = '0.13.0',
     # description = '',
     author = 'Fabian Peter Hammerle',
     author_email = 'fabian.hammerle@gmail.com',
@@ -15,7 +15,7 @@ setup(
     packages = ['finoex'],
     # scripts = glob.glob('scripts/*'),
     install_requires = [
-        'ioex>=0.13.0',
+        'ioex>=0.17.0',
         'pytz',
         ],
     tests_require = ['pytest'],

+ 23 - 0
tests/test_item.py

@@ -0,0 +1,23 @@
+import pytest
+
+import copy
+import finoex
+
+
+def get_item_a(sub_count=0):
+    i = finoex.Item(name='test', price_brutto=finoex.Sum(2.0, 'EUR'))
+    for c in range(sub_count):
+        i.sub_items.append(finoex.Item(
+            name='sub',
+            price_brutto=finoex.Sum(1.0, 'EUR'),
+        ))
+    return i
+
+
+@pytest.mark.parametrize(('item', 'expected_total'), [
+    [get_item_a(sub_count=0), finoex.Sum(2.0, 'EUR')],
+    [get_item_a(sub_count=1), finoex.Sum(3.0, 'EUR')],
+    [get_item_a(sub_count=2), finoex.Sum(4.0, 'EUR')],
+])
+def test_total_price_brutto(item, expected_total):
+    assert expected_total == item.total_price_brutto