Skip to content

Commit 626f0d3

Browse files
committed
add at least two decimals to unit price
1 parent c178ad2 commit 626f0d3

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ codeunit 13916 "Export XRechnung Document"
609609
PriceElement: XmlElement;
610610
begin
611611
PriceElement := XmlElement.Create('Price', XmlNamespaceCAC);
612-
PriceElement.Add(XmlElement.Create('PriceAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimalUnlimited(UnitPrice)));
612+
PriceElement.Add(XmlElement.Create('PriceAmount', XmlNamespaceCBC, XmlAttribute.Create('currencyID', CurrencyCode), FormatDecimalUnlimited(UnitPrice, AlwaysIncludeTwoDecimalPlacesForAmountFields)));
613613
RootElement.Add(PriceElement);
614614
end;
615615

@@ -1394,7 +1394,15 @@ codeunit 13916 "Export XRechnung Document"
13941394

13951395
procedure FormatDecimalUnlimited(VarDecimal: Decimal): Text
13961396
begin
1397-
exit(Format(VarDecimal, 0, 9));
1397+
exit(FormatDecimalUnlimited(VarDecimal, false));
1398+
end;
1399+
1400+
procedure FormatDecimalUnlimited(VarDecimal: Decimal; IncludeMinTwoDecimals: Boolean): Text
1401+
begin
1402+
if IncludeMinTwoDecimals then
1403+
exit(Format(VarDecimal, 0, '<Precision,2:><Standard Format,9>'))
1404+
else
1405+
exit(Format(VarDecimal, 0, 9));
13981406
end;
13991407

14001408
#if not CLEAN29

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,38 @@ codeunit 13918 "XRechnung XML Document Tests"
14491449
// [WHEN/THEN] A value with two decimal places is unchanged
14501450
Assert.AreEqual('1.23', ExportXRechnungDocument.FormatDecimal(1.23, false), 'FormatDecimal(1.23, false) should return ''1.23''');
14511451
end;
1452+
1453+
[Test]
1454+
procedure FormatDecimalUnlimitedWithMinTwoDecimalsReturnsTrailingZero();
1455+
begin
1456+
// [SCENARIO] FormatDecimalUnlimited with IncludeMinTwoDecimals = true ensures minimum two decimal places while preserving extended precision
1457+
Initialize();
1458+
1459+
// [WHEN/THEN] A value with one significant decimal place gets the trailing zero
1460+
Assert.AreEqual('1.10', ExportXRechnungDocument.FormatDecimalUnlimited(1.1, true), 'FormatDecimalUnlimited(1.1, true) should return ''1.10''');
1461+
// [WHEN/THEN] A whole number gets two decimal zeros
1462+
Assert.AreEqual('1.00', ExportXRechnungDocument.FormatDecimalUnlimited(1, true), 'FormatDecimalUnlimited(1, true) should return ''1.00''');
1463+
// [WHEN/THEN] A value with two decimal places is unchanged
1464+
Assert.AreEqual('1.23', ExportXRechnungDocument.FormatDecimalUnlimited(1.23, true), 'FormatDecimalUnlimited(1.23, true) should return ''1.23''');
1465+
// [WHEN/THEN] A value with extended decimal places preserves full precision
1466+
Assert.AreEqual('5.12345', ExportXRechnungDocument.FormatDecimalUnlimited(5.12345, true), 'FormatDecimalUnlimited(5.12345, true) should return ''5.12345''');
1467+
end;
1468+
1469+
[Test]
1470+
procedure FormatDecimalUnlimitedWithoutMinTwoDecimalsUnbounded();
1471+
begin
1472+
// [SCENARIO] FormatDecimalUnlimited with IncludeMinTwoDecimals = false uses unlimited precision without minimum decimal places
1473+
Initialize();
1474+
1475+
// [WHEN/THEN] A value with one significant decimal place has no trailing zero
1476+
Assert.AreEqual('1.1', ExportXRechnungDocument.FormatDecimalUnlimited(1.1, false), 'FormatDecimalUnlimited(1.1, false) should return ''1.1''');
1477+
// [WHEN/THEN] A whole number has no decimal places
1478+
Assert.AreEqual('1', ExportXRechnungDocument.FormatDecimalUnlimited(1, false), 'FormatDecimalUnlimited(1, false) should return ''1''');
1479+
// [WHEN/THEN] A value with two decimal places is unchanged
1480+
Assert.AreEqual('1.23', ExportXRechnungDocument.FormatDecimalUnlimited(1.23, false), 'FormatDecimalUnlimited(1.23, false) should return ''1.23''');
1481+
// [WHEN/THEN] A value with extended decimal places preserves full precision
1482+
Assert.AreEqual('5.12345', ExportXRechnungDocument.FormatDecimalUnlimited(5.12345, false), 'FormatDecimalUnlimited(5.12345, false) should return ''5.12345''');
1483+
end;
14521484
#endregion
14531485

14541486
local procedure CreateAndPostSalesDocument(DocumentType: Enum "Sales Document Type"; LineType: Enum "Sales Line Type"; InvoiceDiscount: Boolean): Code[20];

0 commit comments

Comments
 (0)