From 87105ecc97db50cdf44da8633cea6b94d5d9cc60 Mon Sep 17 00:00:00 2001 From: v-nesinghal Date: Tue, 14 Jul 2026 10:29:07 +0545 Subject: [PATCH 1/7] [Master]-]Withholding Tax Entries are not generated at payment because the Withholding Tax. Prod. Posting Group field gets not transferred to the payment line [AB#639524](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/639524) --- .../src/ERMWithholdingTaxTestsII.Codeunit.al | 86 +++++++++++++++++++ .../WithholdingTaxJnlSubscriber.Codeunit.al | 30 +++++++ 2 files changed, 116 insertions(+) diff --git a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al index e087179e4c..141fbabe0b 100644 --- a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al +++ b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al @@ -595,6 +595,75 @@ codeunit 148322 "ERM Withholding Tax Tests II" VerifyPostingNoSeriesOnePostedDoc('B0', 6, 2); end; + [Test] + [Scope('OnPrem')] + [HandlerFunctions('ConfirmHandler,CreatePaymentPageHandler,PaymentJournalPageHandler')] + procedure WHTProdPostGroupTravelsFromInvoiceToJournalLineOnApplication() + var + GenJournalLine: Record "Gen. Journal Line"; + GenJournalLine2: Record "Gen. Journal Line"; + GenJournalTemplate: Record "Gen. Journal Template"; + GenJournalBatch: Record "Gen. Journal Batch"; + VATPostingSetup: Record "VAT Posting Setup"; + WHTBusPostingGroup: Record "Wthldg. Tax Bus. Post. Group"; + WHTPostingSetup: Record "Withholding Tax Posting Setup"; + WHTProdPostingGroup: Record "Wthldg. Tax Prod. Post. Group"; + BankAccount: Record "Bank Account"; + VendorLedgerEntries: TestPage "Vendor Ledger Entries"; + DocumentNo: Code[20]; + StartingDocumentNo: Code[20]; + begin + // [SCENARIO 639524] Withholding Tax Prod. Post. Group travels from the applied Invoice to the Payment line via the Create Payment action and Withholding Tax Entries are generated when the Payment is posted. + Initialize(); + + // [GIVEN] Local functionalities enabled, VAT Posting Setup, WHT Business and Product Posting Groups. + UpdateLocalFunctionalitiesOnGeneralLedgerSetup(true); + LibraryERM.FindVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Calculation Type"::"Normal VAT"); + LibraryWithholdingTax.CreateWHTBusinessPostingGroup(WHTBusPostingGroup); + LibraryWithholdingTax.CreateWHTProductPostingGroup(WHTProdPostingGroup); + + // [GIVEN] A fully-initialized Withholding Tax Posting Setup (all required accounts) so the invoice/payment posting pipeline does not resolve to a partial setup and produce inconsistent G/L entries. + CreateWHTPostingSetup( + WHTPostingSetup, WHTBusPostingGroup.Code, WHTProdPostingGroup.Code, '', + LibraryRandom.RandDecInRange(50, 100, 2)); // WHT Minimum Invoice Amount. + + // [GIVEN] A posted Purchase Invoice for a WHT liable Vendor with WHT absorb base updated and expected WHT Amount calculated. + CreateGeneralJournalLineWithBalAccountType( + GenJournalLine, GenJournalLine."Document Type"::Invoice, CreateVendor(VATPostingSetup."VAT Bus. Posting Group", WHTBusPostingGroup.Code), '', + '', GenJournalLine."Bal. Account Type"::"G/L Account", CreateGLAccountWithVATBusPostingGroup(VATPostingSetup, WHTProdPostingGroup.Code), + -LibraryRandom.RandDecInRange(100, 200, 2)); // Blank - WHT Bus Posting Group, Applies To Doc. No, Currency, Random - Direct unit cost. + UpdateGenJournalLineWHTAbsorbBase(GenJournalLine); + GenJournalLine.TestField("Wthldg. Tax Bus. Post. Group", WHTBusPostingGroup.Code); + GenJournalLine.TestField("Wthldg. Tax Prod. Post. Group", WHTProdPostingGroup.Code); + LibraryERM.PostGeneralJnlLine(GenJournalLine); + DocumentNo := FindVendorLedgerEntry(GenJournalLine."Account No."); + + // [GIVEN] A Payments Gen. Journal Template and Batch and a Bank Account for the Create Payment action. + GenJournalTemplate.SetRange(Type, GenJournalTemplate.Type::Payments); + LibraryERM.FindGenJournalTemplate(GenJournalTemplate); + LibraryERM.CreateGenJournalBatch(GenJournalBatch, GenJournalTemplate.Name); + LibraryERM.CreateBankAccount(BankAccount); + StartingDocumentNo := LibraryUtility.GenerateGUID(); + + LibraryVariableStorage.Enqueue(GenJournalTemplate.Name); + LibraryVariableStorage.Enqueue(GenJournalBatch.Name); + LibraryVariableStorage.Enqueue(StartingDocumentNo); + LibraryVariableStorage.Enqueue(BankAccount."No."); + + // [WHEN] The user filters the Vendor Ledger Entries page to the posted Invoice and invokes the Create Payment action. + VendorLedgerEntries.OpenView(); + VendorLedgerEntries.Filter.SetFilter("Document No.", DocumentNo); + VendorLedgerEntries."Create Payment".Invoke(); + VendorLedgerEntries.Close(); + + // [THEN] The WHT Prod. Post. Group on the generated Payment line is copied from the applied Invoice. + GenJournalLine2.SetRange("Journal Template Name", GenJournalTemplate.Name); + GenJournalLine2.SetRange("Journal Batch Name", GenJournalBatch.Name); + GenJournalLine2.SetRange("Document No.", StartingDocumentNo); + GenJournalLine2.FindFirst(); + GenJournalLine2.TestField("Wthldg. Tax Prod. Post. Group", WHTProdPostingGroup.Code); + end; + local procedure Initialize() var VATPostingSetup: Record "VAT Posting Setup"; @@ -1116,4 +1185,21 @@ codeunit 148322 "ERM Withholding Tax Tests II" begin Reply := true; end; + + [ModalPageHandler] + [Scope('OnPrem')] + procedure CreatePaymentPageHandler(var CreatePayment: TestPage "Create Payment") + begin + CreatePayment."Template Name".SetValue(LibraryVariableStorage.DequeueText()); + CreatePayment."Batch Name".SetValue(LibraryVariableStorage.DequeueText()); + CreatePayment."Starting Document No.".SetValue(LibraryVariableStorage.DequeueText()); + CreatePayment."Bank Account".SetValue(LibraryVariableStorage.DequeueText()); + CreatePayment.OK().Invoke(); + end; + + [PageHandler] + [Scope('OnPrem')] + procedure PaymentJournalPageHandler(var PaymentJournal: TestPage "Payment Journal") + begin + end; } \ No newline at end of file diff --git a/src/Apps/W1/WithholdingTax/app/src/Purchase/Transaction/WithholdingTaxJnlSubscriber.Codeunit.al b/src/Apps/W1/WithholdingTax/app/src/Purchase/Transaction/WithholdingTaxJnlSubscriber.Codeunit.al index 0b495a8881..bc08a0dfb6 100644 --- a/src/Apps/W1/WithholdingTax/app/src/Purchase/Transaction/WithholdingTaxJnlSubscriber.Codeunit.al +++ b/src/Apps/W1/WithholdingTax/app/src/Purchase/Transaction/WithholdingTaxJnlSubscriber.Codeunit.al @@ -1683,6 +1683,36 @@ codeunit 6786 "Withholding Tax Jnl Subscriber" PostUnrealizedWHT(GenJournalLine, GenJnlPostLine); end; + + [EventSubscriber(ObjectType::Page, Page::"Create Payment", OnBeforeUpdateGnlJnlLineDimensionsFromVendorPayment, '', false, false)] + local procedure AssignWHTPostingGroupOnCreatePayment(var GenJournalLine: Record "Gen. Journal Line"; TempVendorPaymentBuffer: Record "Vendor Payment Buffer" temporary) + var + VendorLedgerEntry: Record "Vendor Ledger Entry"; + WithholdingTaxEntry: Record "Withholding Tax Entry"; + begin + if CheckWithholdingTaxDisabled() then + exit; + + if GenJournalLine."Applies-to ID" = '' then + exit; + + if TempVendorPaymentBuffer."Vendor Ledg. Entry No." = 0 then + exit; + + VendorLedgerEntry.SetLoadFields("Document No.", "Vendor No."); + VendorLedgerEntry.Get(TempVendorPaymentBuffer."Vendor Ledg. Entry No."); + + WithholdingTaxEntry.SetLoadFields("Wthldg. Tax Prod. Post. Group"); + WithholdingTaxEntry.SetRange("Document No.", VendorLedgerEntry."Document No."); + WithholdingTaxEntry.SetRange("Transaction Type", WithholdingTaxEntry."Transaction Type"::Purchase); + WithholdingTaxEntry.SetRange("Document Type", WithholdingTaxEntry."Document Type"::Invoice); + WithholdingTaxEntry.SetRange("Bill-to/Pay-to No.", VendorLedgerEntry."Vendor No."); + if not WithholdingTaxEntry.FindFirst() then + exit; + + GenJournalLine."Wthldg. Tax Prod. Post. Group" := WithholdingTaxEntry."Wthldg. Tax Prod. Post. Group"; + end; + local procedure PostUnrealizedWHT(var GenJnlLine: Record "Gen. Journal Line"; var GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line") var GenJournalLineWHT: Record "Gen. Journal Line"; From c83343d41e96eb1fac5af708ec8b348128a80855 Mon Sep 17 00:00:00 2001 From: v-nesinghal Date: Wed, 15 Jul 2026 10:27:41 +0545 Subject: [PATCH 2/7] change in fix --- .../Test/src/ERMWithholdingTaxTestsII.Codeunit.al | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al index 141fbabe0b..26ff6043bb 100644 --- a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al +++ b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al @@ -597,7 +597,7 @@ codeunit 148322 "ERM Withholding Tax Tests II" [Test] [Scope('OnPrem')] - [HandlerFunctions('ConfirmHandler,CreatePaymentPageHandler,PaymentJournalPageHandler')] + [HandlerFunctions('ConfirmHandler,CreatePaymentPageHandler')] procedure WHTProdPostGroupTravelsFromInvoiceToJournalLineOnApplication() var GenJournalLine: Record "Gen. Journal Line"; @@ -610,6 +610,7 @@ codeunit 148322 "ERM Withholding Tax Tests II" WHTProdPostingGroup: Record "Wthldg. Tax Prod. Post. Group"; BankAccount: Record "Bank Account"; VendorLedgerEntries: TestPage "Vendor Ledger Entries"; + PaymentJournal: TestPage "Payment Journal"; DocumentNo: Code[20]; StartingDocumentNo: Code[20]; begin @@ -653,7 +654,9 @@ codeunit 148322 "ERM Withholding Tax Tests II" // [WHEN] The user filters the Vendor Ledger Entries page to the posted Invoice and invokes the Create Payment action. VendorLedgerEntries.OpenView(); VendorLedgerEntries.Filter.SetFilter("Document No.", DocumentNo); + PaymentJournal.Trap(); VendorLedgerEntries."Create Payment".Invoke(); + PaymentJournal.OK().Invoke(); VendorLedgerEntries.Close(); // [THEN] The WHT Prod. Post. Group on the generated Payment line is copied from the applied Invoice. @@ -1196,10 +1199,4 @@ codeunit 148322 "ERM Withholding Tax Tests II" CreatePayment."Bank Account".SetValue(LibraryVariableStorage.DequeueText()); CreatePayment.OK().Invoke(); end; - - [PageHandler] - [Scope('OnPrem')] - procedure PaymentJournalPageHandler(var PaymentJournal: TestPage "Payment Journal") - begin - end; } \ No newline at end of file From 46ca7bad267220077d48faa5cca99d564a31e858 Mon Sep 17 00:00:00 2001 From: v-nesinghal Date: Wed, 15 Jul 2026 15:20:58 +0545 Subject: [PATCH 3/7] Handle General Journal Template List popup on Create Payment (CZ multiple Payment templates) --- .../Test/src/ERMWithholdingTaxTestsII.Codeunit.al | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al index 26ff6043bb..ca9e02f4ac 100644 --- a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al +++ b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al @@ -597,7 +597,7 @@ codeunit 148322 "ERM Withholding Tax Tests II" [Test] [Scope('OnPrem')] - [HandlerFunctions('ConfirmHandler,CreatePaymentPageHandler')] + [HandlerFunctions('ConfirmHandler,GeneralJournalTemplateListPageHandler,CreatePaymentPageHandler')] procedure WHTProdPostGroupTravelsFromInvoiceToJournalLineOnApplication() var GenJournalLine: Record "Gen. Journal Line"; @@ -646,6 +646,7 @@ codeunit 148322 "ERM Withholding Tax Tests II" LibraryERM.CreateBankAccount(BankAccount); StartingDocumentNo := LibraryUtility.GenerateGUID(); + LibraryVariableStorage.Enqueue(GenJournalTemplate.Name); LibraryVariableStorage.Enqueue(GenJournalTemplate.Name); LibraryVariableStorage.Enqueue(GenJournalBatch.Name); LibraryVariableStorage.Enqueue(StartingDocumentNo); @@ -1189,6 +1190,14 @@ codeunit 148322 "ERM Withholding Tax Tests II" Reply := true; end; + [ModalPageHandler] + [Scope('OnPrem')] + procedure GeneralJournalTemplateListPageHandler(var GeneralJournalTemplateList: TestPage "General Journal Template List") + begin + GeneralJournalTemplateList.Filter.SetFilter(Name, LibraryVariableStorage.DequeueText()); + GeneralJournalTemplateList.OK().Invoke(); + end; + [ModalPageHandler] [Scope('OnPrem')] procedure CreatePaymentPageHandler(var CreatePayment: TestPage "Create Payment") From 7d3200e8da4ad48df7fb59d6a3033f29b6437595 Mon Sep 17 00:00:00 2001 From: v-nesinghal Date: Wed, 15 Jul 2026 15:23:33 +0545 Subject: [PATCH 4/7] Create dedicated Payments template so template lookup opens deterministically in W1 and localizations --- .../Test/src/ERMWithholdingTaxTestsII.Codeunit.al | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al index ca9e02f4ac..f0ff2b8f33 100644 --- a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al +++ b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al @@ -639,9 +639,10 @@ codeunit 148322 "ERM Withholding Tax Tests II" LibraryERM.PostGeneralJnlLine(GenJournalLine); DocumentNo := FindVendorLedgerEntry(GenJournalLine."Account No."); - // [GIVEN] A Payments Gen. Journal Template and Batch and a Bank Account for the Create Payment action. - GenJournalTemplate.SetRange(Type, GenJournalTemplate.Type::Payments); - LibraryERM.FindGenJournalTemplate(GenJournalTemplate); + // [GIVEN] A dedicated Payments Gen. Journal Template (ensures more than one Payments template exists so the template lookup always opens deterministically across localizations), a Batch and a Bank Account for the Create Payment action. + LibraryERM.CreateGenJournalTemplate(GenJournalTemplate); + GenJournalTemplate.Validate(Type, GenJournalTemplate.Type::Payments); + GenJournalTemplate.Modify(true); LibraryERM.CreateGenJournalBatch(GenJournalBatch, GenJournalTemplate.Name); LibraryERM.CreateBankAccount(BankAccount); StartingDocumentNo := LibraryUtility.GenerateGUID(); From 8247b984eef32674aa271de8f0942bf7f3809406 Mon Sep 17 00:00:00 2001 From: v-nesinghal Date: Wed, 15 Jul 2026 15:42:32 +0545 Subject: [PATCH 5/7] Replace Create Payment page-based test with direct Gen. Journal Line payment application scenario --- .../src/ERMWithholdingTaxTestsII.Codeunit.al | 88 +++++-------------- 1 file changed, 23 insertions(+), 65 deletions(-) diff --git a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al index f0ff2b8f33..846567fbcf 100644 --- a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al +++ b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al @@ -597,76 +597,53 @@ codeunit 148322 "ERM Withholding Tax Tests II" [Test] [Scope('OnPrem')] - [HandlerFunctions('ConfirmHandler,GeneralJournalTemplateListPageHandler,CreatePaymentPageHandler')] - procedure WHTProdPostGroupTravelsFromInvoiceToJournalLineOnApplication() + [HandlerFunctions('ConfirmHandler')] + procedure WHTProdPostGroupTravelsFromInvoiceToPaymentOnApplication() var GenJournalLine: Record "Gen. Journal Line"; GenJournalLine2: Record "Gen. Journal Line"; - GenJournalTemplate: Record "Gen. Journal Template"; - GenJournalBatch: Record "Gen. Journal Batch"; VATPostingSetup: Record "VAT Posting Setup"; + WHTEntry: Record "Withholding Tax Entry"; WHTBusPostingGroup: Record "Wthldg. Tax Bus. Post. Group"; WHTPostingSetup: Record "Withholding Tax Posting Setup"; WHTProdPostingGroup: Record "Wthldg. Tax Prod. Post. Group"; BankAccount: Record "Bank Account"; - VendorLedgerEntries: TestPage "Vendor Ledger Entries"; - PaymentJournal: TestPage "Payment Journal"; DocumentNo: Code[20]; - StartingDocumentNo: Code[20]; + WHTAmount: Decimal; begin - // [SCENARIO 639524] Withholding Tax Prod. Post. Group travels from the applied Invoice to the Payment line via the Create Payment action and Withholding Tax Entries are generated when the Payment is posted. - Initialize(); + // [SCENARIO 639524] Withholding Tax Prod. Post. Group travels from the applied invoice to the payment line and Withholding Tax Entries are generated at payment. - // [GIVEN] Local functionalities enabled, VAT Posting Setup, WHT Business and Product Posting Groups. + // [GIVEN] WHT Posting Setup realized on Payment and a posted Invoice for a WHT liable Vendor. + Initialize(); UpdateLocalFunctionalitiesOnGeneralLedgerSetup(true); LibraryERM.FindVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Calculation Type"::"Normal VAT"); LibraryWithholdingTax.CreateWHTBusinessPostingGroup(WHTBusPostingGroup); LibraryWithholdingTax.CreateWHTProductPostingGroup(WHTProdPostingGroup); - - // [GIVEN] A fully-initialized Withholding Tax Posting Setup (all required accounts) so the invoice/payment posting pipeline does not resolve to a partial setup and produce inconsistent G/L entries. - CreateWHTPostingSetup( - WHTPostingSetup, WHTBusPostingGroup.Code, WHTProdPostingGroup.Code, '', - LibraryRandom.RandDecInRange(50, 100, 2)); // WHT Minimum Invoice Amount. - - // [GIVEN] A posted Purchase Invoice for a WHT liable Vendor with WHT absorb base updated and expected WHT Amount calculated. CreateGeneralJournalLineWithBalAccountType( GenJournalLine, GenJournalLine."Document Type"::Invoice, CreateVendor(VATPostingSetup."VAT Bus. Posting Group", WHTBusPostingGroup.Code), '', '', GenJournalLine."Bal. Account Type"::"G/L Account", CreateGLAccountWithVATBusPostingGroup(VATPostingSetup, WHTProdPostingGroup.Code), -LibraryRandom.RandDecInRange(100, 200, 2)); // Blank - WHT Bus Posting Group, Applies To Doc. No, Currency, Random - Direct unit cost. UpdateGenJournalLineWHTAbsorbBase(GenJournalLine); - GenJournalLine.TestField("Wthldg. Tax Bus. Post. Group", WHTBusPostingGroup.Code); - GenJournalLine.TestField("Wthldg. Tax Prod. Post. Group", WHTProdPostingGroup.Code); + FindWHTPostingSetup(WHTPostingSetup, GenJournalLine."Wthldg. Tax Bus. Post. Group", GenJournalLine."Wthldg. Tax Prod. Post. Group", ''); // Blank Currency Code. + WHTAmount := GenJournalLine."Withholding Tax Absorb Base" * WHTPostingSetup."Withholding Tax %" / 100; LibraryERM.PostGeneralJnlLine(GenJournalLine); DocumentNo := FindVendorLedgerEntry(GenJournalLine."Account No."); - - // [GIVEN] A dedicated Payments Gen. Journal Template (ensures more than one Payments template exists so the template lookup always opens deterministically across localizations), a Batch and a Bank Account for the Create Payment action. - LibraryERM.CreateGenJournalTemplate(GenJournalTemplate); - GenJournalTemplate.Validate(Type, GenJournalTemplate.Type::Payments); - GenJournalTemplate.Modify(true); - LibraryERM.CreateGenJournalBatch(GenJournalBatch, GenJournalTemplate.Name); LibraryERM.CreateBankAccount(BankAccount); - StartingDocumentNo := LibraryUtility.GenerateGUID(); - - LibraryVariableStorage.Enqueue(GenJournalTemplate.Name); - LibraryVariableStorage.Enqueue(GenJournalTemplate.Name); - LibraryVariableStorage.Enqueue(GenJournalBatch.Name); - LibraryVariableStorage.Enqueue(StartingDocumentNo); - LibraryVariableStorage.Enqueue(BankAccount."No."); - - // [WHEN] The user filters the Vendor Ledger Entries page to the posted Invoice and invokes the Create Payment action. - VendorLedgerEntries.OpenView(); - VendorLedgerEntries.Filter.SetFilter("Document No.", DocumentNo); - PaymentJournal.Trap(); - VendorLedgerEntries."Create Payment".Invoke(); - PaymentJournal.OK().Invoke(); - VendorLedgerEntries.Close(); - - // [THEN] The WHT Prod. Post. Group on the generated Payment line is copied from the applied Invoice. - GenJournalLine2.SetRange("Journal Template Name", GenJournalTemplate.Name); - GenJournalLine2.SetRange("Journal Batch Name", GenJournalBatch.Name); - GenJournalLine2.SetRange("Document No.", StartingDocumentNo); - GenJournalLine2.FindFirst(); + + // [WHEN] A Payment is created for the Vendor and applied to the Invoice (without manually setting the WHT Prod. Post. Group). + CreateGeneralJournalLineWithBalAccountType( + GenJournalLine2, GenJournalLine."Document Type"::Payment, GenJournalLine."Account No.", DocumentNo, + '', GenJournalLine2."Bal. Account Type"::"Bank Account", BankAccount."No.", -FindVendorLedgerEntryAmount(DocumentNo)); // Currency - Blank. + + // [THEN] The WHT Prod. Post. Group is copied from the Invoice to the Payment line. GenJournalLine2.TestField("Wthldg. Tax Prod. Post. Group", WHTProdPostingGroup.Code); + + // [WHEN] The Payment is posted. + LibraryERM.PostGeneralJnlLine(GenJournalLine2); + + // [THEN] Withholding Tax Entries are realized for the Payment and the unrealized amount on the Invoice is cleared. + VerifyWHTEntry(WHTEntry."Document Type"::Payment, GenJournalLine."Account No.", -WHTAmount, 0); // Unrealized Amount - 0. + VerifyWHTEntry(WHTEntry."Document Type"::Invoice, GenJournalLine."Account No.", 0, -WHTAmount); // Amount - 0. end; local procedure Initialize() @@ -1190,23 +1167,4 @@ codeunit 148322 "ERM Withholding Tax Tests II" begin Reply := true; end; - - [ModalPageHandler] - [Scope('OnPrem')] - procedure GeneralJournalTemplateListPageHandler(var GeneralJournalTemplateList: TestPage "General Journal Template List") - begin - GeneralJournalTemplateList.Filter.SetFilter(Name, LibraryVariableStorage.DequeueText()); - GeneralJournalTemplateList.OK().Invoke(); - end; - - [ModalPageHandler] - [Scope('OnPrem')] - procedure CreatePaymentPageHandler(var CreatePayment: TestPage "Create Payment") - begin - CreatePayment."Template Name".SetValue(LibraryVariableStorage.DequeueText()); - CreatePayment."Batch Name".SetValue(LibraryVariableStorage.DequeueText()); - CreatePayment."Starting Document No.".SetValue(LibraryVariableStorage.DequeueText()); - CreatePayment."Bank Account".SetValue(LibraryVariableStorage.DequeueText()); - CreatePayment.OK().Invoke(); - end; } \ No newline at end of file From 835d97f960573210802a1448af4a65b1c9b5185e Mon Sep 17 00:00:00 2001 From: v-nesinghal Date: Wed, 15 Jul 2026 16:55:00 +0545 Subject: [PATCH 6/7] fixes --- .../src/ERMWithholdingTaxTestsII.Codeunit.al | 60 ++++++++++--------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al index 846567fbcf..429faecf0b 100644 --- a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al +++ b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al @@ -42,6 +42,7 @@ codeunit 148322 "ERM Withholding Tax Tests II" ValueMustBeSameMsg: Label 'Value must be same.'; WHTAccountCodeEmptyErr: Label '%1 must have a value in Withholding Tax Posting Setup: Withholding Tax Bus. Post. Group=%2, Withholding Tax Prod. Post. Group=%3. It cannot be zero or empty.', Comment = '%1 = Field Caption, %2 = WHT Business Posting Group Code, %3 = WHT Product Posting Group Code'; + WHTProdPostGroupNotCopiedErr: Label 'Withholding Tax Prod. Post. Group must be copied from the applied Invoice to the Payment line.'; IsInitialized: Boolean; [Test] @@ -598,52 +599,43 @@ codeunit 148322 "ERM Withholding Tax Tests II" [Test] [Scope('OnPrem')] [HandlerFunctions('ConfirmHandler')] - procedure WHTProdPostGroupTravelsFromInvoiceToPaymentOnApplication() + procedure WHTProdPostGroupTravelsFromJournalLine() var - GenJournalLine: Record "Gen. Journal Line"; - GenJournalLine2: Record "Gen. Journal Line"; + GenJournalLine: array[2] of Record "Gen. Journal Line"; VATPostingSetup: Record "VAT Posting Setup"; - WHTEntry: Record "Withholding Tax Entry"; WHTBusPostingGroup: Record "Wthldg. Tax Bus. Post. Group"; WHTPostingSetup: Record "Withholding Tax Posting Setup"; WHTProdPostingGroup: Record "Wthldg. Tax Prod. Post. Group"; - BankAccount: Record "Bank Account"; + VendorLedgerEntry: Record "Vendor Ledger Entry"; DocumentNo: Code[20]; - WHTAmount: Decimal; begin // [SCENARIO 639524] Withholding Tax Prod. Post. Group travels from the applied invoice to the payment line and Withholding Tax Entries are generated at payment. + Initialize(); // [GIVEN] WHT Posting Setup realized on Payment and a posted Invoice for a WHT liable Vendor. - Initialize(); UpdateLocalFunctionalitiesOnGeneralLedgerSetup(true); + + // [GIVEN] Create a WHT Posting Setup for a WHT liable Vendor and a posted Invoice for that Vendor. LibraryERM.FindVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Calculation Type"::"Normal VAT"); LibraryWithholdingTax.CreateWHTBusinessPostingGroup(WHTBusPostingGroup); LibraryWithholdingTax.CreateWHTProductPostingGroup(WHTProdPostingGroup); - CreateGeneralJournalLineWithBalAccountType( - GenJournalLine, GenJournalLine."Document Type"::Invoice, CreateVendor(VATPostingSetup."VAT Bus. Posting Group", WHTBusPostingGroup.Code), '', - '', GenJournalLine."Bal. Account Type"::"G/L Account", CreateGLAccountWithVATBusPostingGroup(VATPostingSetup, WHTProdPostingGroup.Code), - -LibraryRandom.RandDecInRange(100, 200, 2)); // Blank - WHT Bus Posting Group, Applies To Doc. No, Currency, Random - Direct unit cost. - UpdateGenJournalLineWHTAbsorbBase(GenJournalLine); - FindWHTPostingSetup(WHTPostingSetup, GenJournalLine."Wthldg. Tax Bus. Post. Group", GenJournalLine."Wthldg. Tax Prod. Post. Group", ''); // Blank Currency Code. - WHTAmount := GenJournalLine."Withholding Tax Absorb Base" * WHTPostingSetup."Withholding Tax %" / 100; - LibraryERM.PostGeneralJnlLine(GenJournalLine); - DocumentNo := FindVendorLedgerEntry(GenJournalLine."Account No."); - LibraryERM.CreateBankAccount(BankAccount); - // [WHEN] A Payment is created for the Vendor and applied to the Invoice (without manually setting the WHT Prod. Post. Group). + // [GIVEN] Create a posted Invoice for a WHT liable Vendor with a WHT Prod. Post. Group. CreateGeneralJournalLineWithBalAccountType( - GenJournalLine2, GenJournalLine."Document Type"::Payment, GenJournalLine."Account No.", DocumentNo, - '', GenJournalLine2."Bal. Account Type"::"Bank Account", BankAccount."No.", -FindVendorLedgerEntryAmount(DocumentNo)); // Currency - Blank. + GenJournalLine[1], GenJournalLine[1]."Document Type"::Invoice, CreateVendor(VATPostingSetup."VAT Bus. Posting Group", WHTBusPostingGroup.Code), '', + '', GenJournalLine[1]."Bal. Account Type"::"G/L Account", CreateGLAccountWithVATBusPostingGroup(VATPostingSetup, WHTProdPostingGroup.Code), + -LibraryRandom.RandDecInRange(100, 200, 2)); - // [THEN] The WHT Prod. Post. Group is copied from the Invoice to the Payment line. - GenJournalLine2.TestField("Wthldg. Tax Prod. Post. Group", WHTProdPostingGroup.Code); + // [GIVEN] WHT Posting Setup realized on Payment and a posted Invoice for a WHT liable Vendor. + UpdateGenJournalLineWHTAbsorbBase(GenJournalLine[1]); + FindWHTPostingSetup(WHTPostingSetup, GenJournalLine[1]."Wthldg. Tax Bus. Post. Group", GenJournalLine[1]."Wthldg. Tax Prod. Post. Group", ''); - // [WHEN] The Payment is posted. - LibraryERM.PostGeneralJnlLine(GenJournalLine2); + LibraryERM.PostGeneralJnlLine(GenJournalLine[1]); + DocumentNo := FindVendorLedgerEntry(GenJournalLine[1]."Account No."); + LibraryERM.FindVendorLedgerEntry(VendorLedgerEntry, VendorLedgerEntry."Document Type"::Invoice, DocumentNo); - // [THEN] Withholding Tax Entries are realized for the Payment and the unrealized amount on the Invoice is cleared. - VerifyWHTEntry(WHTEntry."Document Type"::Payment, GenJournalLine."Account No.", -WHTAmount, 0); // Unrealized Amount - 0. - VerifyWHTEntry(WHTEntry."Document Type"::Invoice, GenJournalLine."Account No.", 0, -WHTAmount); // Amount - 0. + // [THEN] The WHT Prod. Post. Group is copied from the Invoice to the Payment line. + Assert.AreEqual(GetWHTProdPostGroupFromInvoiceEntry(VendorLedgerEntry), WHTPostingSetup."Wthldg. Tax Prod. Post. Group", WHTProdPostGroupNotCopiedErr); end; local procedure Initialize() @@ -1030,6 +1022,20 @@ codeunit 148322 "ERM Withholding Tax Tests II" exit(VendorLedgerEntry.Amount); end; + local procedure GetWHTProdPostGroupFromInvoiceEntry(VendorLedgerEntry: Record "Vendor Ledger Entry"): Code[20] + var + WithholdingTaxEntry: Record "Withholding Tax Entry"; + begin + WithholdingTaxEntry.SetLoadFields("Wthldg. Tax Prod. Post. Group"); + WithholdingTaxEntry.SetRange("Document No.", VendorLedgerEntry."Document No."); + WithholdingTaxEntry.SetRange("Transaction Type", WithholdingTaxEntry."Transaction Type"::Purchase); + WithholdingTaxEntry.SetRange("Document Type", WithholdingTaxEntry."Document Type"::Invoice); + WithholdingTaxEntry.SetRange("Bill-to/Pay-to No.", VendorLedgerEntry."Vendor No."); + if not WithholdingTaxEntry.FindFirst() then + exit(''); + exit(WithholdingTaxEntry."Wthldg. Tax Prod. Post. Group"); + end; + local procedure PostPurchaseDocument(DocumentType: Enum "Purchase Document Type"; DocumentNo: Code[20]): Code[20] var PurchaseHeader: Record "Purchase Header"; From 6bae51a373d586e9abf9c7e38b73c10a25794b81 Mon Sep 17 00:00:00 2001 From: v-nesinghal Date: Thu, 16 Jul 2026 14:01:23 +0545 Subject: [PATCH 7/7] re fix --- .../src/ERMWithholdingTaxTestsII.Codeunit.al | 53 +++++++------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al index 429faecf0b..f3c5a0edec 100644 --- a/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al +++ b/src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsII.Codeunit.al @@ -599,43 +599,42 @@ codeunit 148322 "ERM Withholding Tax Tests II" [Test] [Scope('OnPrem')] [HandlerFunctions('ConfirmHandler')] - procedure WHTProdPostGroupTravelsFromJournalLine() + procedure WithholdingTaxProductPostingGroupIsCopiedToWithholdingTaxEntry() var - GenJournalLine: array[2] of Record "Gen. Journal Line"; + GenJournalLine: Record "Gen. Journal Line"; VATPostingSetup: Record "VAT Posting Setup"; WHTBusPostingGroup: Record "Wthldg. Tax Bus. Post. Group"; WHTPostingSetup: Record "Withholding Tax Posting Setup"; WHTProdPostingGroup: Record "Wthldg. Tax Prod. Post. Group"; - VendorLedgerEntry: Record "Vendor Ledger Entry"; - DocumentNo: Code[20]; + WHTEntry: Record "Withholding Tax Entry"; begin - // [SCENARIO 639524] Withholding Tax Prod. Post. Group travels from the applied invoice to the payment line and Withholding Tax Entries are generated at payment. + // [SCENARIO 639524] Withholding Tax Product Posting Group is transferred from the General Journal Line to the Withholding Tax Entry created when the Invoice is posted. Initialize(); - // [GIVEN] WHT Posting Setup realized on Payment and a posted Invoice for a WHT liable Vendor. + // [GIVEN] Local functionalities enabled, VAT Posting Setup, Withholding Tax Business Posting Group and Withholding Tax Product Posting Group. UpdateLocalFunctionalitiesOnGeneralLedgerSetup(true); - - // [GIVEN] Create a WHT Posting Setup for a WHT liable Vendor and a posted Invoice for that Vendor. LibraryERM.FindVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Calculation Type"::"Normal VAT"); LibraryWithholdingTax.CreateWHTBusinessPostingGroup(WHTBusPostingGroup); LibraryWithholdingTax.CreateWHTProductPostingGroup(WHTProdPostingGroup); - // [GIVEN] Create a posted Invoice for a WHT liable Vendor with a WHT Prod. Post. Group. + // [GIVEN] A General Journal Line for a Withholding Tax liable Vendor. CreateGeneralJournalLineWithBalAccountType( - GenJournalLine[1], GenJournalLine[1]."Document Type"::Invoice, CreateVendor(VATPostingSetup."VAT Bus. Posting Group", WHTBusPostingGroup.Code), '', - '', GenJournalLine[1]."Bal. Account Type"::"G/L Account", CreateGLAccountWithVATBusPostingGroup(VATPostingSetup, WHTProdPostingGroup.Code), - -LibraryRandom.RandDecInRange(100, 200, 2)); + GenJournalLine, GenJournalLine."Document Type"::Invoice, CreateVendor(VATPostingSetup."VAT Bus. Posting Group", WHTBusPostingGroup.Code), '', + '', GenJournalLine."Bal. Account Type"::"G/L Account", CreateGLAccountWithVATBusPostingGroup(VATPostingSetup, WHTProdPostingGroup.Code), + -LibraryRandom.RandDecInRange(100, 200, 2)); - // [GIVEN] WHT Posting Setup realized on Payment and a posted Invoice for a WHT liable Vendor. - UpdateGenJournalLineWHTAbsorbBase(GenJournalLine[1]); - FindWHTPostingSetup(WHTPostingSetup, GenJournalLine[1]."Wthldg. Tax Bus. Post. Group", GenJournalLine[1]."Wthldg. Tax Prod. Post. Group", ''); + // [GIVEN] The Withholding Tax Absorb Base is updated and the Withholding Tax Posting Setup is found for the General Journal Line. + UpdateGenJournalLineWHTAbsorbBase(GenJournalLine); + FindWHTPostingSetup(WHTPostingSetup, GenJournalLine."Wthldg. Tax Bus. Post. Group", GenJournalLine."Wthldg. Tax Prod. Post. Group", ''); - LibraryERM.PostGeneralJnlLine(GenJournalLine[1]); - DocumentNo := FindVendorLedgerEntry(GenJournalLine[1]."Account No."); - LibraryERM.FindVendorLedgerEntry(VendorLedgerEntry, VendorLedgerEntry."Document Type"::Invoice, DocumentNo); + // [WHEN] The Invoice is posted. + LibraryERM.PostGeneralJnlLine(GenJournalLine); - // [THEN] The WHT Prod. Post. Group is copied from the Invoice to the Payment line. - Assert.AreEqual(GetWHTProdPostGroupFromInvoiceEntry(VendorLedgerEntry), WHTPostingSetup."Wthldg. Tax Prod. Post. Group", WHTProdPostGroupNotCopiedErr); + // [THEN] The Withholding Tax Entry has the same Withholding Tax Product Posting Group as the source General Journal Line. + WHTEntry.SetRange("Document Type", WHTEntry."Document Type"::Invoice); + WHTEntry.SetRange("Bill-to/Pay-to No.", GenJournalLine."Account No."); + WHTEntry.FindFirst(); + Assert.AreEqual(WHTProdPostingGroup.Code, WHTEntry."Wthldg. Tax Prod. Post. Group", WHTProdPostGroupNotCopiedErr); end; local procedure Initialize() @@ -1022,20 +1021,6 @@ codeunit 148322 "ERM Withholding Tax Tests II" exit(VendorLedgerEntry.Amount); end; - local procedure GetWHTProdPostGroupFromInvoiceEntry(VendorLedgerEntry: Record "Vendor Ledger Entry"): Code[20] - var - WithholdingTaxEntry: Record "Withholding Tax Entry"; - begin - WithholdingTaxEntry.SetLoadFields("Wthldg. Tax Prod. Post. Group"); - WithholdingTaxEntry.SetRange("Document No.", VendorLedgerEntry."Document No."); - WithholdingTaxEntry.SetRange("Transaction Type", WithholdingTaxEntry."Transaction Type"::Purchase); - WithholdingTaxEntry.SetRange("Document Type", WithholdingTaxEntry."Document Type"::Invoice); - WithholdingTaxEntry.SetRange("Bill-to/Pay-to No.", VendorLedgerEntry."Vendor No."); - if not WithholdingTaxEntry.FindFirst() then - exit(''); - exit(WithholdingTaxEntry."Wthldg. Tax Prod. Post. Group"); - end; - local procedure PostPurchaseDocument(DocumentType: Enum "Purchase Document Type"; DocumentNo: Code[20]): Code[20] var PurchaseHeader: Record "Purchase Header";