diff --git a/src/Apps/W1/Subscription Billing/App/Deferrals/Tables/VendSubContractDeferral.Table.al b/src/Apps/W1/Subscription Billing/App/Deferrals/Tables/VendSubContractDeferral.Table.al index 7423680bb5..89a6aee4fa 100644 --- a/src/Apps/W1/Subscription Billing/App/Deferrals/Tables/VendSubContractDeferral.Table.al +++ b/src/Apps/W1/Subscription Billing/App/Deferrals/Tables/VendSubContractDeferral.Table.al @@ -171,8 +171,12 @@ table 8072 "Vend. Sub. Contract Deferral" Sign := 1; end; end; - if (PurchaseLine.Quantity < 0) and (not PurchaseLine."Discount") then - Sign := Sign * -1; + + if (PurchaseLine."Document Type" = Enum::"Purchase Document Type"::"Credit Memo") and (PurchaseLine.Quantity < 0) then + Sign := Sign * -1 + else + if (PurchaseLine.Quantity < 0) and (not PurchaseLine."Discount") then + Sign := Sign * -1; Rec."Vendor No." := PurchaseLine."Pay-to Vendor No."; Rec."Dimension Set ID" := PurchaseLine."Dimension Set ID"; Rec."Discount %" := PurchaseLine."Line Discount %"; diff --git a/src/Apps/W1/Subscription Billing/Test/Deferrals/VendorDeferralsTest.Codeunit.al b/src/Apps/W1/Subscription Billing/Test/Deferrals/VendorDeferralsTest.Codeunit.al index ac5df83204..6a46e2a32a 100644 --- a/src/Apps/W1/Subscription Billing/Test/Deferrals/VendorDeferralsTest.Codeunit.al +++ b/src/Apps/W1/Subscription Billing/Test/Deferrals/VendorDeferralsTest.Codeunit.al @@ -60,6 +60,7 @@ codeunit 139913 "Vendor Deferrals Test" TotalNumberOfMonths: Integer; VendorDeferralsCount: Integer; IsInitialized: Boolean; + ReleasedContractDeferralErr: Label 'Released Contract Deferrals were not reversed properly'; #region Tests @@ -707,6 +708,48 @@ codeunit 139913 "Vendor Deferrals Test" until VendorContractDeferral.Next() = 0; end; + [Test] + [HandlerFunctions('CreateVendorBillingDocsContractPageHandler,ContractDeferralsReleaseRequestPageHandler,MessageHandler')] + procedure VerifyVendSubContrDefAccountBalancedForCreditMemoWithDiscount() + var + SubscriptionLine: Record "Subscription Line"; + ContractDeferralsRelease: Report "Contract Deferrals Release"; + ActualAmount: Decimal; + begin + // [SCENARIO 623041] Verify that released vendor contract deferral amounts have correct sign and GL accounts balance. + Initialize(); + SetPostingAllowTo(0D); + + // [GIVEN] Create Vendor Contract with deferral enabled + CreateVendorContractWithDeferrals('<2M-CM>', true, 1); + + // [GIVEN] Set Discount flag to True on subscription lines + SubscriptionLine.SetRange("Subscription Header No.", ServiceObject."No."); + SubscriptionLine.FindSet(); + repeat + SubscriptionLine.Validate(Discount, true); + SubscriptionLine.Modify(false); + until SubscriptionLine.Next() = 0; + + // [GIVEN] Contract has been created and the billing proposal with non posted contract invoice + CreateBillingProposalAndCreateBillingDocuments('<2M-CM>', '<8M+CM>'); + + // [GIVEN] Post credit memo document + PostPurchDocumentAndFetchDeferrals(); + + // [WHEN] Run Subscription Contract Deferral Release for credit memo + repeat + PostingDate := VendorContractDeferral."Posting Date"; + Commit(); // close transaction before report is called + ContractDeferralsRelease.Run(); // ContractDeferralsReleaseRequestPageHandler + until VendorContractDeferral.Next() = 0; + + // [THEN] Verify "Vend. Sub. Contr. Def. Account" should be balanced after credit memo reversal, which means that released deferral amount was reversed properly + GeneralPostingSetup.Get(Vendor."Gen. Bus. Posting Group", Item."Gen. Prod. Posting Group"); + GetGLEntryAmountFromAccountNo(ActualAmount, GeneralPostingSetup."Vend. Sub. Contr. Def. Account"); + Assert.AreEqual(0, ActualAmount, ReleasedContractDeferralErr); + end; + [Test] procedure UT_CheckFunctionCreateContractDeferralsForPurchaseLine() var