Browse Source

discount: added attr 'code'

Fabian Peter Hammerle 7 years ago
parent
commit
4b52e5c08f
3 changed files with 23 additions and 3 deletions
  1. 4 1
      finoex/__init__.py
  2. 2 2
      setup.py
  3. 17 0
      tests/test_yaml.py

+ 4 - 1
finoex/__init__.py

@@ -216,12 +216,15 @@ class Discount(_Object, _YamlInitConstructor):
 
     yaml_tag = u'!discount'
 
-    def __init__(self, name=None, amount=None):
+    def __init__(self, name=None, amount=None, code=None):
         assert type(name) is str
         self.name = name
         assert type(amount) is Sum
         assert amount.value >= 0
         self.amount = amount
+        if code:
+            assert isinstance(code, str)
+            self.code = code
 
 
 class Item(_Object, _YamlInitConstructor):

+ 2 - 2
setup.py

@@ -4,12 +4,12 @@ import glob
 
 setup(
     name = 'finoex',
-    version = '0.5.0',
+    version = '0.6.0',
     # description = '',
     author = 'Fabian Peter Hammerle',
     author_email = 'fabian.hammerle@gmail.com',
     url = 'https://git.hammerle.me/fphammerle/finoex',
-    download_url = 'https://git.hammerle.me/fphammerle/finoex/archive/0.5.0.tar.gz',
+    download_url = 'https://git.hammerle.me/fphammerle/finoex/archive/0.6.0.tar.gz',
     keywords = ['finances'],
     # classifiers = [],
     packages = ['finoex'],

+ 17 - 0
tests/test_yaml.py

@@ -169,6 +169,13 @@ def get_discount_b():
             amount = get_sum_b(),
             )
 
+def get_discount_c():
+    return finoex.Discount(
+            amount = get_sum_b(),
+            code = 'DISCΓ',
+            name = u'discount c',
+            )
+
 def get_order_a(items = True, discounts = True):
     order = finoex.Order(
             platform = u'platformπ',
@@ -247,6 +254,11 @@ def yaml_diff(a, b):
     [finoex.Distance(1.34, u'μm'), u"!distance '1.34 μm'\n"],
     [get_discount_a(), u"!discount\namount: !sum '1.23 EUR'\nname: discount a\n"],
     [get_discount_b(), u"!discount\namount: !sum '20.45 EUR'\nname: discount β\n"],
+    [get_discount_c(), u"""!discount
+amount: !sum '20.45 EUR'
+code: DISCΓ
+name: discount c
+"""],
     [get_figure_a(), u"!figure '12.3 km'\n"],
     [get_figure_b(), u"!figure '12300 米'\n"],
     [get_item_a(), u"!item\nname: item a\nprice_brutto: !sum '1.23 EUR'\n"],
@@ -415,6 +427,11 @@ def test_to_yaml(source_object, expected_yaml):
     [finoex.Distance(1.34, u'μm'), u"!distance '1.34 μm'"],
     [get_discount_a(), u"!discount\nname: discount a\namount: !sum '1.23 EUR'\n"],
     [get_discount_b(), u"!discount\nname: discount β\namount: !sum '20.45 EUR'\n"],
+    [get_discount_c(), u"""!discount
+amount: !sum 20.45 EUR
+name: discount c
+code: DISCΓ
+"""],
     [get_figure_a(), '!figure\nunit: km\nvalue: 12.3\n'],
     [get_figure_a(), u'!figure\nunit: km\nvalue: 12.3\n'],
     [get_figure_b(), '!figure\nunit: 米\nvalue: 12300\n'],