Open m3nu opened 6 years ago
Should I replace data with some placeholder or a simple white-space?
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.
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
For numeric fields you should put 0 or 0.0 This will correspond to None
.
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
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.
Here is what I am doing,
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.'0'
to it'0.0'
None
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.