Skip to content

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

Description

@Franco111000

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

  • I will provide a fix for a bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM area

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions