Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ codeunit 148322 "ERM Withholding Tax Tests II"
WHTProdPostGroupNotCopiedErr: Label 'Withholding Tax Prod. Post. Group must be copied from the applied Invoice to the Payment line.';
EmployeeOnlyOptionErr: Label 'The %1 option can be used only when the withholding tax is for employees.', Comment = '%1 = field caption';
ThresholdPeriodNotAllowedErr: Label 'The %1 can be specified only when %2 is %3 or %4.', Comment = '%1 = Withholding Threshold Period field caption, %2 = Withholding Threshold Base field caption, %3 = Category in Period option, %4 = Total in Period option';
GenJnlTemplateNotFoundErr: Label 'A general journal template with Type Purchases does not exist.';
IsInitialized: Boolean;

[Test]
Expand Down Expand Up @@ -764,6 +765,60 @@ codeunit 148322 "ERM Withholding Tax Tests II"
Assert.AreEqual(WHTPostingSetup."WHT Threshold Period"::Month, WHTPostingSetup."WHT Threshold Period", ValueMustBeSameMsg);
end;

[Test]
[Scope('OnPrem')]
[HandlerFunctions('ConfirmHandler')]
procedure PostingWHTPaymentWithoutPurchaseJournalTemplateErr()
var
BankAccount: Record "Bank Account";
GenJournalLine: Record "Gen. Journal Line";
GenJournalLine2: Record "Gen. Journal Line";
GLAccount: Record "G/L Account";
GenJournalTemplate: Record "Gen. Journal Template";
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";
DocumentNo: Code[20];
begin
// [FEATURE] [AI Test]
// [SCENARIO 647253] Posting a WHT payment without a purchase journal template results in an error.
Initialize();

// [GIVEN] A posted purchase invoice with withholding tax.
UpdateLocalFunctionalitiesOnGeneralLedgerSetup(true);
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));
UpdateGenJournalLineWHTAbsorbBase(GenJournalLine);
FindWHTPostingSetup(WHTPostingSetup, GenJournalLine."Wthldg. Tax Bus. Post. Group", GenJournalLine."Wthldg. Tax Prod. Post. Group", '');
LibraryERM.PostGeneralJnlLine(GenJournalLine);
DocumentNo := FindVendorLedgerEntry(GenJournalLine."Account No.");

// [GIVEN] A payment journal line applied to the posted invoice.
LibraryERM.CreateGLAccount(GLAccount);
LibraryERM.CreateBankAccount(BankAccount, GLAccount);
CreateGeneralJournalLineWithBalAccountType(
GenJournalLine2, GenJournalLine."Document Type"::Payment, GenJournalLine."Account No.", DocumentNo,
'', GenJournalLine2."Bal. Account Type"::"Bank Account", BankAccount."No.", -FindVendorLedgerEntryAmount(DocumentNo));
GenJournalLine2.Validate("Wthldg. Tax Prod. Post. Group", WHTPostingSetup."Wthldg. Tax Prod. Post. Group");
GenJournalLine2.Modify(true);

// [GIVEN] No general journal template of type Purchases exists.
GenJournalTemplate.SetRange(Type, GenJournalTemplate.Type::Purchases);
GenJournalTemplate.DeleteAll(true);

// [WHEN] Post the payment journal.
asserterror LibraryERM.PostGeneralJnlLine(GenJournalLine2);

// [THEN] The missing purchase journal template error is raised.
Assert.ExpectedError(GenJnlTemplateNotFoundErr);
end;

local procedure Initialize()
var
VATPostingSetup: Record "VAT Posting Setup";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ codeunit 6785 "Withholding Tax Mgmt."
WithholdingMinInvNotConsistentErr: Label 'You cannot post a transaction using different Withholding Tax minimum invoice amounts on lines.';
DiffWithholdingPostGroupsErr: Label 'The Withholding Tax posting groups are different and thus the entries cannot be apply.';
MissingRevenueTypeErr: Label 'The Withholding Tax Entry you are trying to process contains WHT Revenue Type `%1`. Please add this value to your Withholding Revenue Types and post again.', Comment = '%1 = Withholding Revenue Type';
GenJnlTemplateNotFoundErr: Label 'A general journal template with Type Purchases does not exist.';
Comment thread
ViditGupta1277 marked this conversation as resolved.
MustbeNegativeLbl: Label 'must be positive.';
OneLbl: Label 'ONE';
TwoLbl: Label 'TWO';
Expand Down Expand Up @@ -4240,10 +4241,12 @@ codeunit 6785 "Withholding Tax Mgmt."
if Source = Source::Vendor then
GenJnlTemplate.SetRange(Type, GenJnlTemplate.Type::Purchases);

if GenJnlTemplate.FindFirst() then
if GenJnlTemplate.FindFirst() then begin
Comment thread
ViditGupta1277 marked this conversation as resolved.
Comment thread
ViditGupta1277 marked this conversation as resolved.

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\ —\ Agent}$

GenJnlTemplate.SetRange(Type, GenJnlTemplate.Type::Purchases) is only executed when Source = Source::Vendor; for any other Source value the SetRange is never applied, so the subsequent GenJnlTemplate.FindFirst() runs unfiltered against the whole Gen. Journal Template table. In that code path, the new else Error(GenJnlTemplateNotFoundErr) message 'A general journal template with Type Purchases does not exist.' is misleading: the check never actually verified a Purchases-type template exists, only that some template exists. Either apply an equivalent type-specific filter for the non-Vendor source before the FindFirst() check, or use a message that accurately reflects the unfiltered check performed in that branch.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.41.6

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\ —\ Breaking\ Changes}$

The public procedure that posts withholding-tax payments now raises an unconditional Error when no Purchases-type Gen. Journal Template exists. Before this change, that path was a silent no-op, so existing extensions and normal WHT payment posting flows could succeed without that template. After upgrade, the same calls will start failing at runtime for existing customers/partners with that setup. Preserve the previous behavior for the existing call path, or move the new validation behind a separate compatibility-safe path instead of changing this existing contract in place.

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

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.41.6

if GenJnlLine."Journal Template Name" <> GenJnlTemplate.Name then
if WithholdingTaxEntry2.Amount <> 0 then
InsertWithholdingTaxPostingBuffer(WithholdingTaxEntry2, GenJnlLine, 0, AmountWithDisc);
end else
Comment thread
ViditGupta1277 marked this conversation as resolved.
Error(GenJnlTemplateNotFoundErr);
Comment thread
ViditGupta1277 marked this conversation as resolved.
Comment thread
ViditGupta1277 marked this conversation as resolved.
Comment thread
ViditGupta1277 marked this conversation as resolved.
end;
until (WithholdingTaxEntry.Next() = 0);

Expand Down
Loading