Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,16 @@ report 8051 "Contract Deferrals Release"
var
GenJnlLine: Record "Gen. Journal Line";
begin
if IsNullGuid(ServiceContractSetup.SystemId) then
ServiceContractSetup.Get();
GenJnlLine.Init();
GenJnlLine."Journal Template Name" := ServiceContractSetup."Def. Rel. Jnl. Template Name";
GenJnlLine."Journal Batch Name" := ServiceContractSetup."Def. Rel. Jnl. Batch Name";
GenJnlLine."Document No." := InputTempGenJournalLine."Document No.";
GenJnlLine."Account Type" := GenJnlLine."Account Type"::"G/L Account";
GenJnlLine."VAT Posting" := GenJnlLine."VAT Posting"::"Manual VAT Entry";
GenJnlLine.Validate("Account No.", InputTempGenJournalLine."Account No.");
GenJnlLine."Account No." := InputTempGenJournalLine."Account No.";
GenJnlLine."Deferral Code" := '';
GenJnlLine."Posting Date" := InputPostingDate;
GenJnlLine.Description := StrSubstNo(ReleasingOfContractNoTxt, Format(GenJnlLine."Posting Date", 0, '<Month Text> <Year4>'));
GenJnlLine."Subscription Contract No." := InputTempGenJournalLine."Subscription Contract No.";
Expand All @@ -380,7 +383,8 @@ report 8051 "Contract Deferrals Release"
GenJnlLine."VAT Prod. Posting Group" := '';
GenJnlPostLine.RunWithCheck(GenJnlLine);

GenJnlLine.Validate("Account No.", InputTempGenJournalLine."Bal. Account No.");
GenJnlLine."Account No." := InputTempGenJournalLine."Bal. Account No.";
GenJnlLine."Deferral Code" := '';
GenJnlLine.Validate("Dimension Set ID", InputTempGenJournalLine."Dimension Set ID");
GenJnlLine.Validate(Amount, -InputTempGenJournalLine.Amount);
GenJnlLine."Gen. Posting Type" := GenJnlLine."Gen. Posting Type"::" ";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
namespace Microsoft.SubscriptionBilling;

using System.Security.User;
using Microsoft.Utilities;
using Microsoft.Inventory.Item;
using Microsoft.Purchases.Vendor;
using Microsoft.Purchases.Document;
using Microsoft.Purchases.History;
using Microsoft.Finance.Currency;
using Microsoft.Finance.GeneralLedger.Setup;
using Microsoft.Finance.Deferral;
using Microsoft.Finance.GeneralLedger.Account;
using Microsoft.Finance.GeneralLedger.Journal;
using Microsoft.Finance.GeneralLedger.Ledger;
using Microsoft.Finance.GeneralLedger.Setup;
using Microsoft.Inventory.Item;
using Microsoft.Purchases.Document;
using Microsoft.Purchases.History;
using Microsoft.Purchases.Setup;
using Microsoft.Purchases.Vendor;
using Microsoft.Utilities;
using System.Security.User;

#pragma warning disable AA0210
codeunit 139913 "Vendor Deferrals Test"
Expand Down Expand Up @@ -46,6 +48,7 @@ codeunit 139913 "Vendor Deferrals Test"
Assert: Codeunit Assert;
ContractTestLibrary: Codeunit "Contract Test Library";
CorrectPostedPurchaseInvoice: Codeunit "Correct Posted Purch. Invoice";
LibraryERM: Codeunit "Library - ERM";
LibraryTestInitialize: Codeunit "Library - Test Initialize";
LibraryPurchase: Codeunit "Library - Purchase";
LibraryUtility: Codeunit "Library - Utility";
Expand All @@ -60,6 +63,7 @@ codeunit 139913 "Vendor Deferrals Test"
TotalNumberOfMonths: Integer;
VendorDeferralsCount: Integer;
IsInitialized: Boolean;
AmountNotMovedFromDeferralsAccountErr: Label 'Amount was not moved from Deferrals Account to Contract Account';

#region Tests

Expand Down Expand Up @@ -756,6 +760,126 @@ codeunit 139913 "Vendor Deferrals Test"
Assert.IsTrue(PurchaseLine2.CreateContractDeferrals(), FunctionReturnedWrongResultErr);
end;

[Test]
[HandlerFunctions('CreateVendorBillingDocsContractPageHandler,ContractDeferralsReleaseRequestPageHandler,MessageHandler')]
procedure DeferralsReleaseSucceedsWhenGLAccountHasDefaultDeferralTemplateAndJournalTemplMandatory()
var
DeferralTemplate: Record "Deferral Template";
GLAccount: Record "G/L Account";
GLEntry: Record "G/L Entry";
ContractDeferralsRelease: Report "Contract Deferrals Release";
GLAmountBeforeRelease: Decimal;
GLAmountAfterRelease: Decimal;
begin
// [FEATURE] [AI test]
// [SCENARIO 632489] When "Journal Templ. Name Mandatory" is TRUE and G/L Account has a Default Deferral Template Code,
// the Contract Deferrals Release report should successfully post without error
// "Gen. Journal Template does not exist (Name = '')".
Initialize();

// [GIVEN] General Ledger Setup has "Journal Templ. Name Mandatory" = TRUE.
SetPostingAllowTo(0D);
SetJournalTemplateNameMandatory(true);

// [GIVEN] Purchases & Payables Setup has "P. Invoice Template Name" set.
SetupPurchInvoiceTemplateInPurchSetup();

// [GIVEN] Subscription Contract Setup has "Def. Rel. Jnl. Template Name" and "Def. Rel. Jnl. Batch Name" set.
SetupDeferralReleaseJournalTemplateAndBatch();

// [GIVEN] A vendor contract with deferrals enabled.
CreateVendorContractWithDeferrals('<2M-CM>', true);
CreateBillingProposalAndCreateBillingDocuments('<2M-CM>', '<8M+CM>');

// [GIVEN] The G/L Account used for Vendor Sub. Contract Deferral has a Default Deferral Template Code set.
GeneralPostingSetup.Get(Vendor."Gen. Bus. Posting Group", Item."Gen. Prod. Posting Group");
LibraryERM.CreateDeferralTemplate(DeferralTemplate, Enum::"Deferral Calculation Method"::"Straight-Line",
Enum::"Deferral Calculation Start Date"::"Posting Date", 12);
GLAccount.Get(GeneralPostingSetup."Vend. Sub. Contr. Def. Account");
GLAccount."Default Deferral Template Code" := DeferralTemplate."Deferral Code";
GLAccount.Modify(false);

// [GIVEN] Post the contract invoice
PostPurchDocumentAndFetchDeferrals();

// [WHEN] Run Contract Deferrals Release
GetGLEntryAmountFromAccountNo(GLAmountBeforeRelease, GeneralPostingSetup."Vend. Sub. Contr. Def. Account");
PostingDate := VendorContractDeferral."Posting Date";
Commit();
ContractDeferralsRelease.Run();

// [THEN] The deferral is successfully released without error
VendorContractDeferral.Get(VendorContractDeferral."Entry No.");
VendorContractDeferral.TestField(Released, true);
VendorContractDeferral.TestField("G/L Entry No.");

// [THEN] GL entry is posted with Subscription Contract No. and the amount is released from the deferral account.
GLEntry.Get(VendorContractDeferral."G/L Entry No.");
GLEntry.TestField("Subscription Contract No.", VendorContractDeferral."Subscription Contract No.");
GetGLEntryAmountFromAccountNo(GLAmountAfterRelease, GeneralPostingSetup."Vend. Sub. Contr. Def. Account");
Assert.AreEqual(GLAmountBeforeRelease - VendorContractDeferral.Amount, GLAmountAfterRelease, AmountNotMovedFromDeferralsAccountErr);
end;

[Test]
[HandlerFunctions('CreateVendorBillingDocsContractPageHandler,ContractDeferralsReleaseRequestPageHandler,MessageHandler')]
procedure DeferralsReleaseSucceedsWhenGLAccountHasDefaultDeferralTemplateAndJournalTemplNotMandatory()
var
DeferralTemplate: Record "Deferral Template";
GLAccount: Record "G/L Account";
GLEntry: Record "G/L Entry";
ContractDeferralsRelease: Report "Contract Deferrals Release";
GLAmountBeforeRelease: Decimal;
GLAmountAfterRelease: Decimal;
begin
// [FEATURE] [AI test]
// [SCENARIO 632489] When "Journal Templ. Name Mandatory" is FALSE and Subscription Contract Setup has no journal template/batch,
// and G/L Account has a Default Deferral Template Code, the Contract Deferrals Release report should
// successfully post without error "Gen. Journal Template does not exist (Name = '')".
Initialize();

// [GIVEN] General Ledger Setup has "Journal Templ. Name Mandatory" = FALSE.
SetPostingAllowTo(0D);
SetJournalTemplateNameMandatory(false);

// [GIVEN] Purchases & Payables Setup has "P. Invoice Template Name" set.
SetupPurchInvoiceTemplateInPurchSetup();

// [GIVEN] Subscription Contract Setup has empty "Def. Rel. Jnl. Template Name" and "Def. Rel. Jnl. Batch Name".
ClearDeferralReleaseJournalTemplateAndBatch();

// [GIVEN] A vendor contract with deferrals enabled.
CreateVendorContractWithDeferrals('<2M-CM>', true);
CreateBillingProposalAndCreateBillingDocuments('<2M-CM>', '<8M+CM>');

// [GIVEN] The G/L Account used for Vendor Sub. Contract Deferral has a Default Deferral Template Code set.
GeneralPostingSetup.Get(Vendor."Gen. Bus. Posting Group", Item."Gen. Prod. Posting Group");
LibraryERM.CreateDeferralTemplate(DeferralTemplate, Enum::"Deferral Calculation Method"::"Straight-Line",
Enum::"Deferral Calculation Start Date"::"Posting Date", 12);
GLAccount.Get(GeneralPostingSetup."Vend. Sub. Contr. Def. Account");
GLAccount."Default Deferral Template Code" := DeferralTemplate."Deferral Code";
GLAccount.Modify(false);

// [GIVEN] Post the contract invoice.
PostPurchDocumentAndFetchDeferrals();

// [WHEN] Run Contract Deferrals Release.
GetGLEntryAmountFromAccountNo(GLAmountBeforeRelease, GeneralPostingSetup."Vend. Sub. Contr. Def. Account");
PostingDate := VendorContractDeferral."Posting Date";
Commit();
ContractDeferralsRelease.Run();

// [THEN] The deferral is successfully released without error.
VendorContractDeferral.Get(VendorContractDeferral."Entry No.");
VendorContractDeferral.TestField(Released, true);
VendorContractDeferral.TestField("G/L Entry No.");

// [THEN] GL entry is posted with Subscription Contract No. and the amount is released from the deferral account.
GLEntry.Get(VendorContractDeferral."G/L Entry No.");
GLEntry.TestField("Subscription Contract No.", VendorContractDeferral."Subscription Contract No.");
GetGLEntryAmountFromAccountNo(GLAmountAfterRelease, GeneralPostingSetup."Vend. Sub. Contr. Def. Account");
Assert.AreEqual(GLAmountBeforeRelease - VendorContractDeferral.Amount, GLAmountAfterRelease, AmountNotMovedFromDeferralsAccountErr);
end;

#endregion Tests

#region Procedures
Expand All @@ -781,7 +905,6 @@ codeunit 139913 "Vendor Deferrals Test"
GLAccount: Record "G/L Account";
GenJournalBatch: Record "Gen. Journal Batch";
GenJournalLine: Record "Gen. Journal Line";
LibraryERM: Codeunit "Library - ERM";
begin
CreateGeneralJournalBatch(GenJournalBatch);
LibraryERM.CreateGLAccount(GLAccount);
Expand Down Expand Up @@ -852,7 +975,6 @@ codeunit 139913 "Vendor Deferrals Test"
local procedure CreateGeneralJournalBatch(var GenJournalBatch: Record "Gen. Journal Batch")
var
GenJournalTemplate: Record "Gen. Journal Template";
LibraryERM: Codeunit "Library - ERM";
begin
GenJournalTemplate.SetRange(Recurring, false);
GenJournalTemplate.SetRange(Type, GenJournalTemplate.Type::General);
Expand Down Expand Up @@ -1062,6 +1184,53 @@ codeunit 139913 "Vendor Deferrals Test"
VendorContractDeferral.TestField("Document Posting Date", PurchaseHeader."Posting Date");
end;

local procedure SetJournalTemplateNameMandatory(NewValue: Boolean)
begin
GLSetup.Get();
GLSetup."Journal Templ. Name Mandatory" := NewValue;
GLSetup.Modify(false);
end;

local procedure SetupDeferralReleaseJournalTemplateAndBatch()
var
GenJournalTemplate: Record "Gen. Journal Template";
GenJournalBatch: Record "Gen. Journal Batch";
ServiceContractSetup: Record "Subscription Contract Setup";
begin
LibraryERM.CreateGenJournalTemplate(GenJournalTemplate);
LibraryERM.CreateGenJournalBatch(GenJournalBatch, GenJournalTemplate.Name);
ServiceContractSetup.Get();
ServiceContractSetup."Def. Rel. Jnl. Template Name" := GenJournalBatch."Journal Template Name";
ServiceContractSetup."Def. Rel. Jnl. Batch Name" := GenJournalBatch.Name;
ServiceContractSetup.Modify(false);
end;

local procedure ClearDeferralReleaseJournalTemplateAndBatch()
var
ServiceContractSetup: Record "Subscription Contract Setup";
begin
ServiceContractSetup.Get();
ServiceContractSetup."Def. Rel. Jnl. Template Name" := '';
ServiceContractSetup."Def. Rel. Jnl. Batch Name" := '';
ServiceContractSetup.Modify(false);
end;

local procedure SetupPurchInvoiceTemplateInPurchSetup()
var
GenJournalTemplate: Record "Gen. Journal Template";
PurchasesPayablesSetup: Record "Purchases & Payables Setup";
begin
PurchasesPayablesSetup.Get();
if PurchasesPayablesSetup."P. Invoice Template Name" <> '' then
exit;
LibraryERM.CreateGenJournalTemplate(GenJournalTemplate);
GenJournalTemplate.Type := GenJournalTemplate.Type::Purchases;
GenJournalTemplate."Posting No. Series" := LibraryERM.CreateNoSeriesCode();
GenJournalTemplate.Modify(false);
PurchasesPayablesSetup."P. Invoice Template Name" := GenJournalTemplate.Name;
PurchasesPayablesSetup.Modify(false);
end;

#endregion Procedures

#region Handlers
Expand Down
Loading