Skip to content

Commit 75af6c1

Browse files
authored
XRechnung – Invalid XML Generated When Invoice Discount Percentage Exceeds 2 Decimals (#29295)
<!-- Thank you for submitting a Pull Request. If you're new to contributing to AlAppExtensions please read our pull request guideline below * https://github.com/microsoft/ALAppExtensions/blob/main/CONTRIBUTING.md --> #### Summary <!-- Provide a general summary of your changes --> Invoice Discount and Line Discount rounding to 5 decimals #### Work Item(s) <!-- Add the issue number here after the #. The issue needs to be open and approved. Submitting PRs with no linked issues or unapproved issues is highly discouraged. --> Fixes #29253 Fixes [AB#609593](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/609593)
1 parent 0d33f2a commit 75af6c1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Apps/DE/EDocumentDE/app/src/XRechnung/ExportXRechnungDocument.Codeunit.al

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ codeunit 13916 "Export XRechnung Document"
644644
AllowanceChargeElement := XmlElement.Create('AllowanceCharge', XmlNamespaceCAC);
645645
AllowanceChargeElement.Add(XmlElement.Create('ChargeIndicator', XmlNamespaceCBC, 'false'));
646646
AllowanceChargeElement.Add(XmlElement.Create('AllowanceChargeReason', XmlNamespaceCBC, AllowanceChargeReason));
647-
AllowanceChargeElement.Add(XmlElement.Create('MultiplierFactorNumeric', XmlNamespaceCBC, FormatDecimal(MultiplierFactorNumeric)));
647+
AllowanceChargeElement.Add(XmlElement.Create('MultiplierFactorNumeric', XmlNamespaceCBC, FormatFiveDecimal(MultiplierFactorNumeric)));
648648
AllowanceChargeElement.Add(XmlElement.Create('Amount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(Amount)));
649649
AllowanceChargeElement.Add(XmlElement.Create('BaseAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimal(BaseAmount)));
650650
if InsertTaxCat then
@@ -1027,6 +1027,11 @@ codeunit 13916 "Export XRechnung Document"
10271027
exit(Format(Round(VarDecimal, 0.0001), 0, 9));
10281028
end;
10291029

1030+
procedure FormatFiveDecimal(VarDecimal: Decimal): Text[30];
1031+
begin
1032+
exit(Format(Round(VarDecimal, 0.00001), 0, 9));
1033+
end;
1034+
10301035
procedure GetUoMCode(UoMCode: Code[10]): Text;
10311036
var
10321037
UnitofMeasure: Record "Unit of Measure";

Apps/DE/EDocumentDE/test/src/XRechnungXMLDocumentTests.Codeunit.al

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ codeunit 13918 "XRechnung XML Document Tests"
672672
begin
673673
LibrarySales.SetCalcInvDiscount(true);
674674
SalesHeader.CalcFields(Amount);
675-
SalesCalcDiscountByType.ApplyInvDiscBasedOnAmt(SalesHeader.Amount / 2, SalesHeader);
675+
SalesCalcDiscountByType.ApplyInvDiscBasedOnAmt(SalesHeader.Amount * LibraryRandom.RandDecInRange(40, 60, 5) / 100, SalesHeader);
676676
end;
677677

678678
local procedure CreateSalesHeader(var SalesHeader: Record "Sales Header"; DocumentType: Enum "Sales Document Type");
@@ -722,7 +722,7 @@ codeunit 13918 "XRechnung XML Document Tests"
722722
SalesLine.Validate("Unit of Measure", UnitOfMeasure.Code);
723723
SalesLine.Validate("Tax Category", LibraryRandom.RandText(2));
724724
if LineDiscount then
725-
SalesLine.Validate("Line Discount %", LibraryRandom.RandDecInRange(10, 20, 2));
725+
SalesLine.Validate("Line Discount %", LibraryRandom.RandDecInRange(10, 20, 5));
726726
SalesLine.Modify(true);
727727
end;
728728

@@ -970,7 +970,7 @@ codeunit 13918 "XRechnung XML Document Tests"
970970
Path := DocumentTok + '/cbc:AllowanceChargeReason';
971971
Assert.AreEqual('LineDiscount', GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
972972
Path := DocumentTok + '/cbc:MultiplierFactorNumeric';
973-
Assert.AreEqual(FormatDecimal(SalesInvoiceLine."Line Discount %"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
973+
Assert.AreEqual(FormatFiveDecimal(SalesInvoiceLine."Line Discount %"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
974974
Path := DocumentTok + '/cbc:Amount';
975975
Assert.AreEqual(FormatDecimal(SalesInvoiceLine."Line Discount Amount"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
976976
Path := DocumentTok + '/cbc:BaseAmount';
@@ -986,7 +986,7 @@ codeunit 13918 "XRechnung XML Document Tests"
986986
Path := DocumentTok + '/cbc:AllowanceChargeReason';
987987
Assert.AreEqual('Document discount', GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
988988
Path := DocumentTok + '/cbc:MultiplierFactorNumeric';
989-
Assert.AreEqual(FormatDecimal(100 * SalesInvoiceHeader."Invoice Discount Amount" / (SalesInvoiceHeader."Invoice Discount Amount" + SalesInvoiceHeader.Amount)), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
989+
Assert.AreEqual(FormatFiveDecimal(100 * SalesInvoiceHeader."Invoice Discount Amount" / (SalesInvoiceHeader."Invoice Discount Amount" + SalesInvoiceHeader.Amount)), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
990990
Path := DocumentTok + '/cbc:Amount';
991991
Assert.AreEqual(FormatDecimal(SalesInvoiceHeader."Invoice Discount Amount"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
992992
Path := DocumentTok + '/cbc:BaseAmount';
@@ -1056,7 +1056,7 @@ codeunit 13918 "XRechnung XML Document Tests"
10561056
Path := DocumentTok + '/cbc:AllowanceChargeReason';
10571057
Assert.AreEqual('LineDiscount', GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
10581058
Path := DocumentTok + '/cbc:MultiplierFactorNumeric';
1059-
Assert.AreEqual(FormatDecimal(SalesCrMemoLine."Line Discount %"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
1059+
Assert.AreEqual(FormatFiveDecimal(SalesCrMemoLine."Line Discount %"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
10601060
Path := DocumentTok + '/cbc:Amount';
10611061
Assert.AreEqual(FormatDecimal(SalesCrMemoLine."Line Discount Amount"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
10621062
Path := DocumentTok + '/cbc:BaseAmount';
@@ -1072,7 +1072,7 @@ codeunit 13918 "XRechnung XML Document Tests"
10721072
Path := DocumentTok + '/cbc:AllowanceChargeReason';
10731073
Assert.AreEqual('Document discount', GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
10741074
Path := DocumentTok + '/cbc:MultiplierFactorNumeric';
1075-
Assert.AreEqual(FormatDecimal(100 * SalesCrMemoHeader."Invoice Discount Amount" / (SalesCrMemoHeader."Invoice Discount Amount" + SalesCrMemoHeader.Amount)), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
1075+
Assert.AreEqual(FormatFiveDecimal(100 * SalesCrMemoHeader."Invoice Discount Amount" / (SalesCrMemoHeader."Invoice Discount Amount" + SalesCrMemoHeader.Amount)), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
10761076
Path := DocumentTok + '/cbc:Amount';
10771077
Assert.AreEqual(FormatDecimal(SalesCrMemoHeader."Invoice Discount Amount"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
10781078
Path := DocumentTok + '/cbc:BaseAmount';
@@ -1232,6 +1232,11 @@ codeunit 13918 "XRechnung XML Document Tests"
12321232
exit(Format(Round(VarDecimal, 0.0001), 0, 9));
12331233
end;
12341234

1235+
procedure FormatFiveDecimal(VarDecimal: Decimal): Text[30];
1236+
begin
1237+
exit(Format(Round(VarDecimal, 0.00001), 0, 9));
1238+
end;
1239+
12351240
local procedure Initialize();
12361241
begin
12371242
LibraryTestInitialize.OnTestInitialize(Codeunit::"XRechnung XML Document Tests");

0 commit comments

Comments
 (0)