Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -595,6 +596,47 @@ codeunit 148322 "ERM Withholding Tax Tests II"
VerifyPostingNoSeriesOnePostedDoc('B0', 6, 2);
end;

[Test]
[Scope('OnPrem')]
[HandlerFunctions('ConfirmHandler')]
procedure WithholdingTaxProductPostingGroupIsCopiedToWithholdingTaxEntry()
var
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";
WHTEntry: Record "Withholding Tax Entry";
begin
// [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] Local functionalities enabled, VAT Posting Setup, Withholding Tax Business Posting Group and Withholding Tax Product Posting Group.
UpdateLocalFunctionalitiesOnGeneralLedgerSetup(true);
LibraryERM.FindVATPostingSetup(VATPostingSetup, VATPostingSetup."VAT Calculation Type"::"Normal VAT");
LibraryWithholdingTax.CreateWHTBusinessPostingGroup(WHTBusPostingGroup);
LibraryWithholdingTax.CreateWHTProductPostingGroup(WHTProdPostingGroup);

// [GIVEN] A General Journal Line for a Withholding Tax liable Vendor.
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));

// [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", '');

// [WHEN] The Invoice is posted.
LibraryERM.PostGeneralJnlLine(GenJournalLine);

// [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()
var
VATPostingSetup: Record "VAT Posting Setup";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Testing} \quad \color{gray}{\texttt{\small Iteration\ 2}}$

The new event subscriber AssignWHTPostingGroupOnCreatePayment (WithholdingTaxJnlSubscriber.Codeunit.al) copies 'Wthldg.

Tax Prod. Post. Group' from the Withholding Tax Entry onto the Gen. Journal Line when a payment is created via the 'Create Payment' page. This is new production logic that changes financial posting data. The single test added in this PR (WithholdingTaxProductPostingGroupIsCopiedToWithholdingTaxEntry) only exercises direct invoice posting and asserts that the group is copied onto the Withholding Tax Entry - a pre-existing code path unrelated to the new subscriber. None of the existing 'Create Payment' related tests invoke the page's OnBeforeUpdateGnlJnlLineDimensionsFromVendorPayment event (they post payments directly through Gen. Journal Line, bypassing the page). As a result, the new subscriber's behavior - including its guard clauses (Applies-to ID blank, Vendor Ledg. Entry No. = 0, no matching Withholding Tax Entry) and the successful copy path - has no test coverage. Recommend adding a test that drives the 'Create Payment' page (or otherwise raises OnBeforeUpdateGnlJnlLineDimensionsFromVendorPayment) to verify the Gen. Journal Line's WHT Product Posting Group is populated correctly before posting.

Agent judgement — not directly backed by a BCQuality knowledge article.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

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";
Expand Down
Loading