Skip to content

[Master] - 'Greater Than' Withholding Tax Calculation Rule is not applied correctly in Withholding Tax Posting Setup.#9515

Open
DhavalMore88 wants to merge 1 commit into
microsoft:mainfrom
DhavalMore88:bugs/Bug-642326-Main-Greater-Than-Withholding-Tax-Calculation
Open

[Master] - 'Greater Than' Withholding Tax Calculation Rule is not applied correctly in Withholding Tax Posting Setup.#9515
DhavalMore88 wants to merge 1 commit into
microsoft:mainfrom
DhavalMore88:bugs/Bug-642326-Main-Greater-Than-Withholding-Tax-Calculation

Conversation

@DhavalMore88

@DhavalMore88 DhavalMore88 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Bug 642326: [master] [All-e]'Greater Than' Withholding Tax Calculation Rule is not applied correctly in Withholding Tax Posting Setup.

AB#642326

Issue: When a Withholding Tax Posting Setup uses a "Wthldg. Tax Calculation Rule" other than "Less than" (e.g. "Greater than", "Greater than or equal to", "Equal to"), the withholding tax was calculated/zeroed incorrectly against the "Wthldg. Tax Min. Inv. Amount". WHT was created (or suppressed) based on the wrong comparison, so amounts that should have been excluded got taxed and vice-versa.

Cause: Multiple threshold checks across Withholding Tax Jnl Subscriber, Withholding Tax Mgmt., and Wthldg Tax Purch. Subscribers hard-coded the comparison as Abs(Amount) < WithholdingPostingSetup."Wthldg. Tax Min. Inv. Amount". This assumed a "Less than" rule and completely ignored the configured "Wthldg. Tax Calculation Rule" enum, so the other rule options (Greater than, etc.) were never honored.

Solution: Added a reusable ShouldCreateWithholdingTax(Amount, WithholdingPostingSetup) procedure in Withholding Tax Mgmt. that returns not CheckWithholdingCalculationRule(...), so the decision respects the actual configured "Wthldg. Tax Calculation Rule" (Less than / ≤ / Equal / Greater than / ≥). Replaced all hard-coded Abs(Amount) < Min Inv. Amount checks in the three transaction codeunits with this rule-aware call, ensuring consistent, correct WHT creation and zeroing for every calculation rule.

@github-actions github-actions Bot added AL: Apps (W1) Add-on apps for W1 From Fork Pull request is coming from a fork labels Jul 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Could not find linked issues in the pull request description. Please make sure the pull request description contains a line that contains 'Fixes #' followed by the issue number being fixed. Use that pattern for every issue you want to link.

@DhavalMore88 DhavalMore88 marked this pull request as ready for review July 15, 2026 14:40
@DhavalMore88 DhavalMore88 requested a review from a team July 15, 2026 14:40
@github-actions github-actions Bot added the Linked Issue is linked to a Azure Boards work item label Jul 15, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Jul 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Copilot PR Review

Iteration 1 · Outcome: completed

Knowledge source: https://github.com/microsoft/BCQuality@186d8a131465475c79244d994acb872cd5c0d4bf

Orchestrator pre-filter (2 file(s) excluded)

  • layer-disabled (knowledge) : 2 file(s)

Findings produced by the AL review agent v1.7.3. Reply 👎 on any inline comment to flag false positives.

@DhavalMore88 DhavalMore88 added the Finance GitHub request for Finance area label Jul 16, 2026

Copilot AI left a comment

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.

Pull request overview

This PR fixes withholding tax (WHT) creation/zeroing logic so it correctly respects the configured Wthldg. Tax Calculation Rule (Less than / ≤ / = / > / ≥) when comparing against Wthldg. Tax Min. Inv. Amount, and adds regression tests for the “Greater than” rule behavior on purchase invoices.

Changes:

  • Added ShouldCreateWithholdingTax(...) in Withholding Tax Mgmt. to centralize the rule-aware decision.
  • Replaced hard-coded minimum-invoice threshold comparisons in purchase/journal subscribers with the new rule-aware helper.
  • Added new OnPrem tests to validate WHT entry creation/suppression for the “Greater than” calculation rule.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Apps/W1/WithholdingTax/app/src/Purchase/Transaction/WithholdingTaxMgmt.Codeunit.al Adds ShouldCreateWithholdingTax and uses it where minimum-invoice threshold logic previously hard-coded comparisons.
src/Apps/W1/WithholdingTax/app/src/Purchase/Transaction/WithholdingTaxJnlSubscriber.Codeunit.al Updates journal logic to use the centralized rule-aware decision instead of direct amount/min comparisons.
src/Apps/W1/WithholdingTax/app/src/Purchase/Transaction/WthldgTaxPurchSubscribers.Codeunit.al Updates purchase posting logic to use ShouldCreateWithholdingTax before inserting invoice WHT.
src/Apps/W1/WithholdingTax/Test/src/ERMWithholdingTaxTestsI.Codeunit.al Adds new regression tests and supporting helpers for “Greater than” rule scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +612 to +615
procedure ShouldCreateWithholdingTax(InvoiceAmount: Decimal; WithholdingPostingSetup: Record "Withholding Tax Posting Setup"): Boolean
begin
exit(not CheckWithholdingCalculationRule(InvoiceAmount, WithholdingPostingSetup));
end;
Comment on lines 670 to 680
local procedure IsAboveWithholdingMinInvAmount(GenJnlLine: Record "Gen. Journal Line"): Boolean
var
WithholdingPostingSetup: Record "Withholding Tax Posting Setup";
WithholdingTaxMgmt: Codeunit "Withholding Tax Mgmt.";
begin
if not (GenJnlLine."Document Type" in [GenJnlLine."Document Type"::Invoice, GenJnlLine."Document Type"::"Credit Memo"]) then
exit(true);

if WithholdingPostingSetup.Get(GenJnlLine."Wthldg. Tax Bus. Post. Group", GenJnlLine."Wthldg. Tax Prod. Post. Group") then
exit(Abs(GenJnlLine.Amount) >= WithholdingPostingSetup."Wthldg. Tax Min. Inv. Amount");
exit(WithholdingTaxMgmt.ShouldCreateWithholdingTax(GenJnlLine.Amount, WithholdingPostingSetup));

Comment on lines +2804 to +2818
local procedure VerifyWHTEntryExists(DocumentNo: Code[20])
var
WHTEntry: Record "Withholding Tax Entry";
begin
WHTEntry.SetRange("Document No.", DocumentNo);
Assert.RecordIsNotEmpty(WHTEntry);
end;

local procedure VerifyWHTEntryDoesNotExist(DocumentNo: Code[20])
var
WHTEntry: Record "Withholding Tax Entry";
begin
WHTEntry.SetRange("Document No.", DocumentNo);
Assert.RecordIsEmpty(WHTEntry);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1 Finance GitHub request for Finance area From Fork Pull request is coming from a fork Linked Issue is linked to a Azure Boards work item

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants