[Master] - 'Greater Than' Withholding Tax Calculation Rule is not applied correctly in Withholding Tax Posting Setup.#9515
Conversation
|
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. |
Copilot PR ReviewIteration 1 · Outcome: completed Knowledge source: https://github.com/microsoft/BCQuality@186d8a131465475c79244d994acb872cd5c0d4bf Orchestrator pre-filter (2 file(s) excluded)
Findings produced by the AL review agent v1.7.3. Reply 👎 on any inline comment to flag false positives. |
There was a problem hiding this comment.
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.
| procedure ShouldCreateWithholdingTax(InvoiceAmount: Decimal; WithholdingPostingSetup: Record "Withholding Tax Posting Setup"): Boolean | ||
| begin | ||
| exit(not CheckWithholdingCalculationRule(InvoiceAmount, WithholdingPostingSetup)); | ||
| end; |
| 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)); | ||
|
|
| 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; |
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.