[Bug]: Service Line CalcVATAmountLines double-counts VAT Difference and leaks filters onto OnAfterCalcVATAmountLines
Nobody has claimed this yet.
- Dominant language
- AL
- Stars
- 683
- Forks
- 459
- Avg merge
- 3d 26m
- Merged PRs (30d)
- 633
Description
Describe the issue
CalcVATAmountLines in table 5902 "Service Line" diverges from the Sales Line / Purchase Line implementation, causing two defects visible on Service Statistics when invoice rounding and VAT difference are both enabled:
- VAT Difference is double-counted when accumulating the rounding residual:
TotalVATAmount += ServiceLine."Amount Including VAT" - ServiceLine.Amount + ServiceLine."VAT Difference";
Sales Line accumulates SalesLine."Amount Including VAT" - SalesLine.Amount only. Since Amount Including VAT - Amount already contains the VAT Difference, the Service version adds it twice, and the excess is dumped onto the 0% invoice-rounding VAT line, so the VAT specification shows an incorrect VAT amount on the rounding line.
- The filters set by
FindVATAmountLinein the invoice-rounding block are never reset, soOnAfterCalcVATAmountLinesfires with a filteredVATAmountLine, and the VAT Specification subform on page 6030 "Service Statistics" can show a single VAT line instead of all lines. Sales Line clears these filters before the event.
Verified still present in current main in BOTH src/Layers/W1/BaseApp/Service/Document/ServiceLine.Table.al and the NA layer's full table copy src/Layers/NA/BaseApp/Service/Document/ServiceLine.Table.al (the only country layer that overrides table 5902).
Expected behavior
Service document VAT statistics match the Sales/Purchase behavior: no double-counted VAT Difference on the invoice-rounding VAT line, and all VAT specification lines visible after recalculation.
Steps to reproduce
- Enable invoice rounding (Sales & Receivables Setup) and Allow VAT Difference with a Max. VAT Difference Allowed.
- Create a Service Invoice whose amounts require an invoice rounding line.
- Open Service Statistics and manually change the VAT amount (creating a VAT Difference) on a VAT line.
- The rounding VAT line receives the VAT Difference amount again (incorrect VAT amount), and the VAT specification can collapse to a single line.
Additional context
This is a copy of microsoft/BusinessCentralApps#1562 and microsoft/BusinessCentralApps#1563 (both labeled Approved/Finance in the contribution pilot). Both were being fixed together in microsoft/BusinessCentralApps#1913, which received a code-owner approval, but the internal merge attempt reported test failures and the PR was closed unmerged when the repository was retired. The likely cause of those failures has been identified: the fix patched the W1 layer only, while the NA layer's full copy of table 5902 kept the defects, so localization runs of the new W1 tests failed. The re-submitted fix will cover both layers.
I will provide a fix for a bug
- I will provide a fix for a bug
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Compare CalcVATAmountLines in src/Layers/W1/BaseApp/Service/Document/ServiceLine.Table.al with the NA copy at src/Layers/NA/BaseApp/Service/Document/ServiceLine.Table.al, then inspect the corresponding Sales Line implementation. Run the relevant W1 VAT tests and localization tests; done means Service Statistics matches Sales/Purchase behavior and all VAT specification lines remain visible after recalculation.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100