@@ -6,6 +6,8 @@ namespace Microsoft.eServices.EDocument.Formats;
66using Microsoft. Foundation. Company;
77using Microsoft. Sales. Customer;
88using Microsoft. Sales. History;
9+ using Microsoft. Purchases. Vendor;
10+ using Microsoft. Purchases. Document;
911using System. Utilities;
1012using System. IO;
1113using 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