From b4da8a8b4ead446ec58ad8acff5bde1ab7457542 Mon Sep 17 00:00:00 2001 From: Jatin Kumar Date: Thu, 22 Oct 2026 21:13:21 +0530 Subject: [PATCH 1/3] Hide irrelevant VAT fields in North American setup cards and templates --- .../Account/GLAccountCard.Page.al | 6 + .../Inventory/Item/ItemTemplCard.Page.al | 9 +- .../Purchases/Vendor/VendorTemplCard.Page.al | 9 +- .../Sales/Customer/CustomerTemplCard.Page.al | 6 + .../Tests/SMB/O365TemplatesTest.Codeunit.al | 248 +++++++++++++++++- 5 files changed, 275 insertions(+), 3 deletions(-) diff --git a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Account/GLAccountCard.Page.al b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Account/GLAccountCard.Page.al index e1a4bf03f00..4ed8a72a644 100644 --- a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Account/GLAccountCard.Page.al +++ b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Account/GLAccountCard.Page.al @@ -215,11 +215,13 @@ page 17 "G/L Account Card" { ApplicationArea = Basic, Suite; Importance = Promoted; + Visible = VATInUse; } field("VAT Prod. Posting Group"; Rec."VAT Prod. Posting Group") { ApplicationArea = Basic, Suite; Importance = Promoted; + Visible = VATInUse; } field("Tax Group Code"; Rec."Tax Group Code") { @@ -734,6 +736,7 @@ page 17 "G/L Account Card" var ExtendedPriceEnabled: Boolean; + VATInUse: Boolean; SubCategoryDescription: Text[80]; local procedure UpdateAccountSubcategoryDescription() @@ -744,8 +747,11 @@ page 17 "G/L Account Card" local procedure SetControlVisibility() var + GLSetup: Record "General Ledger Setup"; PriceCalculationMgt: Codeunit "Price Calculation Mgt."; begin + GLSetup.Get(); + VATInUse := GLSetup."VAT in Use"; ExtendedPriceEnabled := PriceCalculationMgt.IsExtendedPriceCalculationEnabled(); end; } \ No newline at end of file diff --git a/src/Layers/NA/BaseApp/Inventory/Item/ItemTemplCard.Page.al b/src/Layers/NA/BaseApp/Inventory/Item/ItemTemplCard.Page.al index 4e76c227362..f3b2c9c7fcb 100644 --- a/src/Layers/NA/BaseApp/Inventory/Item/ItemTemplCard.Page.al +++ b/src/Layers/NA/BaseApp/Inventory/Item/ItemTemplCard.Page.al @@ -5,6 +5,7 @@ namespace Microsoft.Inventory.Item; using Microsoft.Finance.Dimension; +using Microsoft.Finance.GeneralLedger.Setup; using Microsoft.Inventory.Planning; using Microsoft.Inventory.Setup; @@ -209,6 +210,7 @@ page 1384 "Item Templ. Card" ApplicationArea = Basic, Suite; Importance = Additional; ShowMandatory = true; + Visible = VATInUse; } field("Tax Group Code"; Rec."Tax Group Code") { @@ -253,7 +255,7 @@ page 1384 "Item Templ. Card" } field("Price Includes VAT"; Rec."Price Includes VAT") { - ApplicationArea = Basic, Suite; + ApplicationArea = VAT; Importance = Additional; } field("Price/Profit Calculation"; Rec."Price/Profit Calculation") @@ -593,13 +595,18 @@ page 1384 "Item Templ. Card" end; trigger OnOpenPage() + var + GLSetup: Record "General Ledger Setup"; begin + GLSetup.Get(); + VATInUse := GLSetup."VAT in Use"; EnablePlanningControls(); EnableShowVariantMandatory(); end; var ShowVariantMandatoryDefaultYes: Boolean; + VATInUse: Boolean; protected var TimeBucketEnable: Boolean; diff --git a/src/Layers/NA/BaseApp/Purchases/Vendor/VendorTemplCard.Page.al b/src/Layers/NA/BaseApp/Purchases/Vendor/VendorTemplCard.Page.al index 701c1eae1ca..f9e025f3c46 100644 --- a/src/Layers/NA/BaseApp/Purchases/Vendor/VendorTemplCard.Page.al +++ b/src/Layers/NA/BaseApp/Purchases/Vendor/VendorTemplCard.Page.al @@ -5,6 +5,7 @@ namespace Microsoft.Purchases.Vendor; using Microsoft.Finance.Dimension; +using Microsoft.Finance.GeneralLedger.Setup; using Microsoft.Foundation.Address; page 1386 "Vendor Templ. Card" @@ -216,7 +217,7 @@ page 1386 "Vendor Templ. Card" } field("Prices Including VAT"; Rec."Prices Including VAT") { - ApplicationArea = Basic, Suite; + ApplicationArea = VAT; Importance = Additional; } field("Price Calculation Method"; Rec."Price Calculation Method") @@ -238,6 +239,7 @@ page 1386 "Vendor Templ. Card" { ApplicationArea = Basic, Suite; Importance = Additional; + Visible = VATInUse; } field("Vendor Posting Group"; Rec."Vendor Posting Group") { @@ -443,11 +445,16 @@ page 1386 "Vendor Templ. Card" } trigger OnOpenPage() + var + GLSetup: Record "General Ledger Setup"; begin + GLSetup.Get(); + VATInUse := GLSetup."VAT in Use"; IsCountyVisible := FormatAddress.UseCounty(Rec."Country/Region Code"); end; var FormatAddress: Codeunit "Format Address"; IsCountyVisible: Boolean; + VATInUse: Boolean; } \ No newline at end of file diff --git a/src/Layers/NA/BaseApp/Sales/Customer/CustomerTemplCard.Page.al b/src/Layers/NA/BaseApp/Sales/Customer/CustomerTemplCard.Page.al index 7d271c6fa79..5ccfc944a9b 100644 --- a/src/Layers/NA/BaseApp/Sales/Customer/CustomerTemplCard.Page.al +++ b/src/Layers/NA/BaseApp/Sales/Customer/CustomerTemplCard.Page.al @@ -5,6 +5,7 @@ namespace Microsoft.Sales.Customer; using Microsoft.Finance.Dimension; +using Microsoft.Finance.GeneralLedger.Setup; using Microsoft.Foundation.Address; using Microsoft.Pricing.Calculation; using Microsoft.Sales.Setup; @@ -268,6 +269,7 @@ page 1382 "Customer Templ. Card" { ApplicationArea = Basic, Suite; Importance = Additional; + Visible = VATInUse; } field("Customer Posting Group"; Rec."Customer Posting Group") { @@ -518,8 +520,11 @@ page 1382 "Customer Templ. Card" trigger OnOpenPage() var + GLSetup: Record "General Ledger Setup"; PriceCalculationMgt: Codeunit "Price Calculation Mgt."; begin + GLSetup.Get(); + VATInUse := GLSetup."VAT in Use"; IsCountyVisible := FormatAddress.UseCounty(Rec."Country/Region Code"); SalesReceivablesSetup.Get(); IsAllowMultiplePostingGroupsVisible := SalesReceivablesSetup."Allow Multiple Posting Groups"; @@ -532,4 +537,5 @@ page 1382 "Customer Templ. Card" ExtendedPriceEnabled: Boolean; IsAllowMultiplePostingGroupsVisible: Boolean; IsCountyVisible: Boolean; + VATInUse: Boolean; } diff --git a/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al b/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al index c2edb04bbf8..25355272857 100644 --- a/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al +++ b/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al @@ -1602,6 +1602,193 @@ codeunit 138012 "O365 Templates Test" VerifyItemAfterApplyTemplateWithPhysInvtCountingPeriod(Item, ItemTempl); end; + [Test] + procedure ItemTemplateVATFieldsHiddenWhenVATNotInUse() + var + ItemTemplate: Record "Item Templ."; + ItemTemplateCard: TestPage "Item Templ. Card"; + begin + // [FEATURE] [AI test 1.0] + // [SCENARIO] Item templates hide VAT posting fields without hiding sales tax fields when VAT is not in use. + Initialize(); + + // [GIVEN] An item template with VAT in Use disabled while VAT and sales tax application areas are enabled. + SetVATInUse(false); + LibraryTemplates.CreateItemTemplateWithData(ItemTemplate); + + // [WHEN] The item template card is opened. + ItemTemplateCard.OpenView(); + ItemTemplateCard.GoToRecord(ItemTemplate); + + // [THEN] VAT posting fields are hidden and the sales tax field remains visible. + VerifyItemTemplateVATFieldVisibility(ItemTemplateCard, false); + ItemTemplateCard.Close(); + end; + + [Test] + procedure GLAccountVATFieldsHiddenWhenVATNotInUse() + var + GLAccount: Record "G/L Account"; + GLAccountCard: TestPage "G/L Account Card"; + begin + // [FEATURE] [AI test 1.0] + // [SCENARIO] G/L accounts hide VAT posting fields without hiding sales tax fields when VAT is not in use. + Initialize(); + + // [GIVEN] A G/L account with VAT in Use disabled while VAT and sales tax application areas are enabled. + SetVATInUse(false); + LibraryERM.CreateGLAccount(GLAccount); + + // [WHEN] The G/L account card is opened. + GLAccountCard.OpenView(); + GLAccountCard.GoToRecord(GLAccount); + + // [THEN] VAT posting fields are hidden and the sales tax field remains visible. + VerifyGLAccountVATFieldVisibility(GLAccountCard, false); + GLAccountCard.Close(); + end; + + [Test] + procedure CustomerTemplateVATPostingHiddenWhenVATNotInUse() + var + CustomerTemplate: Record "Customer Templ."; + CustomerTemplateCard: TestPage "Customer Templ. Card"; + begin + // [FEATURE] [AI test 1.0] + // [SCENARIO] Customer templates hide VAT posting setup without hiding general posting setup when VAT is not in use. + Initialize(); + + // [GIVEN] A customer template with VAT in Use disabled while the VAT application area is enabled. + SetVATInUse(false); + LibraryTemplates.CreateCustomerTemplate(CustomerTemplate); + + // [WHEN] The customer template card is opened. + CustomerTemplateCard.OpenView(); + CustomerTemplateCard.GoToRecord(CustomerTemplate); + + // [THEN] Only the VAT posting group is hidden. + Assert.IsFalse(CustomerTemplateCard."VAT Bus. Posting Group".Visible(), 'Customer template VAT posting group must be hidden when VAT is not in use.'); + Assert.IsTrue(CustomerTemplateCard."Gen. Bus. Posting Group".Visible(), 'Customer template general posting group must remain visible.'); + Assert.IsTrue(CustomerTemplateCard."Customer Posting Group".Visible(), 'Customer posting group must remain visible.'); + CustomerTemplateCard.Close(); + end; + + [Test] + procedure VendorTemplateVATPostingHiddenWhenVATNotInUse() + var + VendorTemplate: Record "Vendor Templ."; + VendorTemplateCard: TestPage "Vendor Templ. Card"; + begin + // [FEATURE] [AI test 1.0] + // [SCENARIO] Vendor templates hide VAT posting setup without hiding general posting setup when VAT is not in use. + Initialize(); + + // [GIVEN] A vendor template with VAT in Use disabled while the VAT application area is enabled. + SetVATInUse(false); + LibraryTemplates.CreateVendorTemplate(VendorTemplate); + + // [WHEN] The vendor template card is opened. + VendorTemplateCard.OpenView(); + VendorTemplateCard.GoToRecord(VendorTemplate); + + // [THEN] Only the VAT posting group is hidden. + Assert.IsFalse(VendorTemplateCard."VAT Bus. Posting Group".Visible(), 'Vendor template VAT posting group must be hidden when VAT is not in use.'); + Assert.IsTrue(VendorTemplateCard."Gen. Bus. Posting Group".Visible(), 'Vendor template general posting group must remain visible.'); + Assert.IsTrue(VendorTemplateCard."Vendor Posting Group".Visible(), 'Vendor posting group must remain visible.'); + VendorTemplateCard.Close(); + end; + + [Test] + procedure VATPostingFieldsVisibleWhenVATInUse() + var + ItemTemplate: Record "Item Templ."; + UpdatedItemTemplate: Record "Item Templ."; + GLAccount: Record "G/L Account"; + CustomerTemplate: Record "Customer Templ."; + VendorTemplate: Record "Vendor Templ."; + ItemTemplateCard: TestPage "Item Templ. Card"; + GLAccountCard: TestPage "G/L Account Card"; + CustomerTemplateCard: TestPage "Customer Templ. Card"; + VendorTemplateCard: TestPage "Vendor Templ. Card"; + begin + // [FEATURE] [AI test 1.0] + // [SCENARIO] VAT posting fields follow VAT in Use when the same template and account cards are reopened. + Initialize(); + + // [GIVEN] Templates and a G/L account in a company that uses VAT. + SetVATInUse(true); + LibraryTemplates.CreateItemTemplateWithData(ItemTemplate); + LibraryERM.CreateGLAccount(GLAccount); + LibraryTemplates.CreateCustomerTemplate(CustomerTemplate); + LibraryTemplates.CreateVendorTemplate(VendorTemplate); + + // [WHEN] The cards are opened. + ItemTemplateCard.OpenView(); + ItemTemplateCard.GoToRecord(ItemTemplate); + GLAccountCard.OpenView(); + GLAccountCard.GoToRecord(GLAccount); + CustomerTemplateCard.OpenView(); + CustomerTemplateCard.GoToRecord(CustomerTemplate); + VendorTemplateCard.OpenView(); + VendorTemplateCard.GoToRecord(VendorTemplate); + + // [THEN] VAT posting fields and sales tax fields remain visible. + VerifyItemTemplateVATFieldVisibility(ItemTemplateCard, true); + VerifyGLAccountVATFieldVisibility(GLAccountCard, true); + Assert.IsTrue(CustomerTemplateCard."VAT Bus. Posting Group".Visible(), 'Customer template VAT posting group must be visible when VAT is in use.'); + Assert.IsTrue(VendorTemplateCard."VAT Bus. Posting Group".Visible(), 'Vendor template VAT posting group must be visible when VAT is in use.'); + VendorTemplateCard.Close(); + CustomerTemplateCard.Close(); + GLAccountCard.Close(); + ItemTemplateCard.Close(); + + // [WHEN] VAT is disabled and the same records are reopened. + SetVATInUse(false); + ItemTemplateCard.OpenView(); + ItemTemplateCard.GoToRecord(ItemTemplate); + GLAccountCard.OpenView(); + GLAccountCard.GoToRecord(GLAccount); + CustomerTemplateCard.OpenView(); + CustomerTemplateCard.GoToRecord(CustomerTemplate); + VendorTemplateCard.OpenView(); + VendorTemplateCard.GoToRecord(VendorTemplate); + + // [THEN] VAT posting fields are hidden without hiding sales tax or clearing the item's stored VAT posting group. + VerifyItemTemplateVATFieldVisibility(ItemTemplateCard, false); + VerifyGLAccountVATFieldVisibility(GLAccountCard, false); + Assert.IsFalse(CustomerTemplateCard."VAT Bus. Posting Group".Visible(), 'Customer template must reload VAT in Use when reopened.'); + Assert.IsFalse(VendorTemplateCard."VAT Bus. Posting Group".Visible(), 'Vendor template must reload VAT in Use when reopened.'); + VendorTemplateCard.Close(); + CustomerTemplateCard.Close(); + GLAccountCard.Close(); + ItemTemplateCard.Close(); + + UpdatedItemTemplate.Get(ItemTemplate.Code); + UpdatedItemTemplate.TestField("VAT Prod. Posting Group", ItemTemplate."VAT Prod. Posting Group"); + end; + + [Test] + procedure TemplateVATPricesHiddenWithoutVATApplicationArea() + begin + // [FEATURE] [AI test 1.0] + // [SCENARIO] Template VAT pricing fields are hidden for sales tax application areas even when VAT is in use. + Initialize(); + SetVATInUse(true); + LibraryApplicationArea.EnableSalesTaxSetup(); + VerifyTemplateVATPriceVisibility(false); + end; + + [Test] + procedure TemplateVATPricesVisibleWithVATApplicationArea() + begin + // [FEATURE] [AI test 1.0] + // [SCENARIO] Template VAT pricing fields follow their master cards when the VAT application area is enabled. + Initialize(); + SetVATInUse(false); + LibraryApplicationArea.EnableFoundationSetup(); + VerifyTemplateVATPriceVisibility(true); + end; + local procedure Initialize() var SalesSetup: Record "Sales & Receivables Setup"; @@ -1610,6 +1797,7 @@ codeunit 138012 "O365 Templates Test" DeleteConfigurationTemplates(); LibraryVariableStorage.Clear(); LibrarySetupStorage.Restore(); + LibraryApplicationArea.EnableFoundationSetup(); // Lazy Setup. if isInitialized then @@ -1629,11 +1817,11 @@ codeunit 138012 "O365 Templates Test" if not LibraryFiscalYear.AccountingPeriodsExists() then LibraryFiscalYear.CreateFiscalYear(); - LibraryApplicationArea.EnableFoundationSetup(); LibrarySetupStorage.Save(DATABASE::"Marketing Setup"); LibrarySetupStorage.Save(DATABASE::"Sales & Receivables Setup"); LibrarySetupStorage.Save(DATABASE::"Purchases & Payables Setup"); LibrarySetupStorage.Save(DATABASE::"Inventory Setup"); + LibrarySetupStorage.Save(DATABASE::"General Ledger Setup"); SalesSetup.Get(); SalesSetup."Stockout Warning" := false; @@ -1644,6 +1832,64 @@ codeunit 138012 "O365 Templates Test" LibraryTestInitialize.OnAfterTestSuiteInitialize(CODEUNIT::"O365 Templates Test"); end; + local procedure SetVATInUse(VATInUse: Boolean) + var + ApplicationAreaSetup: Record "Application Area Setup"; + GeneralLedgerSetup: Record "General Ledger Setup"; + ApplicationAreaMgmtFacade: Codeunit "Application Area Mgmt. Facade"; + begin + LibraryApplicationArea.EnableSalesTaxSetup(); + ApplicationAreaSetup.Get(CompanyName(), '', ''); + ApplicationAreaSetup.Validate(VAT, true); + ApplicationAreaSetup.Modify(true); + ApplicationAreaMgmtFacade.SetupApplicationArea(); + GeneralLedgerSetup.Get(); + GeneralLedgerSetup.Validate("VAT in Use", VATInUse); + GeneralLedgerSetup.Modify(true); + end; + + local procedure VerifyItemTemplateVATFieldVisibility(var ItemTemplateCard: TestPage "Item Templ. Card"; VATInUse: Boolean) + begin + Assert.AreEqual(VATInUse, ItemTemplateCard."VAT Prod. Posting Group".Visible(), 'Item template VAT posting field visibility must follow VAT in Use.'); + Assert.IsTrue(ItemTemplateCard."Tax Group Code".Visible(), 'Item template Tax Group Code must remain visible for sales tax.'); + end; + + local procedure VerifyGLAccountVATFieldVisibility(var GLAccountCard: TestPage "G/L Account Card"; VATInUse: Boolean) + begin + Assert.AreEqual(VATInUse, GLAccountCard."VAT Bus. Posting Group".Visible(), 'G/L account VAT business posting field visibility must follow VAT in Use.'); + Assert.AreEqual(VATInUse, GLAccountCard."VAT Prod. Posting Group".Visible(), 'G/L account VAT product posting field visibility must follow VAT in Use.'); + Assert.IsTrue(GLAccountCard."Tax Group Code".Visible(), 'G/L account Tax Group Code must remain visible for sales tax.'); + end; + + local procedure VerifyTemplateVATPriceVisibility(ExpectedVisible: Boolean) + var + ItemTemplate: Record "Item Templ."; + CustomerTemplate: Record "Customer Templ."; + VendorTemplate: Record "Vendor Templ."; + ItemTemplateCard: TestPage "Item Templ. Card"; + CustomerTemplateCard: TestPage "Customer Templ. Card"; + VendorTemplateCard: TestPage "Vendor Templ. Card"; + begin + LibraryTemplates.CreateItemTemplate(ItemTemplate); + LibraryTemplates.CreateCustomerTemplate(CustomerTemplate); + LibraryTemplates.CreateVendorTemplate(VendorTemplate); + + ItemTemplateCard.OpenView(); + ItemTemplateCard.GoToRecord(ItemTemplate); + CustomerTemplateCard.OpenView(); + CustomerTemplateCard.GoToRecord(CustomerTemplate); + VendorTemplateCard.OpenView(); + VendorTemplateCard.GoToRecord(VendorTemplate); + + Assert.AreEqual(ExpectedVisible, ItemTemplateCard."Price Includes VAT".Visible(), 'Item template VAT pricing visibility must follow the VAT application area.'); + Assert.AreEqual(ExpectedVisible, CustomerTemplateCard."Prices Including VAT".Visible(), 'Customer template VAT pricing visibility must follow the VAT application area.'); + Assert.AreEqual(ExpectedVisible, VendorTemplateCard."Prices Including VAT".Visible(), 'Vendor template VAT pricing visibility must follow the VAT application area.'); + + VendorTemplateCard.Close(); + CustomerTemplateCard.Close(); + ItemTemplateCard.Close(); + end; + local procedure ClearTable(TableID: Integer) var Job: Record Job; From 11a33fde63556054ef74996c6a0d200b51ab934d Mon Sep 17 00:00:00 2001 From: Jatin Kumar Date: Fri, 23 Oct 2026 02:33:02 +0530 Subject: [PATCH 2/3] Hide resource VAT posting group when VAT is off --- .../Resources/Resource/ResourceCard.Page.al | 6 ++ .../Tests/SMB/O365TemplatesTest.Codeunit.al | 98 ++++++++++++++++--- 2 files changed, 93 insertions(+), 11 deletions(-) diff --git a/src/Layers/NA/BaseApp/Projects/Resources/Resource/ResourceCard.Page.al b/src/Layers/NA/BaseApp/Projects/Resources/Resource/ResourceCard.Page.al index 234e10ab9c5..b917466af20 100644 --- a/src/Layers/NA/BaseApp/Projects/Resources/Resource/ResourceCard.Page.al +++ b/src/Layers/NA/BaseApp/Projects/Resources/Resource/ResourceCard.Page.al @@ -5,6 +5,7 @@ namespace Microsoft.Projects.Resources.Resource; using Microsoft.Finance.Dimension; +using Microsoft.Finance.GeneralLedger.Setup; using Microsoft.Foundation.Address; using Microsoft.Foundation.Attachment; using Microsoft.Foundation.Comment; @@ -145,6 +146,7 @@ page 76 "Resource Card" { ApplicationArea = Basic, Suite; Importance = Promoted; + Visible = VATInUse; } field("Default Deferral Template Code"; Rec."Default Deferral Template Code") { @@ -739,8 +741,11 @@ page 76 "Resource Card" trigger OnOpenPage() var + GLSetup: Record "General Ledger Setup"; IntegrationTableMapping: Record "Integration Table Mapping"; begin + GLSetup.Get(); + VATInUse := GLSetup."VAT in Use"; CRMIntegrationEnabled := CRMIntegrationManagement.IsCRMIntegrationEnabled(); if IntegrationTableMapping.Get('RESOURCE-PRODUCT') then BlockedFilterApplied := IntegrationTableMapping.GetTableFilter().Contains('Field38=1(0)'); @@ -759,6 +764,7 @@ page 76 "Resource Card" ExtendedPriceEnabled: Boolean; NoFieldVisible: Boolean; IsCountyVisible: Boolean; + VATInUse: Boolean; local procedure SetNoFieldVisible() var diff --git a/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al b/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al index 25355272857..b166017cbac 100644 --- a/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al +++ b/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al @@ -12,6 +12,7 @@ codeunit 138012 "O365 Templates Test" LibraryInventory: Codeunit "Library - Inventory"; LibraryPurchase: Codeunit "Library - Purchase"; LibrarySales: Codeunit "Library - Sales"; + LibraryResource: Codeunit "Library - Resource"; LibraryRandom: Codeunit "Library - Random"; LibraryVariableStorage: Codeunit "Library - Variable Storage"; LibraryUtility: Codeunit "Library - Utility"; @@ -36,6 +37,7 @@ codeunit 138012 "O365 Templates Test" StartingNumberTxt: Label 'ABC00010D'; EndingNumberTxt: Label 'ABC00090D'; InsertedItemErr: Label 'Item inserted with wrong data'; + PageFieldNotFoundErr: Label 'The field with ID = %1 is not found on the page.', Locked = true, Comment = '%1 = page control ID'; [Test] [HandlerFunctions('CustomerTemplateCardHandler')] @@ -1698,6 +1700,29 @@ codeunit 138012 "O365 Templates Test" VendorTemplateCard.Close(); end; + [Test] + procedure ResourceVATFieldHiddenWhenVATNotInUse() + var + Resource: Record Resource; + ResourceCard: TestPage "Resource Card"; + begin + // [FEATURE] [AI test 1.0] + // [SCENARIO] Resources hide VAT posting setup without hiding sales tax when VAT is not in use. + Initialize(); + + // [GIVEN] A resource with VAT in Use disabled while VAT and sales tax application areas are enabled. + SetVATInUse(false); + LibraryResource.CreateResourceNew(Resource); + + // [WHEN] The resource card is opened. + ResourceCard.OpenView(); + ResourceCard.GoToRecord(Resource); + + // [THEN] The VAT posting group is hidden and Tax Group Code remains visible. + VerifyResourceVATFieldVisibility(ResourceCard, false); + ResourceCard.Close(); + end; + [Test] procedure VATPostingFieldsVisibleWhenVATInUse() var @@ -1706,21 +1731,25 @@ codeunit 138012 "O365 Templates Test" GLAccount: Record "G/L Account"; CustomerTemplate: Record "Customer Templ."; VendorTemplate: Record "Vendor Templ."; + Resource: Record Resource; + UpdatedResource: Record Resource; ItemTemplateCard: TestPage "Item Templ. Card"; GLAccountCard: TestPage "G/L Account Card"; CustomerTemplateCard: TestPage "Customer Templ. Card"; VendorTemplateCard: TestPage "Vendor Templ. Card"; + ResourceCard: TestPage "Resource Card"; begin // [FEATURE] [AI test 1.0] - // [SCENARIO] VAT posting fields follow VAT in Use when the same template and account cards are reopened. + // [SCENARIO] VAT posting fields follow VAT in Use when the same template, account and resource cards are reopened. Initialize(); - // [GIVEN] Templates and a G/L account in a company that uses VAT. + // [GIVEN] Templates, a G/L account and a resource in a company that uses VAT. SetVATInUse(true); LibraryTemplates.CreateItemTemplateWithData(ItemTemplate); LibraryERM.CreateGLAccount(GLAccount); LibraryTemplates.CreateCustomerTemplate(CustomerTemplate); LibraryTemplates.CreateVendorTemplate(VendorTemplate); + LibraryResource.CreateResourceNew(Resource); // [WHEN] The cards are opened. ItemTemplateCard.OpenView(); @@ -1731,12 +1760,16 @@ codeunit 138012 "O365 Templates Test" CustomerTemplateCard.GoToRecord(CustomerTemplate); VendorTemplateCard.OpenView(); VendorTemplateCard.GoToRecord(VendorTemplate); + ResourceCard.OpenView(); + ResourceCard.GoToRecord(Resource); // [THEN] VAT posting fields and sales tax fields remain visible. VerifyItemTemplateVATFieldVisibility(ItemTemplateCard, true); VerifyGLAccountVATFieldVisibility(GLAccountCard, true); Assert.IsTrue(CustomerTemplateCard."VAT Bus. Posting Group".Visible(), 'Customer template VAT posting group must be visible when VAT is in use.'); Assert.IsTrue(VendorTemplateCard."VAT Bus. Posting Group".Visible(), 'Vendor template VAT posting group must be visible when VAT is in use.'); + VerifyResourceVATFieldVisibility(ResourceCard, true); + ResourceCard.Close(); VendorTemplateCard.Close(); CustomerTemplateCard.Close(); GLAccountCard.Close(); @@ -1752,12 +1785,16 @@ codeunit 138012 "O365 Templates Test" CustomerTemplateCard.GoToRecord(CustomerTemplate); VendorTemplateCard.OpenView(); VendorTemplateCard.GoToRecord(VendorTemplate); + ResourceCard.OpenView(); + ResourceCard.GoToRecord(Resource); - // [THEN] VAT posting fields are hidden without hiding sales tax or clearing the item's stored VAT posting group. + // [THEN] VAT posting fields are hidden without hiding sales tax or clearing stored VAT posting groups. VerifyItemTemplateVATFieldVisibility(ItemTemplateCard, false); VerifyGLAccountVATFieldVisibility(GLAccountCard, false); Assert.IsFalse(CustomerTemplateCard."VAT Bus. Posting Group".Visible(), 'Customer template must reload VAT in Use when reopened.'); Assert.IsFalse(VendorTemplateCard."VAT Bus. Posting Group".Visible(), 'Vendor template must reload VAT in Use when reopened.'); + VerifyResourceVATFieldVisibility(ResourceCard, false); + ResourceCard.Close(); VendorTemplateCard.Close(); CustomerTemplateCard.Close(); GLAccountCard.Close(); @@ -1765,6 +1802,8 @@ codeunit 138012 "O365 Templates Test" UpdatedItemTemplate.Get(ItemTemplate.Code); UpdatedItemTemplate.TestField("VAT Prod. Posting Group", ItemTemplate."VAT Prod. Posting Group"); + UpdatedResource.Get(Resource."No."); + UpdatedResource.TestField("VAT Prod. Posting Group", Resource."VAT Prod. Posting Group"); end; [Test] @@ -1785,7 +1824,7 @@ codeunit 138012 "O365 Templates Test" // [SCENARIO] Template VAT pricing fields follow their master cards when the VAT application area is enabled. Initialize(); SetVATInUse(false); - LibraryApplicationArea.EnableFoundationSetup(); + LibraryApplicationArea.EnableVATSetup(); VerifyTemplateVATPriceVisibility(true); end; @@ -1861,33 +1900,70 @@ codeunit 138012 "O365 Templates Test" Assert.IsTrue(GLAccountCard."Tax Group Code".Visible(), 'G/L account Tax Group Code must remain visible for sales tax.'); end; + local procedure VerifyResourceVATFieldVisibility(var ResourceCard: TestPage "Resource Card"; VATInUse: Boolean) + begin + Assert.AreEqual(VATInUse, ResourceCard."VAT Prod. Posting Group".Visible(), 'Resource VAT posting field visibility must follow VAT in Use.'); + Assert.IsTrue(ResourceCard."Tax Group Code".Visible(), 'Resource Tax Group Code must remain visible for sales tax.'); + end; + local procedure VerifyTemplateVATPriceVisibility(ExpectedVisible: Boolean) var ItemTemplate: Record "Item Templ."; CustomerTemplate: Record "Customer Templ."; VendorTemplate: Record "Vendor Templ."; + ApplicationAreaMgmtFacade: Codeunit "Application Area Mgmt. Facade"; + ExpectedErrorMessage: Text; ItemTemplateCard: TestPage "Item Templ. Card"; CustomerTemplateCard: TestPage "Customer Templ. Card"; VendorTemplateCard: TestPage "Vendor Templ. Card"; begin + Assert.AreEqual(ExpectedVisible, ApplicationAreaMgmtFacade.IsVATEnabled(), 'The VAT application area must match the test scenario.'); LibraryTemplates.CreateItemTemplate(ItemTemplate); LibraryTemplates.CreateCustomerTemplate(CustomerTemplate); LibraryTemplates.CreateVendorTemplate(VendorTemplate); ItemTemplateCard.OpenView(); ItemTemplateCard.GoToRecord(ItemTemplate); + if ExpectedVisible then + Assert.IsTrue(ItemTemplateCard."Price Includes VAT".Visible(), 'Item template VAT pricing must be visible when the VAT application area is enabled.') + else begin + ExpectedErrorMessage := GetPageFieldNotFoundError(Page::"Item Templ. Card", 'Price Includes VAT'); + asserterror ItemTemplateCard."Price Includes VAT".Activate(); + Assert.ExpectedError(ExpectedErrorMessage); + end; + ItemTemplateCard.Close(); + CustomerTemplateCard.OpenView(); CustomerTemplateCard.GoToRecord(CustomerTemplate); + if ExpectedVisible then + Assert.IsTrue(CustomerTemplateCard."Prices Including VAT".Visible(), 'Customer template VAT pricing must be visible when the VAT application area is enabled.') + else begin + ExpectedErrorMessage := GetPageFieldNotFoundError(Page::"Customer Templ. Card", 'Prices Including VAT'); + asserterror CustomerTemplateCard."Prices Including VAT".Activate(); + Assert.ExpectedError(ExpectedErrorMessage); + end; + CustomerTemplateCard.Close(); + VendorTemplateCard.OpenView(); VendorTemplateCard.GoToRecord(VendorTemplate); - - Assert.AreEqual(ExpectedVisible, ItemTemplateCard."Price Includes VAT".Visible(), 'Item template VAT pricing visibility must follow the VAT application area.'); - Assert.AreEqual(ExpectedVisible, CustomerTemplateCard."Prices Including VAT".Visible(), 'Customer template VAT pricing visibility must follow the VAT application area.'); - Assert.AreEqual(ExpectedVisible, VendorTemplateCard."Prices Including VAT".Visible(), 'Vendor template VAT pricing visibility must follow the VAT application area.'); - + if ExpectedVisible then + Assert.IsTrue(VendorTemplateCard."Prices Including VAT".Visible(), 'Vendor template VAT pricing must be visible when the VAT application area is enabled.') + else begin + ExpectedErrorMessage := GetPageFieldNotFoundError(Page::"Vendor Templ. Card", 'Prices Including VAT'); + asserterror VendorTemplateCard."Prices Including VAT".Activate(); + Assert.ExpectedError(ExpectedErrorMessage); + end; VendorTemplateCard.Close(); - CustomerTemplateCard.Close(); - ItemTemplateCard.Close(); + end; + + local procedure GetPageFieldNotFoundError(PageID: Integer; ControlName: Text): Text + var + PageControlField: Record "Page Control Field"; + begin + PageControlField.SetRange(PageNo, PageID); + PageControlField.SetRange(ControlName, ControlName); + PageControlField.FindFirst(); + exit(StrSubstNo(PageFieldNotFoundErr, PageControlField.ControlId)); end; local procedure ClearTable(TableID: Integer) From 1af2ed02f36cee18d3de2c219499f9536037c1b6 Mon Sep 17 00:00:00 2001 From: Jatin Kumar Date: Mon, 26 Oct 2026 12:29:27 +0530 Subject: [PATCH 3/3] Create each template right before its check instead of committing --- src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al b/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al index b166017cbac..6ea01684979 100644 --- a/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al +++ b/src/Layers/NA/Tests/SMB/O365TemplatesTest.Codeunit.al @@ -1918,10 +1918,8 @@ codeunit 138012 "O365 Templates Test" VendorTemplateCard: TestPage "Vendor Templ. Card"; begin Assert.AreEqual(ExpectedVisible, ApplicationAreaMgmtFacade.IsVATEnabled(), 'The VAT application area must match the test scenario.'); + // Each template is created right before its page check because asserterror rolls back uncommitted data. LibraryTemplates.CreateItemTemplate(ItemTemplate); - LibraryTemplates.CreateCustomerTemplate(CustomerTemplate); - LibraryTemplates.CreateVendorTemplate(VendorTemplate); - ItemTemplateCard.OpenView(); ItemTemplateCard.GoToRecord(ItemTemplate); if ExpectedVisible then @@ -1933,6 +1931,7 @@ codeunit 138012 "O365 Templates Test" end; ItemTemplateCard.Close(); + LibraryTemplates.CreateCustomerTemplate(CustomerTemplate); CustomerTemplateCard.OpenView(); CustomerTemplateCard.GoToRecord(CustomerTemplate); if ExpectedVisible then @@ -1944,6 +1943,7 @@ codeunit 138012 "O365 Templates Test" end; CustomerTemplateCard.Close(); + LibraryTemplates.CreateVendorTemplate(VendorTemplate); VendorTemplateCard.OpenView(); VendorTemplateCard.GoToRecord(VendorTemplate); if ExpectedVisible then