Skip to content
Open
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 @@ -363,8 +363,8 @@ report 8051 "Contract Deferrals Release"
GeneralLedgerSetup: Record "General Ledger Setup";
begin
GeneralLedgerSetup.Get();
ServiceContractSetup.Get();
if GeneralLedgerSetup."Journal Templ. Name Mandatory" then begin
ServiceContractSetup.Get();
ServiceContractSetup.TestField("Def. Rel. Jnl. Template Name");
ServiceContractSetup.TestField("Def. Rel. Jnl. Batch Name");
end;
Expand All @@ -380,7 +380,8 @@ report 8051 "Contract Deferrals Release"
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.");
Comment thread
DhavalMore88 marked this conversation as resolved.
Comment thread
DhavalMore88 marked this conversation as resolved.
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 @@ -396,7 +397,8 @@ report 8051 "Contract Deferrals Release"
OnBeforePostGenJnlLine(InputTempGenJournalLine, GenJnlLine);
GenJnlPostLine.RunWithCheck(GenJnlLine);

GenJnlLine.Validate("Account No.", InputTempGenJournalLine."Bal. Account No.");
GenJnlLine."Account No." := InputTempGenJournalLine."Bal. Account No.";
Comment thread
DhavalMore88 marked this conversation as resolved.
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
Expand Up @@ -9,6 +9,7 @@ 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;
Expand Down Expand Up @@ -63,6 +64,7 @@ codeunit 139913 "Vendor Deferrals Test"
VendorDeferralsCount: Integer;
IsInitialized: Boolean;
ReleasedContractDeferralErr: Label 'Released Contract Deferrals were not reversed properly';
AmountNotMovedFromDeferralsAccountErr: Label 'Amount was not moved from Deferrals Account to Contract Account';

#region Tests

Expand Down Expand Up @@ -948,6 +950,126 @@ codeunit 139913 "Vendor Deferrals Test"
Assert.ExpectedError(DeferralCodeCannotBeUsedWithContractDeferralsErr);
end;

[Test]
Comment thread
DhavalMore88 marked this conversation as resolved.
[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";
Comment thread
DhavalMore88 marked this conversation as resolved.
GLAccount.Modify(false);

// [GIVEN] Post the contract invoice
Comment thread
DhavalMore88 marked this conversation as resolved.
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 entries are posted correctly
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 entries are posted correctly
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 Down Expand Up @@ -1262,6 +1384,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;
Comment thread
DhavalMore88 marked this conversation as resolved.
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