invoice-x / factur-x-ng

Python lib for Factur-X, the e-invoicing standard for France and Germany
Other
33 stars 8 forks source link

Clean up XML template files #22

Open m3nu opened 6 years ago

m3nu commented 6 years ago

Each invoice XML standard has a few template files, as defined in flavors.yml. These templates are used to add an empty XML. For now I just copied the sample files provided by the standardization bodies. These still have some sample data. This sample data should be removed soon. Else there will be confusion on what is real data and what is leftover sample data.

duskybomb commented 6 years ago

Should I replace data with some placeholder or a simple white-space?

m3nu commented 6 years ago

It should be an empty XML tag. Not a placeholder and not white-space.

When the user assigns a value to the tag, there is a value. Else the tag is empty. Like an empty HTML tag. Putting random white space means it has a value. So it's not a good solution.

duskybomb commented 6 years ago

So I tried doing this, but after removing data I am getting [ERROR] The XML file is invalid against the XML Schema Definition and then XSD Error. The reason being there are tags like TaxBasisTotalAmount which only accept decimal value and cannot accept None

m3nu commented 6 years ago

For numeric fields you should put 0 or 0.0 This will correspond to None.

duskybomb commented 6 years ago

This might not be a good way, but this is what I intend to do:

def isfloat(x):
    try:
        a = float(x)
    except ValueError:
        return False
    else:
        return True

def isint(x):
    try:
        a = float(x)
        b = int(a)
    except ValueError:
        return False
    else:
        return a == b

for element in self.xml.iter("*"):
    if element.text is not None and element.text.strip():
        try:
            int(element.text)
        except ValueError
            element.text = None
        else:
            if isint(element.text):
                element.text = 0
            elif isfloat(element.text):
                element.text = 0.0
m3nu commented 6 years ago

What's this doing? My suggestion was to put 0.0 in all the required numerical fields to get rid of placeholders.

I'm aware the the file will not validate. Before saving it, the user needs to fill the minimal required data or get an error message. Embedding an empty XML doesn't make sense anyways.

If you want to keep the original sample files, you can copy them to a samples folder in each flavor before removing the placeholders.

Of course the empty XML template can't be validated before it has values. On saving there could either be validation all the time or only validation on request with a function.

duskybomb commented 6 years ago

Here is what I am doing,