Skip to content

Commit 07f3bcc

Browse files
authored
Merge branch 'main' into xRechnungMandatoryCustomerData
2 parents 1ce8e42 + 75af6c1 commit 07f3bcc

File tree

3 files changed

+91
-7
lines changed

3 files changed

+91
-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/app/src/XRechnung/XRechnungFormat.Codeunit.al

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ using Microsoft.Sales.Customer;
1212
using Microsoft.Foundation.Company;
1313
using Microsoft.eServices.EDocument;
1414
using Microsoft.eServices.EDocument.IO.Peppol;
15+
using Microsoft.Service.History;
1516

1617
codeunit 13914 "XRechnung Format" implements "E-Document"
1718
{
@@ -93,6 +94,14 @@ codeunit 13914 "XRechnung Format" implements "E-Document"
9394
if not EDocumentService."Buyer Reference Mandatory" then
9495
exit;
9596

97+
if not (SourceDocumentHeader.Number in
98+
[Database::"Sales Invoice Header",
99+
Database::"Sales Cr.Memo Header",
100+
Database::"Service Invoice Header",
101+
Database::"Service Cr.Memo Header"])
102+
then
103+
exit;
104+
96105
case EDocumentService."Buyer Reference" of
97106
EDocumentService."Buyer Reference"::"Customer Reference":
98107
begin

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

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace Microsoft.eServices.EDocument.Formats;
66
using Microsoft.Foundation.Company;
77
using Microsoft.Sales.Customer;
88
using Microsoft.Sales.History;
9+
using Microsoft.Purchases.Vendor;
10+
using Microsoft.Purchases.Document;
911
using System.Utilities;
1012
using System.IO;
1113
using Microsoft.Foundation.UOM;
@@ -32,6 +34,7 @@ codeunit 13918 "XRechnung XML Document Tests"
3234
GeneralLedgerSetup: Record "General Ledger Setup";
3335
EDocumentService: Record "E-Document Service";
3436
LibraryTestInitialize: Codeunit "Library - Test Initialize";
37+
LibraryPurchase: Codeunit "Library - Purchase";
3538
LibrarySales: Codeunit "Library - Sales";
3639
LibraryInventory: Codeunit "Library - Inventory";
3740
LibraryRandom: Codeunit "Library - Random";
@@ -539,6 +542,47 @@ codeunit 13918 "XRechnung XML Document Tests"
539542
VerifyCrMemoLineWithDiscounts(SalesCrMemoHeader, TempXMLBuffer);
540543
end;
541544
#endregion
545+
546+
#region PurchaseInvoice
547+
[Test]
548+
procedure ReleasePurchaseInvoiceInXRechnungFormat();
549+
var
550+
PurchaseHeader: Record "Purchase Header";
551+
begin
552+
// [SCENARIO] Release purchase invoice regardless if XRechnung format is setup with customer reference
553+
Initialize();
554+
555+
// [GIVEN] Set Buyer reference = customer reference
556+
SetEdocumentServiceBuyerReference("E-Document Buyer Reference"::"Customer Reference");
557+
558+
// [WHEN] Create and release Purchase Invoice
559+
CreatePurchDocument(PurchaseHeader, "Purchase Document Type"::Invoice);
560+
LibraryPurchase.ReleasePurchaseDocument(PurchaseHeader);
561+
562+
// [THEN] No error occurs
563+
end;
564+
#endregion
565+
566+
#region PurchaseCreditMemo
567+
[Test]
568+
procedure ReleasePurchaseCreditMemoInXRechnungFormat();
569+
var
570+
PurchaseHeader: Record "Purchase Header";
571+
begin
572+
// [SCENARIO] Release purchase credit memo regardless if XRechnung format is setup with customer reference
573+
Initialize();
574+
575+
// [GIVEN] Set Buyer reference = customer reference
576+
SetEdocumentServiceBuyerReference("E-Document Buyer Reference"::"Customer Reference");
577+
578+
// [WHEN] Create and release Purchase credit Memo
579+
CreatePurchDocument(PurchaseHeader, "Purchase Document Type"::"Credit Memo");
580+
LibraryPurchase.ReleasePurchaseDocument(PurchaseHeader);
581+
582+
// [THEN] No error occurs
583+
end;
584+
#endregion
585+
542586
local procedure CreateAndPostSalesDocument(DocumentType: Enum "Sales Document Type"; LineType: Enum "Sales Line Type"; InvoiceDiscount: Boolean): Code[20];
543587
var
544588
SalesHeader: Record "Sales Header";
@@ -563,6 +607,27 @@ codeunit 13918 "XRechnung XML Document Tests"
563607
exit(LibrarySales.PostSalesDocument(SalesHeader, true, true));
564608
end;
565609

610+
local procedure CreatePurchDocument(var PurchaseHeader: Record "Purchase Header"; DocumentType: Enum "Purchase Document Type")
611+
var
612+
PurchaseLine: Record "Purchase Line";
613+
begin
614+
CreatePurchHeader(PurchaseHeader, DocumentType);
615+
LibraryPurchase.CreatePurchaseLine(
616+
PurchaseLine, PurchaseHeader, PurchaseLine.Type::Item, LibraryInventory.CreateItemNo(), LibraryRandom.RandInt(10));
617+
PurchaseLine.Validate("Direct Unit Cost", LibraryRandom.RandDec(50, 2));
618+
PurchaseLine.Modify(true);
619+
end;
620+
621+
local procedure CreatePurchHeader(var PurchaseHeader: Record "Purchase Header"; DocumentType: Enum "Purchase Document Type")
622+
var
623+
Vendor: Record Vendor;
624+
begin
625+
LibraryPurchase.CreateVendor(Vendor);
626+
LibraryPurchase.CreatePurchHeader(PurchaseHeader, DocumentType, Vendor."No.");
627+
PurchaseHeader.Validate("Vendor Invoice No.", PurchaseHeader."No.");
628+
PurchaseHeader.Modify(true);
629+
end;
630+
566631
local procedure CreateSalesDocumentWithLine(DocumentType: Enum "Sales Document Type"; LineType: Enum "Sales Line Type"; InvoiceDiscount: Boolean): Code[20];
567632
var
568633
SalesHeader: Record "Sales Header";
@@ -607,7 +672,7 @@ codeunit 13918 "XRechnung XML Document Tests"
607672
begin
608673
LibrarySales.SetCalcInvDiscount(true);
609674
SalesHeader.CalcFields(Amount);
610-
SalesCalcDiscountByType.ApplyInvDiscBasedOnAmt(SalesHeader.Amount / 2, SalesHeader);
675+
SalesCalcDiscountByType.ApplyInvDiscBasedOnAmt(SalesHeader.Amount * LibraryRandom.RandDecInRange(40, 60, 5) / 100, SalesHeader);
611676
end;
612677

613678
local procedure CreateSalesHeader(var SalesHeader: Record "Sales Header"; DocumentType: Enum "Sales Document Type");
@@ -657,7 +722,7 @@ codeunit 13918 "XRechnung XML Document Tests"
657722
SalesLine.Validate("Unit of Measure", UnitOfMeasure.Code);
658723
SalesLine.Validate("Tax Category", LibraryRandom.RandText(2));
659724
if LineDiscount then
660-
SalesLine.Validate("Line Discount %", LibraryRandom.RandDecInRange(10, 20, 2));
725+
SalesLine.Validate("Line Discount %", LibraryRandom.RandDecInRange(10, 20, 5));
661726
SalesLine.Modify(true);
662727
end;
663728

@@ -905,7 +970,7 @@ codeunit 13918 "XRechnung XML Document Tests"
905970
Path := DocumentTok + '/cbc:AllowanceChargeReason';
906971
Assert.AreEqual('LineDiscount', GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
907972
Path := DocumentTok + '/cbc:MultiplierFactorNumeric';
908-
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));
909974
Path := DocumentTok + '/cbc:Amount';
910975
Assert.AreEqual(FormatDecimal(SalesInvoiceLine."Line Discount Amount"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
911976
Path := DocumentTok + '/cbc:BaseAmount';
@@ -921,7 +986,7 @@ codeunit 13918 "XRechnung XML Document Tests"
921986
Path := DocumentTok + '/cbc:AllowanceChargeReason';
922987
Assert.AreEqual('Document discount', GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
923988
Path := DocumentTok + '/cbc:MultiplierFactorNumeric';
924-
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));
925990
Path := DocumentTok + '/cbc:Amount';
926991
Assert.AreEqual(FormatDecimal(SalesInvoiceHeader."Invoice Discount Amount"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
927992
Path := DocumentTok + '/cbc:BaseAmount';
@@ -991,7 +1056,7 @@ codeunit 13918 "XRechnung XML Document Tests"
9911056
Path := DocumentTok + '/cbc:AllowanceChargeReason';
9921057
Assert.AreEqual('LineDiscount', GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
9931058
Path := DocumentTok + '/cbc:MultiplierFactorNumeric';
994-
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));
9951060
Path := DocumentTok + '/cbc:Amount';
9961061
Assert.AreEqual(FormatDecimal(SalesCrMemoLine."Line Discount Amount"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
9971062
Path := DocumentTok + '/cbc:BaseAmount';
@@ -1007,7 +1072,7 @@ codeunit 13918 "XRechnung XML Document Tests"
10071072
Path := DocumentTok + '/cbc:AllowanceChargeReason';
10081073
Assert.AreEqual('Document discount', GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
10091074
Path := DocumentTok + '/cbc:MultiplierFactorNumeric';
1010-
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));
10111076
Path := DocumentTok + '/cbc:Amount';
10121077
Assert.AreEqual(FormatDecimal(SalesCrMemoHeader."Invoice Discount Amount"), GetNodeByPathWithError(TempXMLBuffer, Path), StrSubstNo(IncorrectValueErr, Path));
10131078
Path := DocumentTok + '/cbc:BaseAmount';
@@ -1167,6 +1232,11 @@ codeunit 13918 "XRechnung XML Document Tests"
11671232
exit(Format(Round(VarDecimal, 0.0001), 0, 9));
11681233
end;
11691234

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

0 commit comments

Comments
 (0)