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

Comments

Projects
None yet
2 participants
@m3nu
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

This comment has been minimized.

Show comment
Hide comment
@duskybomb

duskybomb May 26, 2018

Collaborator

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

Collaborator

duskybomb commented May 26, 2018

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

@m3nu

This comment has been minimized.

Show comment
Hide comment
@m3nu

m3nu May 26, 2018

Collaborator

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.

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@duskybomb

duskybomb May 26, 2018

Collaborator

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

Collaborator

duskybomb commented May 26, 2018

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

This comment has been minimized.

Show comment
Hide comment
@m3nu

m3nu May 26, 2018

Collaborator

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

Collaborator

m3nu commented May 26, 2018

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

@duskybomb

This comment has been minimized.

Show comment
Hide comment
@duskybomb

duskybomb May 26, 2018

Collaborator

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
Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@m3nu

m3nu May 27, 2018

Collaborator

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.

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@duskybomb

duskybomb May 27, 2018

Collaborator

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 #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
Collaborator

duskybomb commented May 27, 2018

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 #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