Browse Source

service: added attr 'period'

Fabian Peter Hammerle 7 years ago
parent
commit
9cc00e27be
3 changed files with 36 additions and 8 deletions
  1. 9 4
      finoex/__init__.py
  2. 1 1
      setup.py
  3. 26 3
      tests/test_yaml.py

+ 9 - 4
finoex/__init__.py

@@ -362,15 +362,20 @@ class Service(Item):
 
     def __init__(self,
                  duration=None,
+                 period=None,
                  state=None,
                  **kwargs
                  ):
         super(Service, self).__init__(**kwargs)
-        if duration is not None:
-            assert type(duration) is ioex.datetimeex.Duration
+        assert not (duration and period)
+        if duration:
+            assert isinstance(duration, ioex.datetimeex.Duration)
             self.duration = duration
-        if state is not None:
-            assert type(state) is str
+        if period:
+            assert isinstance(period, ioex.datetimeex.Period)
+            self.period = period
+        if state:
+            assert isinstance(state, str)
             self.state = state
 
 

+ 1 - 1
setup.py

@@ -4,7 +4,7 @@ import glob
 
 setup(
     name = 'finoex',
-    version = '0.3.0',
+    version = '0.4.0',
     # description = '',
     author = 'Fabian Peter Hammerle',
     author_email = 'fabian.hammerle@gmail.com',

+ 26 - 3
tests/test_yaml.py

@@ -35,7 +35,7 @@ def get_item_b():
         price_brutto = get_sum_b(),
         )
 
-def get_service():
+def get_service_a():
     return finoex.Service(
         name = u'service',
         price_brutto = finoex.Sum(1.0, u'EUR'),
@@ -43,6 +43,16 @@ def get_service():
         state = 'success',
         )
 
+def get_service_b():
+    return finoex.Service(
+        name = u'service',
+        price_brutto = finoex.Sum(1.0, u'EUR'),
+        period = ioex.datetimeex.Period(
+            start = datetime.datetime(2017, 4, 2, 10, 23),
+            end = None,
+            ),
+        )
+
 def get_person_a():
     return finoex.Person(
         first_name = u'Fabian Peter',
@@ -239,12 +249,19 @@ founder: company
 name: campaign without end
 website_url: http://campaign.com
 """],
-    [get_service(), u"""!service
+    [get_service_a(), u"""!service
 duration: !duration
   years: 2
 name: service
 price_brutto: !sum '1.0 EUR'
 state: success
+"""],
+    [get_service_b(), u"""!service
+name: service
+period: !period
+  end: null
+  start: 2017-04-02 10:23:00
+price_brutto: !sum '1.0 EUR'
 """],
     [get_pledge(), u"""!pledge
 campaign: !campaign
@@ -388,12 +405,18 @@ founder: company
 name: campaign without end
 website_url: http://campaign.com
 """],
-    [get_service(), u"""!service
+    [get_service_a(), u"""!service
 duration: !duration
   years: 2
 name: service
 price_brutto: !sum '1.0 EUR'
 state: success
+"""],
+    [get_service_b(), u"""!service
+name: service
+period: !period
+  start: 2017-04-02 10:23:00
+price_brutto: !sum '1.0 EUR'
 """],
     [get_pledge(), u"""!pledge
 campaign: !campaign