python-drafthorse icon indicating copy to clipboard operation
python-drafthorse copied to clipboard

IncludedNote and EffectiveSpecifiedPeriod in wrong order for schema "FACTUR-X_EXTENDED"

Open Grosskopf opened this issue 1 year ago • 1 comments

Thank you so much for maintaining this for all of us out here :)

I tried to serialize an invoice including values in

  • doc.header.notes
  • doc.header.effective_period.complete

this didn't work as it is specified in this template: https://github.com/pretix/python-drafthorse/blob/5ed87a6f99919156609408b2ecf619f2c82e9b31/drafthorse/schema/FACTUR-X_EXTENDED_urn_un_unece_uncefact_data_standard_ReusableAggregateBusinessInformationEntity_100.xsd#L63-L64

that the EffectiveSpecifiedPeriod comes first and after that includedNote

however my xml resulted in these lines:

    <ram:EffectiveSpecifiedPeriod>
      <ram:CompleteDateTime>
        <udt:DateTimeString format="102">20240906</udt:DateTimeString>
      </ram:CompleteDateTime>
    </ram:EffectiveSpecifiedPeriod>
    <ram:IncludedNote>
      <ram:Content>Test Note 1</ram:Content>
    </ram:IncludedNote>

meaning in my case, the order was reversed and thus validate_xml failed :)

currently this works as a replacement for xml = doc.serialize(schema="FACTUR-X_EXTENDED") but I'm sure you have a better idea than this :D :

tree = doc.to_etree()
if (
    'IncludedNote' in tree[1][-1].tag and
    'EffectiveSpecifiedPeriod' in tree[1][-2].tag
):
    element = tree[1][-1]
    tree[1].remove(element)
    tree[1].insert(-1, element)
xml = validate_xml(ET.tostring(tree, "utf-8"), "FACTUR-X_EXTENDED")

Grosskopf avatar Sep 06 '24 13:09 Grosskopf

it seems like the order of creation in the class definition of the Header is reflected in xml:

https://github.com/pretix/python-drafthorse/blob/5ed87a6f99919156609408b2ecf619f2c82e9b31/drafthorse/models/document.py#L83-L89

moving that one line about the notes up fixes the error for this template, it seems like this might be a viable fix for this as the effective_period is only ever used in this xsd file :)

Grosskopf avatar Sep 06 '24 13:09 Grosskopf