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

Quantity Decimal Places Limitation Conflicts with XRechnung Compliance (Needs Immediate Fix) #494

Closed
fktrdui opened this issue Sep 27, 2024 · 5 comments

Comments

@fktrdui
Copy link

fktrdui commented Sep 27, 2024

According to the XRechnung specification, as highlighted in the attached screenshot (section 8.8 "Quantity"), the quantity values should not have a limitation on decimal places. The specification explicitly mentions that the quantity field should allow a floating-point number without limitation on decimal places ("ohne Limitierung der Nachkommastellen").
quantityFormat

However, the Mustang project appears to limit the number of decimal places for quantities in certain methods.
Specifically, in the ZUGFeRD2PullProvider class, the quantityFormat method restricts quantities to 4 decimal places:

protected String quantityFormat(BigDecimal value) {
    return XMLTools.nDigitFormat(value, 4);
}

This method is called by:

+ "<ram:BasisQuantity unitCode=\"" + XMLTools.encodeXML(currentItem.getProduct().getUnit())
+ "\">" + quantityFormat(currentItem.getBasisQuantity()) + "</ram:BasisQuantity>"

Additionally, in the IZUGFeRDExportableItem interface, the getBasisQuantity() method also uses BigDecimal.ONE.setScale(4), which imposes a restriction of 4 decimal places for the quantity.

default BigDecimal getBasisQuantity() {
    return BigDecimal.ONE.setScale(4);
}

Request for Immediate Action
This issue requires urgent attention as it directly impacts XRechnung compliance. Non-compliant e-invoices could lead to legal and financial risks, such as invoice rejections.

Proposed Fix:
Modify the following methods to allow arbitrary precision for quantity values:
quantityFormat in the ZUGFeRD2PullProvider class.
getBasisQuantity in the IZUGFeRDExportableItem interface.

@fktrdui fktrdui changed the title "URGENT: Quantity Decimal Places Limitation Conflicts with XRechnung Compliance (Needs Immediate Fix)" Quantity Decimal Places Limitation Conflicts with XRechnung Compliance (Needs Immediate Fix) Sep 27, 2024
@fktrdui
Copy link
Author

fktrdui commented Sep 30, 2024

Thank you for your immediate update.
Due to changes there are some test issues in the project:

Failed tests: testDXExport(org.mustangproject.ZUGFeRD.DXTest): expected:<400.0000> but was:<400.000000000000000000>
testOXEdgeExport(org.mustangproject.ZUGFeRD.OXTest): expected:<1.0000> but was:<1.000000000000000000>
testOXExport(org.mustangproject.ZUGFeRD.OXTest): expected:<400.0000> but was:<400.000000000000000000>
testExport(org.mustangproject.ZUGFeRD.ZF2Test): expected:<1.0000[00000000000000]> but was:<1.0000[]>
testInvoiceImport(org.mustangproject.ZUGFeRD.ZF2ZInvoiceImporterTest): expected:<400.0000[]> but was:<400.0000[00000000000000]>

langfr added a commit to langfr/mustangproject that referenced this issue Sep 30, 2024
@langfr
Copy link
Contributor

langfr commented Sep 30, 2024

PR #497 created to fix these issues.

@jstaerk
Copy link
Collaborator

jstaerk commented Oct 5, 2024

@fktrdui can you provide one or two tests?

@fktrdui
Copy link
Author

fktrdui commented Oct 9, 2024

@jstaerk I would be happy to modify the previous tests to reflect the changes in the ZUGFeRD2PullProvider.
My suggestion for modified methods in ZUGFeRD2PullProvider is:

protected String priceFormat(BigDecimal value) {
                String digit = XMLTools.nDigitFormat(value, 18);
		BigDecimal digitDecimal = BigDecimal.valueOf(Double.parseDouble(digit));
		return digitDecimal.stripTrailingZeros().toPlainString();
	}

	protected String quantityFormat(BigDecimal value) {
                String digit = XMLTools.nDigitFormat(value, 18);
		BigDecimal digitDecimal = BigDecimal.valueOf(Double.parseDouble(digit));
                return digitDecimal.stripTrailingZeros().toPlainString();
	}

With these changes, unnecessary trailing zeros are eliminated, and the quantities are formatted as required by the specification.

@fktrdui
Copy link
Author

fktrdui commented Oct 9, 2024

Modified Test Cases:

  1. org.mustangproject.ZUGFeRD.DXTest: testDXExport
    Line 301:
    assertEquals(new BigDecimal("400"), i.getZFItems()[1].getQuantity());

  2. org.mustangproject.ZUGFeRD.OXTest: testOXExport
    Line 300:
    assertEquals(new BigDecimal("400"), i.getZFItems()[1].getQuantity());

  3. org.mustangproject.ZUGFeRD.OXTest: testOXEdgeExport
    Line 354:
    assertEquals(new BigDecimal("1"), i.getZFItems()[1].getQuantity());

  4. org.mustangproject.ZUGFeRD.ZF2Test: testExport
    Line 236:
    assertEquals(li.get(0).getQuantity().toString(), "1");

  5. org.mustangproject.ZUGFeRD.ZF2ZInvoiceImporterTest: testInvoiceImport
    Line 60-63:

assertEquals("400", invoice.getZFItems()[1].getQuantity().toString());
assertEquals("AB321", invoice.getReferenceNumber());
assertEquals("160", invoice.getZFItems()[0].getPrice().toString());

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

No branches or pull requests

3 participants