Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up XML template files #22

Open
m3nu opened this issue May 25, 2018 · 7 comments
Open

Clean up XML template files #22

m3nu opened this issue May 25, 2018 · 7 comments
Assignees

Comments

@m3nu
Copy link
Collaborator

m3nu commented May 25, 2018

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
Copy link

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

@m3nu
Copy link
Collaborator Author

m3nu commented May 26, 2018

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
Copy link

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
Copy link
Collaborator Author

m3nu commented May 26, 2018

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

@duskybomb
Copy link

duskybomb commented May 26, 2018

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
Copy link
Collaborator Author

m3nu commented May 27, 2018

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
Copy link

Here is what I am doing,

  • Since all the element.text are in string format and then they are converted to int type or float type during validation. So in Clean up XML template files #23 I am checking whether the string is an int, float or string type.
  • Then if it is int type then I assign '0' to it
  • If float type then '0.0'
  • Else I am assigning None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants