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()))
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
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
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)
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)
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,
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):
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")
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):
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)
_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,