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

Merged
merged 6 commits into from
Jun 7, 2018
Merged

Clean up XML template files #23

merged 6 commits into from
Jun 7, 2018

Conversation

duskybomb
Copy link

Let's discuss it here.
Issue #22

  • It is validating against XML schema and passes.
  • able to print xml using write_xml()
  • unable to print pdf using write_pdf because some fields are conflicting. Example I have replace date data with '0' but white printing it cannot convert it to date format.

@duskybomb
Copy link
Author

What should we do about this?

@m3nu
Copy link
Collaborator

m3nu commented May 27, 2018

I see you implemented a function to remove existing XML data from sample files. I don't think this is transparent enough since I can't easily look at the empty XML files and validate they are empty.

It would be better to split the current XML files into 2 folders. One for samples (to view and develop with) and one for empty templates.

  • factur-x/facturx/flavors/[zugferd|facturx|ubl]/xml/ (has empty XML templates)
  • factur-x/facturx/flavors/[zugferd|facturx|ubl]/xml/samples (has current sample files)

@duskybomb
Copy link
Author

Okay, so this way we don't need to create any function and can just copy empty XML templates.

@m3nu
Copy link
Collaborator

m3nu commented May 27, 2018

Yes. I think this is the most transparent solution. So we can just look at the empty XML and validate it. In the accounting industry, no mistake can happen. Like forgetting to remove some old value from an XML template. That's what I meant from the start. From the way you implemented it, I see now that I wasn't clear enough on the implementation step.

@duskybomb
Copy link
Author

Like this?

<?xml version="1.0" encoding="UTF-8"?>
<rsm:CrossIndustryInvoice xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <rsm:ExchangedDocumentContext>
        <ram:BusinessProcessSpecifiedDocumentContextParameter>
            <ram:ID/>
        </ram:BusinessProcessSpecifiedDocumentContextParameter>
        <ram:GuidelineSpecifiedDocumentContextParameter>
            <ram:ID/>
        </ram:GuidelineSpecifiedDocumentContextParameter>
    </rsm:ExchangedDocumentContext>
    <rsm:ExchangedDocument>
        <ram:ID/>
        <ram:TypeCode>0</ram:TypeCode>
        <ram:IssueDateTime>
            <udt:DateTimeString format="102">00000000</udt:DateTimeString>
        </ram:IssueDateTime>
    </rsm:ExchangedDocument>
    <rsm:SupplyChainTradeTransaction>
        <ram:ApplicableHeaderTradeAgreement>
            <ram:BuyerReference/>
            <ram:SellerTradeParty>
                <ram:Name/>
                <ram:SpecifiedLegalOrganization>
                    <ram:ID schemeID="0002">0</ram:ID>
                </ram:SpecifiedLegalOrganization>
                <ram:PostalTradeAddress>
                    <ram:CountryID/>
                </ram:PostalTradeAddress>
                <ram:SpecifiedTaxRegistration>
                    <ram:ID schemeID="VA"/>
                </ram:SpecifiedTaxRegistration>
            </ram:SellerTradeParty>
            <ram:BuyerTradeParty>
                <ram:Name/>
                <ram:SpecifiedLegalOrganization>
                    <ram:ID schemeID="0002">0</ram:ID>
                </ram:SpecifiedLegalOrganization>
            </ram:BuyerTradeParty>
            <ram:BuyerOrderReferencedDocument>
                <ram:IssuerAssignedID/>
            </ram:BuyerOrderReferencedDocument>
        </ram:ApplicableHeaderTradeAgreement>
        <ram:ApplicableHeaderTradeDelivery/>
        <ram:ApplicableHeaderTradeSettlement>
            <ram:InvoiceCurrencyCode/>
            <ram:SpecifiedTradeSettlementHeaderMonetarySummation>
                <ram:TaxBasisTotalAmount currencyID="">0.0</ram:TaxBasisTotalAmount>
                <ram:TaxTotalAmount currencyID="">0.0</ram:TaxTotalAmount>
                <ram:GrandTotalAmount currencyID="">0.0</ram:GrandTotalAmount>
                <ram:DuePayableAmount currencyID="">0.0</ram:DuePayableAmount>
            </ram:SpecifiedTradeSettlementHeaderMonetarySummation>
        </ram:ApplicableHeaderTradeSettlement>
    </rsm:SupplyChainTradeTransaction>
</rsm:CrossIndustryInvoice>

@duskybomb
Copy link
Author

I haven't tested all but minimum.xml. And it works just fine.

@duskybomb duskybomb changed the title First commit to clean up XML template files Clean up XML template files May 29, 2018
<ram:IssueDateTime>
<udt:DateTimeString format="102">20171031</udt:DateTimeString>
<udt:DateTimeString format="102">00000000</udt:DateTimeString>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so many 00 and not an empty tag?

Copy link
Author

@duskybomb duskybomb Jun 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because dates have 8 digits?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use an empty tag, like you did with all other tags? You said that's good practice. Why add placeholders for this one?

@@ -1,165 +1,165 @@
<rsm:CrossIndustryInvoice xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rsm:ExchangedDocumentContext>
<ram:BusinessProcessSpecifiedDocumentContextParameter>
<ram:ID>A1</ram:ID>
<ram:ID/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will lxml expand the tag again? I would have expected to see <ram:ID></ram:ID> for an empty tag.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the tags are expanded when any data is added. It's good practice to have empty tags as <tag/> rather than <tag></tag>.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they are expanded it's fine.

@m3nu
Copy link
Collaborator

m3nu commented Jun 2, 2018

Please provide a minimal example that I can run to see that the empty XML templates can be filled again. Can post it here as comment.

@m3nu m3nu closed this Jun 2, 2018
@m3nu m3nu reopened this Jun 2, 2018
@duskybomb
Copy link
Author

You can try this to check:

from facturx import *
factx = FacturX('invoice.pdf')  # where invoice.pdf doesn't contain any embedded metadata
factx['seller'] = 'Manu'

</ram:IncludedNote>
</rsm:ExchangedDocument>
<rsm:SupplyChainTradeTransaction>
<ram:IncludedSupplyChainTradeLineItem>
<ram:AssociatedDocumentLineDocument>
<ram:LineID>1</ram:LineID>
<ram:LineID>0</ram:LineID>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be 0. It's the line numbering.

<ram:CityName>PARIS</ram:CityName>
<ram:CountryID>FR</ram:CountryID>
<ram:PostcodeCode>0</ram:PostcodeCode>
<ram:LineOne/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you decide on using an empty tag vs. 0 as placeholder?

</ram:IncludedNote>
<ram:IncludedNote>
<ram:Content>RCS NANTERRE 999 888 777</ram:Content>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there are multiple invoice notes, you can't just make them all empty. We only keep one. Our current logic doesn't even allow having multiple elements at the same path.

@m3nu
Copy link
Collaborator

m3nu commented Jun 3, 2018

Still need major changes before merging. See comments and

  • you didn't show a full understanding of the XML document. So you are not sure how to clean it up. Having a better understanding of the document will be helpful for you.
  • After you empty fields, you need to see if a) we have them covered as editable fields, b) they are useless, c) they could have a default value that never changes.

@duskybomb
Copy link
Author

Can you provide me some resource from where I can understand the XML document?

@m3nu
Copy link
Collaborator

m3nu commented Jun 3, 2018

The XML represents an invoice. You can look at the sample invoice PDF content and see how they relate to the XML. Then try again.

@duskybomb
Copy link
Author

Here are the things I have gathered till know:

  • Only four fields can be changed using pdfwriter.py
    • seller
    • invoice_number
    • date
    • doc_type
  • Since only four fields can be changed using python, we can extend it to at least change _required fields. And as most of the fields needs to be changed manually we should use <tag></tag> instead of <tag/> for empty tags.
  • BusinessProcessSpecifiedDocumentContextParameter is something that is not related to invoice and maybe useless or can have a default value.
  • GuidelineSpecifiedDocumentContextParameter/ID needs to have a default value for every level. Like for minimum it is urn:factur-x.eu:1p0:minimum

@m3nu
Copy link
Collaborator

m3nu commented Jun 5, 2018

I don't know what you mean with your last comment. The stuff you write about the "only four fields can be changed" is simply not true. Maybe you want to check again.

@m3nu
Copy link
Collaborator

m3nu commented Jun 5, 2018

It seems you are mixing up the module for creating the PDF with the module responsible for the XML document. That's totally unrelated...

 * Assigning a placeholder if some restriction is there in XSD
 * Or if it contains default value
 * All the templates have been successfully validated against XSD
<ram:TypeCode>380</ram:TypeCode>
<ram:IssueDateTime>
<udt:DateTimeString format="102">20171031</udt:DateTimeString>
<udt:DateTimeString format=""></udt:DateTimeString>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep the default time format. Else we need to code support for different formats which isn't practical.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should I leave all the attributes as is?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave all the time formats. format="102". Else we need to take care of time formatting in many places.

@m3nu
Copy link
Collaborator

m3nu commented Jun 7, 2018

It seems like you didn't adjust the code to use the new empty templates you created. That would be here.

@duskybomb
Copy link
Author

I don't think there is any need to adjust the code, because the old templates are moved to sample and the new empty templates have been added in-place of older ones.

@m3nu m3nu merged commit 26cf6c9 into master Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants