]> git.ipfire.org Git - thirdparty/python-drafthorse.git/commitdiff
Resolve TODOs
authorRaphael Michel <mail@raphaelmichel.de>
Mon, 15 Oct 2018 18:36:29 +0000 (20:36 +0200)
committerRaphael Michel <mail@raphaelmichel.de>
Mon, 15 Oct 2018 18:36:29 +0000 (20:36 +0200)
demo.py
drafthorse/models/document.py
drafthorse/models/fields.py
drafthorse/models/note.py
drafthorse/models/party.py
drafthorse/models/payment.py

diff --git a/demo.py b/demo.py
index 44c172c97c7c8c5a4faf47fb9aef18b0055ddb25..0b7636cc31d4fee63574b3cd7e20ed8bb06573c5 100644 (file)
--- a/demo.py
+++ b/demo.py
@@ -9,6 +9,9 @@ doc.header.id = "RE1337"
 doc.header.name = "RECHNUNG"
 doc.header.type_code = "380"
 doc.header.issue_date_time.value = date.today()
-doc.header.notes.add(IncludedNote(content="Test Node 1"))
-doc.header.notes.add(IncludedNote(content="Test Node 2", subject_code="foo"))
+doc.header.languages.add("de")
+n = IncludedNote()
+n.content.add("Test Node 1")
+n.content.add("Test Node 2")
+doc.header.notes.add(n)
 print(prettify(doc.serialize()))
index a81fb664ec342a26b79563955301c92ed2f3ba59..6104b49ed55595b6812035f5b6c8d399309409f1 100644 (file)
@@ -3,7 +3,7 @@ import xml.etree.cElementTree as ET
 from drafthorse.models.note import IncludedNote
 from . import NS_RAM, NS_UDT, NS_FERD_1p0, EXTENDED, BASIC
 from .elements import Element
-from .fields import DateTimeField, Field, MultiField, StringField, IndicatorField
+from .fields import DateTimeField, Field, MultiField, StringField, IndicatorField, MultiStringField
 from .trade import TradeTransaction
 
 
@@ -58,8 +58,7 @@ class Header(Element):
     effective_period = Field(EffectivePeriod, required=False, profile=EXTENDED,
                              _d="Vertragliches Fälligkeitsdatum der Rechnung")
     notes = MultiField(IncludedNote)
-
-    # TODO: LanguageID
+    languages = MultiStringField(NS_FERD_1p0, "LanguageID", required=False, profile=EXTENDED)
 
     class Meta:
         namespace = NS_FERD_1p0
index 32c45becf750b59bffcd2c8a80258b4ca8aced40..1119b4e8a7015af1124afabc1943947291c3a1b4 100644 (file)
@@ -195,7 +195,7 @@ class Container:
         self.child_type = child_type
 
     def add(self, item):
-        if not isinstance(item, self.child_type):
+        if isinstance(self.child_type, type) and not isinstance(item, self.child_type):
             raise TypeError("{} is not of type {}".format(item, self.child_type))
         self.children.append(item)
 
@@ -211,3 +211,72 @@ class MultiField(Field):
 
     def initialize(self):
         return self.cls(child_type=self.inner_type)
+
+
+class StringContainer(Container):
+    def __init__(self, child_type, namespace, tag):
+        super().__init__(child_type)
+        self.namespace = namespace
+        self.tag = tag
+
+    def append_to(self, node):
+        for child in self.children:
+            from .elements import StringElement
+            cnode = StringElement(namespace=self.namespace, tag=self.tag, text=child)
+            cnode.append_to(node)
+
+
+class MultiStringField(Field):
+    def __init__(self, namespace, tag, default=False, required=False, profile=BASIC, _d=None):
+        super().__init__(StringContainer, default, required, profile, _d)
+        self.namespace = namespace
+        self.tag = tag
+
+    def initialize(self):
+        return self.cls(child_type=str, namespace=self.namespace, tag=self.tag)
+
+
+class CurrencyContainer(Container):
+    def __init__(self, child_type, namespace, tag):
+        super().__init__(child_type)
+        self.namespace = namespace
+        self.tag = tag
+
+    def append_to(self, node):
+        for child in self.children:
+            from .elements import CurrencyElement
+            cnode = CurrencyElement(namespace=self.namespace, tag=self.tag, amount=child[0], currency=child[1])
+            cnode.append_to(node)
+
+
+class MultiCurrencyField(Field):
+    def __init__(self, namespace, tag, default=False, required=False, profile=BASIC, _d=None):
+        super().__init__(CurrencyContainer, default, required, profile, _d)
+        self.namespace = namespace
+        self.tag = tag
+
+    def initialize(self):
+        return self.cls(child_type=(tuple, list), namespace=self.namespace, tag=self.tag)
+
+
+class IDContainer(Container):
+    def __init__(self, child_type, namespace, tag):
+        super().__init__(child_type)
+        self.namespace = namespace
+        self.tag = tag
+
+    def append_to(self, node):
+        for child in self.children:
+            from .elements import IDElement
+            cnode = IDElement(namespace=self.namespace, tag=self.tag, scheme_id=child[0], text=child[1])
+            cnode.append_to(node)
+
+
+class MultiIDField(Field):
+    def __init__(self, namespace, tag, default=False, required=False, profile=BASIC, _d=None):
+        super().__init__(IDContainer, default, required, profile, _d)
+        self.namespace = namespace
+        self.tag = tag
+
+    def initialize(self):
+        return self.cls(child_type=(tuple, list), namespace=self.namespace, tag=self.tag)
index 2dec5b23b24ae66bb81aa79771c258523eb632b7..21a101c3a31f7115a64e346acfa0133ca2a9fc67 100644 (file)
@@ -1,11 +1,11 @@
 from . import NS_FERD_1p0, BASIC, COMFORT, EXTENDED
 from .elements import Element
-from .fields import StringField
+from .fields import StringField, MultiStringField
 
 
 class IncludedNote(Element):
-    content = StringField(NS_FERD_1p0, "Content", required=False,
-                          profile=BASIC)  # TODO: Can appear multiple times
+    content = MultiStringField(NS_FERD_1p0, "Content", required=False,
+                               profile=BASIC)
     content_code = StringField(NS_FERD_1p0, "ContentCode", required=False,
                                profile=EXTENDED)
     subject_code = StringField(NS_FERD_1p0, "SubjectCode", required=False,
index 156e6ed93e1c73e5b120ead2b36f2d518333982a..c636fd4fc70ee2fc874eea8f531864085bd97e3a 100644 (file)
@@ -1,6 +1,6 @@
 from . import NS_FERD_1p0, COMFORT, BASIC, EXTENDED
 from .elements import Element
-from .fields import StringField, Field, IDField, MultiField
+from .fields import StringField, Field, IDField, MultiField, MultiIDField
 
 
 class PostalTradeAddress(Element):
@@ -67,8 +67,8 @@ class TradeContact(Element):
 class TradeParty(Element):
     id = StringField(NS_FERD_1p0, "ID", required=False, profile=COMFORT,
                      _d="Identifier des Verkäufers")
-    global_id = IDField(NS_FERD_1p0, "GlobalID", required=False, profile=COMFORT,
-                        _d="Globaler Identifier des Verkäufers")  # TODO: Support multiple
+    global_id = MultiIDField(NS_FERD_1p0, "GlobalID", required=False, profile=COMFORT,
+                             _d="Globaler Identifier des Verkäufers")
     name = StringField(NS_FERD_1p0, "Name", required=False, profile=BASIC)
     contact = Field(TradeContact, required=False, profile=EXTENDED,
                     _d="Ansprechpartner des Käufers")
index 8471787b1662b2be5f3ac8356c9adfb7c8bef3f0..88bcbd6eb974304b720a4ea2c6e04d55b44bea64 100644 (file)
@@ -1,6 +1,7 @@
 from . import NS_FERD_1p0, COMFORT, BASIC, EXTENDED
 from .elements import Element
-from .fields import Field, StringField, IDField, DateTimeField, DecimalField, CurrencyField
+from .fields import Field, StringField, IDField, DateTimeField, DecimalField, CurrencyField, MultiStringField, \
+    MultiCurrencyField
 
 
 class PayerFinancialAccount(Element):
@@ -44,7 +45,7 @@ class PayeeFinancialInstitution(Element):
 
 class PaymentMeans(Element):
     type_code = StringField(NS_FERD_1p0, "TypeCode", required=False, profile=COMFORT)
-    information = StringField(NS_FERD_1p0, "Information", required=False, profile=COMFORT)  # TODO: Allow multiple
+    information = MultiStringField(NS_FERD_1p0, "Information", required=False, profile=COMFORT)
     id = IDField(NS_FERD_1p0, "ID", required=False, profile=BASIC)
     payer_account = Field(PayerFinancialAccount)
     payer_institution = Field(PayerFinancialInstitution)
@@ -87,8 +88,8 @@ class PaymentTerms(Element):
                               _d="Freitext der Zahlungsbedingungen")
     due = DateTimeField(NS_FERD_1p0, "DueDateDateTime", required=False, profile=COMFORT,
                         _d="Fälligkeitsdatum")
-    partial_amount = CurrencyField(NS_FERD_1p0, "PartialPaymentAmount", profile=EXTENDED,
-                                   required=False, _d="Betrag der Teilzahlung")  # TODO: Allow multiple times
+    partial_amount = MultiCurrencyField(NS_FERD_1p0, "PartialPaymentAmount", profile=EXTENDED,
+                                        required=False, _d="Betrag der Teilzahlung")
     penalty_terms = Field(PaymentPenaltyTerms, required=False, profile=EXTENDED,
                           _d="Detailinformationen zu Zahlungszuschlägen")
     discount_terms = Field(PaymentDiscountTerms, required=False, profile=EXTENDED,