From 505f443c28ff928183781f88b5eedb87ec9eef20 Mon Sep 17 00:00:00 2001 From: ventselartur Date: Fri, 31 Jul 2026 17:08:00 +0200 Subject: [PATCH 1/5] Fix: Block IRS 1099 data on vendor ledger entries of non-1099 vendors Bug #620132: It is possible to specify 1099 information in vendor ledger entry even though the vendor is not 1099 Root Cause: - The OnValidate triggers of "IRS 1099 Reporting Period", "IRS 1099 Form No." and "IRS 1099 Form Box No." in tableextension 10035 "IRS 1099 Vendor Ledger Entry" only guarded against entries already linked to an IRS 1099 form document. Nothing verified that the vendor is subject to 1099 reporting, so a user could assign a reporting period, form and form box on the Vendor Ledger Entries page for a vendor with no "IRS 1099 Vendor Form Box Setup" record at all. Changes: - Added CheckVendorSubjectFor1099Reporting to codeunit 10037 "IRS 1099 Vendor Form Box". It exits for a blank period and otherwise errors when no "IRS 1099 Vendor Form Box Setup" record exists for the (period, vendor) pair. - Called the new check from the three OnValidate triggers in tableextension 10035, guarded so that clearing the fields remains allowed. Test Coverage: - ValidateIRS1099PeriodOnVendLedgEntryForNon1099Vendor (new, reproduces the bug) - ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor (new, regression guard) - ClearIRS1099PeriodOnVendLedgEntryForNon1099Vendor (new, clearing stays allowed) - 42/42 tests in codeunit 148010 "IRS 1099 Document Tests" pass - Number of fix iterations: 1 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b132ff13-1ace-428c-a844-844eee2d1932 --- .../IRS1099VendorLedgerEntry.TableExt.al | 6 + .../IRS1099VendorFormBox.Codeunit.al | 11 ++ .../test/src/IRS1099DocumentTests.Codeunit.al | 107 ++++++++++++++++++ 3 files changed, 124 insertions(+) diff --git a/src/Apps/US/IRSForms/app/src/Extensions/IRS1099VendorLedgerEntry.TableExt.al b/src/Apps/US/IRSForms/app/src/Extensions/IRS1099VendorLedgerEntry.TableExt.al index 2218fea2b3b..840ec65b88e 100644 --- a/src/Apps/US/IRSForms/app/src/Extensions/IRS1099VendorLedgerEntry.TableExt.al +++ b/src/Apps/US/IRSForms/app/src/Extensions/IRS1099VendorLedgerEntry.TableExt.al @@ -24,6 +24,8 @@ tableextension 10035 "IRS 1099 Vendor Ledger Entry" extends "Vendor Ledger Entry trigger OnValidate() begin IRS1099FormDocument.CheckIfVendLedgEntryAllowed(Rec."Entry No."); + if "IRS 1099 Reporting Period" <> '' then + IRS1099VendorFormBox.CheckVendorSubjectFor1099Reporting(Rec."Vendor No.", "IRS 1099 Reporting Period"); Validate("IRS 1099 Form No.", ''); end; } @@ -35,6 +37,8 @@ tableextension 10035 "IRS 1099 Vendor Ledger Entry" extends "Vendor Ledger Entry trigger OnValidate() begin IRS1099FormDocument.CheckIfVendLedgEntryAllowed(Rec."Entry No."); + if "IRS 1099 Form No." <> '' then + IRS1099VendorFormBox.CheckVendorSubjectFor1099Reporting(Rec."Vendor No.", "IRS 1099 Reporting Period"); Validate("IRS 1099 Form Box No.", ''); Validate("IRS 1099 Reporting Amount", 0); end; @@ -47,6 +51,8 @@ tableextension 10035 "IRS 1099 Vendor Ledger Entry" extends "Vendor Ledger Entry trigger OnValidate() begin IRS1099FormDocument.CheckIfVendLedgEntryAllowed(Rec."Entry No."); + if "IRS 1099 Form Box No." <> '' then + IRS1099VendorFormBox.CheckVendorSubjectFor1099Reporting(Rec."Vendor No.", "IRS 1099 Reporting Period"); "IRS 1099 Subject For Reporting" := "IRS 1099 Form Box No." <> ''; IRS1099VendorFormBox.UpdatePurchDocFormBoxNoFromVendLedgEntry(Rec); end; diff --git a/src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al b/src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al index 9e867b687ee..06c6ab34c8b 100644 --- a/src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al +++ b/src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al @@ -141,6 +141,17 @@ codeunit 10037 "IRS 1099 Vendor Form Box" end; end; + procedure CheckVendorSubjectFor1099Reporting(VendorNo: Code[20]; PeriodNo: Code[20]) + var + IRS1099VendorFormBoxSetup: Record "IRS 1099 Vendor Form Box Setup"; + VendorNotSetupFor1099Err: Label 'Vendor %1 is not set up for IRS 1099 reporting in the reporting period %2.', Comment = '%1 = Vendor No., %2 = Period No.'; + begin + if PeriodNo = '' then + exit; + if not IRS1099VendorFormBoxSetup.Get(PeriodNo, VendorNo) then + Error(VendorNotSetupFor1099Err, VendorNo, PeriodNo); + end; + local procedure ShowIfVendorHas1099CodePrevPeriodButNotCurrNotificationId(): Guid begin exit('4b87dd95-f7ba-4e72-909b-76ca6a1d8b6a'); diff --git a/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al b/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al index a0ac5bc3937..a973794fecf 100644 --- a/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al +++ b/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al @@ -39,6 +39,7 @@ codeunit 148010 "IRS 1099 Document Tests" PeriodNoFieldVisibleErr: Label 'Field Period No. should be visible.'; PeriodNoNotVisibleErr: Label 'Field Period No. should not be visible.'; ChangingPostingDateInPurchHeaderWhileHavingLineMsg: Label 'You have changed the Posting Date on the purchase header, which might affect the prices and discounts on the purchase lines.\You should review the lines and manually update prices and discounts if needed'; + VendorNotSetupForIRS1099Err: Label 'Vendor %1 is not set up for IRS 1099 reporting in the reporting period %2.', Comment = '%1 = Vendor No., %2 = Period No.'; trigger OnRun() @@ -1380,6 +1381,112 @@ codeunit 148010 "IRS 1099 Document Tests" Assert.AreEqual(FormBoxNo[2], PurchCrMemoHdr."IRS 1099 Form Box No.", 'IRS 1099 Form Box No. in Purch. Cr. Memo Hdr. should be updated'); end; + [Test] + procedure ValidateIRS1099PeriodOnVendLedgEntryForNon1099Vendor() + var + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + VendorLedgEntry: Record "Vendor Ledger Entry"; + VendNo: Code[20]; + FormNo: Code[20]; + FormBoxNo: Code[20]; + PeriodNo: Code[20]; + InvNo: Code[20]; + begin + // [SCENARIO 620132] Setting IRS 1099 Reporting Period on vendor ledger entry of a vendor with no 1099 setup raises an error + + Initialize(); + // [GIVEN] IRS Reporting Period "P" with form "F" and form box "FB" + PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate()); + FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate()); + FormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo); + + // [GIVEN] Vendor "V" with NO IRS 1099 form box setup (plain vendor) + VendNo := LibraryPurchase.CreateVendorNo(); + + // [GIVEN] Posted purchase invoice for vendor "V" + LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Invoice, VendNo); + LibraryPurchase.CreatePurchaseLineWithUnitCost(PurchaseLine, PurchaseHeader, LibraryInventory.CreateItemNo(), 1, 100); + InvNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true); + + // [WHEN] Validate "IRS 1099 Reporting Period" in the vendor ledger entry + LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo); + // [THEN] An error is raised because vendor "V" has no 1099 setup for the period + asserterror VendorLedgEntry.Validate("IRS 1099 Reporting Period", PeriodNo); + Assert.ExpectedError(StrSubstNo(VendorNotSetupForIRS1099Err, VendNo, PeriodNo)); + end; + + [Test] + procedure ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor() + var + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + VendorLedgEntry: Record "Vendor Ledger Entry"; + VendNo: Code[20]; + FormNo: Code[20]; + FormBoxNo: Code[20]; + InvNo: Code[20]; + begin + // [SCENARIO 620132] Vendor WITH 1099 setup can still validate form box on its ledger entry without error + + Initialize(); + // [GIVEN] IRS Reporting Period with Form "F" and Form Box "FB" + LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate()); + FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate()); + FormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo); + + // [GIVEN] Vendor "V" WITH IRS 1099 form box setup + VendNo := LibraryIRS1099FormBox.CreateVendorNoWithFormBox(WorkDate(), WorkDate(), FormNo, FormBoxNo); + + // [GIVEN] Posted purchase invoice for vendor "V" + LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Invoice, VendNo); + LibraryPurchase.CreatePurchaseLineWithUnitCost(PurchaseLine, PurchaseHeader, LibraryInventory.CreateItemNo(), 1, 100); + InvNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true); + + // [WHEN] Validate "IRS 1099 Form Box No." in the vendor ledger entry + LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo); + // [THEN] No error is raised for a vendor that has 1099 setup + VendorLedgEntry.Validate("IRS 1099 Form Box No.", FormBoxNo); + VendorLedgEntry.TestField("IRS 1099 Form Box No.", FormBoxNo); + end; + + [Test] + procedure ClearIRS1099PeriodOnVendLedgEntryForNon1099Vendor() + var + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + VendorLedgEntry: Record "Vendor Ledger Entry"; + VendNo: Code[20]; + FormNo: Code[20]; + FormBoxNo: Code[20]; + PeriodNo: Code[20]; + InvNo: Code[20]; + begin + // [SCENARIO 620132] Clearing IRS 1099 Reporting Period on a non-1099 vendor ledger entry does not raise an error + + Initialize(); + // [GIVEN] IRS Reporting Period "P" with form "F" and form box "FB" + PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate()); + FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate()); + FormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo); + + // [GIVEN] Vendor "V" with NO IRS 1099 form box setup + VendNo := LibraryPurchase.CreateVendorNo(); + + // [GIVEN] Posted purchase invoice for vendor "V", with IRS period set directly (bypassing validation) + LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Invoice, VendNo); + LibraryPurchase.CreatePurchaseLineWithUnitCost(PurchaseLine, PurchaseHeader, LibraryInventory.CreateItemNo(), 1, 100); + InvNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true); + LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo); + VendorLedgEntry."IRS 1099 Reporting Period" := PeriodNo; + VendorLedgEntry.Modify(); + + // [WHEN] Clear "IRS 1099 Reporting Period" by validating with '' + // [THEN] No error is raised (clearing must always be allowed) + VendorLedgEntry.Validate("IRS 1099 Reporting Period", ''); + VendorLedgEntry.TestField("IRS 1099 Reporting Period", ''); + end; + local procedure Initialize() var IRSReportingPeriod: Record "IRS Reporting Period"; From 8da917480887709db7d2b459120198473cf9251f Mon Sep 17 00:00:00 2001 From: ventselartur Date: Fri, 31 Jul 2026 17:37:04 +0200 Subject: [PATCH 2/5] Tag the new IRS 1099 vendor ledger entry tests as AI tests Add the [FEATURE] [AI test] marker above the [SCENARIO 620132] line in the three new tests, matching the convention used by the other tests in the IRSForms test codeunits. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b132ff13-1ace-428c-a844-844eee2d1932 --- src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al b/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al index a973794fecf..f7ca116391a 100644 --- a/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al +++ b/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al @@ -1393,6 +1393,7 @@ codeunit 148010 "IRS 1099 Document Tests" PeriodNo: Code[20]; InvNo: Code[20]; begin + // [FEATURE] [AI test] // [SCENARIO 620132] Setting IRS 1099 Reporting Period on vendor ledger entry of a vendor with no 1099 setup raises an error Initialize(); @@ -1427,6 +1428,7 @@ codeunit 148010 "IRS 1099 Document Tests" FormBoxNo: Code[20]; InvNo: Code[20]; begin + // [FEATURE] [AI test] // [SCENARIO 620132] Vendor WITH 1099 setup can still validate form box on its ledger entry without error Initialize(); @@ -1462,6 +1464,7 @@ codeunit 148010 "IRS 1099 Document Tests" PeriodNo: Code[20]; InvNo: Code[20]; begin + // [FEATURE] [AI test] // [SCENARIO 620132] Clearing IRS 1099 Reporting Period on a non-1099 vendor ledger entry does not raise an error Initialize(); From e559fd464eea6ab5f14e850e6dd155704c7f1a5a Mon Sep 17 00:00:00 2001 From: ventselartur Date: Wed, 5 Aug 2026 14:29:58 +0200 Subject: [PATCH 3/5] fix test --- .../IRSForms/test/src/IRS1099VendorTests.Codeunit.al | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Apps/US/IRSForms/test/src/IRS1099VendorTests.Codeunit.al b/src/Apps/US/IRSForms/test/src/IRS1099VendorTests.Codeunit.al index a599a5b40aa..c4e945ae7dd 100644 --- a/src/Apps/US/IRSForms/test/src/IRS1099VendorTests.Codeunit.al +++ b/src/Apps/US/IRSForms/test/src/IRS1099VendorTests.Codeunit.al @@ -168,7 +168,7 @@ codeunit 148011 "IRS 1099 Vendor Tests" var VendorLedgerEntry: Record "Vendor Ledger Entry"; VendorLedgerEntriesPage: TestPage "Vendor Ledger Entries"; - NewPeriodNo, FormNo, NewFormNo, FormBoxNo, NewFormBoxNo : Code[20]; + VendNo, NewPeriodNo, FormNo, NewFormNo, FormBoxNo, NewFormBoxNo : Code[20]; IRSAmount: Decimal; NewDate: Date; begin @@ -187,7 +187,13 @@ codeunit 148011 "IRS 1099 Vendor Tests" NewPeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(NewDate); NewFormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(NewDate); NewFormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(NewDate, NewFormNo); - IRSAmount := IRSAmount / 3; + // [GIVEN] The entry belongs to a vendor set up for IRS 1099 reporting in both periods + VendNo := LibraryIRS1099FormBox.CreateVendorNoWithFormBox(WorkDate(), FormNo, FormBoxNo); + LibraryIRS1099FormBox.AssignFormBoxForVendorInPeriod(VendNo, NewDate, NewDate, NewFormNo, NewFormBoxNo); + VendorLedgerEntry."Vendor No." := VendNo; + VendorLedgerEntry.Modify(); + + IRSAmount := Round(IRSAmount / 3); // [GIVEN] Vendor Ledger Entries page opened and filtered by Entry No. VendorLedgerEntriesPage.OpenEdit(); VendorLedgerEntriesPage.Filter.SetFilter("Entry No.", Format(VendorLedgerEntry."Entry No.")); From c74e438f8d56338d7875cae5575e1feccd68b41a Mon Sep 17 00:00:00 2001 From: ventselartur Date: Thu, 13 Aug 2026 15:19:02 +0200 Subject: [PATCH 4/5] Fix AA0206: remove unused FormBoxNo variable in new IRS 1099 tests The build's new-warning gate failed on two AA0206 diagnostics in the IRS Forms test project. Both new tests assigned the result of CreateSingleFormBoxInReportingPeriod to a FormBoxNo variable that was never read. The call is kept as a statement so the form box is still created as part of the test setup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al b/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al index f7ca116391a..a0e902c2b9d 100644 --- a/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al +++ b/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al @@ -1389,7 +1389,6 @@ codeunit 148010 "IRS 1099 Document Tests" VendorLedgEntry: Record "Vendor Ledger Entry"; VendNo: Code[20]; FormNo: Code[20]; - FormBoxNo: Code[20]; PeriodNo: Code[20]; InvNo: Code[20]; begin @@ -1400,7 +1399,7 @@ codeunit 148010 "IRS 1099 Document Tests" // [GIVEN] IRS Reporting Period "P" with form "F" and form box "FB" PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate()); FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate()); - FormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo); + LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo); // [GIVEN] Vendor "V" with NO IRS 1099 form box setup (plain vendor) VendNo := LibraryPurchase.CreateVendorNo(); @@ -1460,7 +1459,6 @@ codeunit 148010 "IRS 1099 Document Tests" VendorLedgEntry: Record "Vendor Ledger Entry"; VendNo: Code[20]; FormNo: Code[20]; - FormBoxNo: Code[20]; PeriodNo: Code[20]; InvNo: Code[20]; begin @@ -1471,7 +1469,7 @@ codeunit 148010 "IRS 1099 Document Tests" // [GIVEN] IRS Reporting Period "P" with form "F" and form box "FB" PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate()); FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate()); - FormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo); + LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo); // [GIVEN] Vendor "V" with NO IRS 1099 form box setup VendNo := LibraryPurchase.CreateVendorNo(); From 02a830bf8b3e24bc7cc8a1f313fbf4e42e4aa40f Mon Sep 17 00:00:00 2001 From: ventselartur Date: Wed, 19 Aug 2026 11:40:46 +0200 Subject: [PATCH 5/5] address PR review feedback - Raise an actionable ErrorInfo with a navigation action to the IRS 1099 Vendor Form Box Setup page instead of a dead-end Error dialog - Make ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor set a reporting period first so it actually exercises the new vendor-setup guard - Add a negative test covering the IRS 1099 Form No. and Form Box No. guards for a vendor without 1099 setup Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../IRS1099VendorFormBox.Codeunit.al | 11 +++- .../test/src/IRS1099DocumentTests.Codeunit.al | 53 ++++++++++++++++++- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al b/src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al index 06c6ab34c8b..f773ae77a4e 100644 --- a/src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al +++ b/src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al @@ -144,12 +144,19 @@ codeunit 10037 "IRS 1099 Vendor Form Box" procedure CheckVendorSubjectFor1099Reporting(VendorNo: Code[20]; PeriodNo: Code[20]) var IRS1099VendorFormBoxSetup: Record "IRS 1099 Vendor Form Box Setup"; + VendorNotSetupErrorInfo: ErrorInfo; VendorNotSetupFor1099Err: Label 'Vendor %1 is not set up for IRS 1099 reporting in the reporting period %2.', Comment = '%1 = Vendor No., %2 = Period No.'; + OpenVendorFormBoxSetupLbl: Label 'Open IRS 1099 Vendor Form Box Setup'; begin if PeriodNo = '' then exit; - if not IRS1099VendorFormBoxSetup.Get(PeriodNo, VendorNo) then - Error(VendorNotSetupFor1099Err, VendorNo, PeriodNo); + if IRS1099VendorFormBoxSetup.Get(PeriodNo, VendorNo) then + exit; + + VendorNotSetupErrorInfo.Message := StrSubstNo(VendorNotSetupFor1099Err, VendorNo, PeriodNo); + VendorNotSetupErrorInfo.PageNo := Page::"IRS 1099 Vendor Form Box Setup"; + VendorNotSetupErrorInfo.AddNavigationAction(OpenVendorFormBoxSetupLbl); + Error(VendorNotSetupErrorInfo); end; local procedure ShowIfVendorHas1099CodePrevPeriodButNotCurrNotificationId(): Guid diff --git a/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al b/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al index a0e902c2b9d..21297f0e147 100644 --- a/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al +++ b/src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al @@ -1425,6 +1425,7 @@ codeunit 148010 "IRS 1099 Document Tests" VendNo: Code[20]; FormNo: Code[20]; FormBoxNo: Code[20]; + PeriodNo: Code[20]; InvNo: Code[20]; begin // [FEATURE] [AI test] @@ -1432,7 +1433,7 @@ codeunit 148010 "IRS 1099 Document Tests" Initialize(); // [GIVEN] IRS Reporting Period with Form "F" and Form Box "FB" - LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate()); + PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate()); FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate()); FormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo); @@ -1444,13 +1445,61 @@ codeunit 148010 "IRS 1099 Document Tests" LibraryPurchase.CreatePurchaseLineWithUnitCost(PurchaseLine, PurchaseHeader, LibraryInventory.CreateItemNo(), 1, 100); InvNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true); - // [WHEN] Validate "IRS 1099 Form Box No." in the vendor ledger entry + // [WHEN] Validate the IRS 1099 fields in the vendor ledger entry LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo); // [THEN] No error is raised for a vendor that has 1099 setup + VendorLedgEntry.Validate("IRS 1099 Reporting Period", PeriodNo); + VendorLedgEntry.Validate("IRS 1099 Form No.", FormNo); VendorLedgEntry.Validate("IRS 1099 Form Box No.", FormBoxNo); VendorLedgEntry.TestField("IRS 1099 Form Box No.", FormBoxNo); end; + [Test] + procedure ValidateIRS1099FormAndFormBoxOnVendLedgEntryForNon1099Vendor() + var + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + VendorLedgEntry: Record "Vendor Ledger Entry"; + VendNo: Code[20]; + FormNo: Code[20]; + FormBoxNo: Code[20]; + PeriodNo: Code[20]; + InvNo: Code[20]; + begin + // [FEATURE] [AI test] + // [SCENARIO 620132] Setting IRS 1099 Form No. or Form Box No. on vendor ledger entry of a vendor with no 1099 setup raises an error + + Initialize(); + // [GIVEN] IRS Reporting Period "P" with form "F" and form box "FB" + PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate()); + FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate()); + FormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo); + + // [GIVEN] Vendor "V" with NO IRS 1099 form box setup (plain vendor) + VendNo := LibraryPurchase.CreateVendorNo(); + + // [GIVEN] Posted purchase invoice for vendor "V", with IRS period set directly (bypassing validation) + LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Invoice, VendNo); + LibraryPurchase.CreatePurchaseLineWithUnitCost(PurchaseLine, PurchaseHeader, LibraryInventory.CreateItemNo(), 1, 100); + InvNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true); + LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo); + VendorLedgEntry."IRS 1099 Reporting Period" := PeriodNo; + VendorLedgEntry.Modify(); + + // [WHEN] Validate "IRS 1099 Form No." in the vendor ledger entry + // [THEN] An error is raised because vendor "V" has no 1099 setup for the period + asserterror VendorLedgEntry.Validate("IRS 1099 Form No.", FormNo); + Assert.ExpectedError(StrSubstNo(VendorNotSetupForIRS1099Err, VendNo, PeriodNo)); + + // [WHEN] Validate "IRS 1099 Form Box No." in the vendor ledger entry + // [THEN] An error is raised because vendor "V" has no 1099 setup for the period + LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo); + VendorLedgEntry."IRS 1099 Reporting Period" := PeriodNo; + VendorLedgEntry."IRS 1099 Form No." := FormNo; + asserterror VendorLedgEntry.Validate("IRS 1099 Form Box No.", FormBoxNo); + Assert.ExpectedError(StrSubstNo(VendorNotSetupForIRS1099Err, VendNo, PeriodNo)); + end; + [Test] procedure ClearIRS1099PeriodOnVendLedgEntryForNon1099Vendor() var