BCApps icon indicating copy to clipboard operation
BCApps copied to clipboard

[Bug]: Service Line CalcVATAmountLines double-counts VAT Difference and leaks filters onto OnAfterCalcVATAmountLines

Open Franco111000 opened this issue 4 months ago • 4 comments

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:

  1. 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.

  1. The filters set by FindVATAmountLine in the invoice-rounding block are never reset, so OnAfterCalcVATAmountLines fires with a filtered VATAmountLine, 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

  1. Enable invoice rounding (Sales & Receivables Setup) and Allow VAT Difference with a Max. VAT Difference Allowed.
  2. Create a Service Invoice whose amounts require an invoice rounding line.
  3. Open Service Statistics and manually change the VAT amount (creating a VAT Difference) on a VAT line.
  4. 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

  • [x] I will provide a fix for a bug

Franco111000 avatar Jul 05 '26 12:07 Franco111000

:robot: AI triage completed. Product group, please validate the triage report (Microsoft internal access only, use Ctrl+Click to open in new tab).


Was this triage helpful? React with :thumbsup: or :thumbsdown: on this comment to provide feedback.

github-actions[bot] avatar Jul 05 '26 12:07 github-actions[bot]

Gentle follow-up on triage here. This was filed on 5 July as a re-submission of a fix that had already received a code-owner approval in the retired pilot repository, and it still carries no Approved label.

The fix is ready on my side. It covers both the W1 and NA copies of table 5902, so the localization runs behind the earlier internal test failures are addressed, and the tests are re-keyed on VAT Identifier. Since a pull request needs an approved linked issue, I am holding it until this one is triaged. Is there anything else needed from me to help it along?

Franco111000 avatar Jul 26 '26 08:07 Franco111000

Hi @AndersLarsenMicrosoft! A gentle follow-up on this one, since you routed it to SCM back in July and it has been quiet since.

This was filed on 2026-07-05 as a re-submission of a fix that had already been reviewed in the BusinessCentralApps repository (issues #1562 and #1563, PR #1913) before that repository was retired and its notice asked contributors to re-file here. Five weeks on it still carries only the SCM label, so it is waiting on a triage decision rather than on any work.

For context, the other three re-submissions from the same batch took different routes: #9099 and #9101 were approved on 2026-07-07 and are now open pull requests (#9180, which has since been reviewed and approved, and #9181), while #9100 is sitting in exactly the same state as this one.

Worth adding, since it may be why the original stalled: the pilot version of this fix was reported as failing internal tests, and while re-doing the work I found the likely cause. The NA layer carries its own copy of the table, so a W1-only change leaves the two out of step. The current fix patches that copy as well, and the test lookup is re-keyed on VAT Identifier rather than on line ordering, which is what made the original fragile.

I am not trying to rush anyone, I would just like to know whether this is still in the queue or whether it was set aside for a reason. Happy to provide more detail if that helps it get decided.

Franco111000 avatar Aug 09 '26 10:08 Franco111000

Let's move on it needs to be fixed - approved

AndersLarsenMicrosoft avatar Sep 03 '26 16:09 AndersLarsenMicrosoft