Ensure line item ExemptionReason and ExemptionReasonCode are not written for EN16931 profile#1122
Conversation
…n data if not already set Closes ZUGFeRD#996
|
@jstaerk also having the same issue.. is this a viable fix for the issue described in the linked issue? |
|
testout-ZF2PushExemption.xml Tried to check this locally. Uploaded it to different web sites then:
Number 1 uses mustangproject as first validator and then their own "valitool". Number 2 is using the KoSIT Validator 1.5.0. Classifies the invoice as legal and does not even race any warnings. Number 3 raises the two errors, "Element 'ram:ExemptionReason' is marked as not used in the given context." and "Element 'ram:ExemptionReasonCode' is marked as not used in the given context." from using schematron/2.4/FACTUR-X_EN16931.xslt. Number 4 does not find any warnings or errors within the xml. (it raises a warning the values in xml and pdf do not match, that's expected in this test case). So in summary, the two fields ExemptionReason and ExemptionReasonCode must not be written on line level when using the EN16931 profile, only for EXTENDED. |
|
Diving deeper into the validation. When I omit a mandatory field, e.g. the invoice number, the apply of the validation schema creates this: For ExemptionReason and ExemptionReasonCode we get this: Mustang validator is only interested in failed-assert's. |
This pull request is a second PR attempt to fix #996 that causes Mustang to generate invalid EN16931 - profile documents, and report warnings in the Valitool validator.
If a Mustang
Productobject has a defined ExemptionReason and / or ExemptionReasonCode, theZUGFeRD2PullProvider generateXML()method currently adds ram:ExemptionReason and /or ram:ExemptionReasonCode to SpecifiedLineTradeSettlement ApplicableTradeTax, for any Profile.However, these line item Exemption fields are only defined for Extended profile. This discrepancy is causing our test ZUGFeRD EN16931 - profile invoices generated by Mustang to fail third-party validation for non-standard tax cases that have an exemption reason that should appear in the document-level VAT Breakdown section.
Note that the referred bug ticket was previously closed by @jstaerk without explanation, and without an apparent fix, so I am contributing a fix here for review.
PR Code Changes
This PR only makes a change for EN16931 - profile invoices, to limit its impact on existing Mustang unit tests as much as possible. If the code is changed to only include line item Exemption nodes for EXTENDED profile, other existing Mustang unit tests , including for XRechnung, also break. For my purposes, my client's project only uses EN16931 - profile docs, so I do not want to make any changes that will affect other profiles in the PR.
I had to add a new
enrichProductFromVATBreakdownmethod to theItemclass used by the ZUGFeRDInvoiceImporter, to enrich per-line item Product objects with the ExemptionReason and ExemptionReasonCode, now that they may now only be present in the doc - level VAT Breakdown section (for EN16931 docs at least).I also added an unrelated but apparently missing CategoryCode code line to the
Item(NodeList itemChilds, boolean recalcPrice)constructor otherwise theZF2PushTest.testAttachmentsExport()test fails.Closes #996