[Main]- When issuing a prepayment invoice with an invoice discount applied, the prepayment amount does not take into account the total amount including tax.#9222
Conversation
Copilot PR ReviewIteration 2 · Outcome: completed
Knowledge source: https://github.com/microsoft/BCQuality@822cae1b2771ac25f665f73369f69093bd4fd630 Orchestrator pre-filter (13 file(s) excluded)
Findings produced by the Copilot CLI agent against BCQuality at |
Agentic PR Review - Round 1Recommendation: Request ChangesWhat this PR doesThis PR changes NA sales prepayment posting so the invoice-discount reconciliation target uses the discounted tax-inclusive total when The fix is narrow and the normal no-invoice-discount path stays unchanged because SuggestionsS1 - Add Prices Including VAT coverage Risk assessment and necessityRisk: This is sales prepayment posting in the NA BaseApp, with invoice discount and tax in the same calculation. A wrong result can post the wrong financial amount. The code change is small and has no public API or event signature change, but the untested Necessity: ADO Bug 641621 is a valid and important bug; the repro data is concrete, although there is no
|
Bug 641621: [All-E][Main]When issuing a prepayment invoice with an invoice discount applied, the prepayment amount does not take into account the total amount including tax.
AB#641621
Issue: When posting a sales prepayment invoice with "Prepmt. Include Tax" = TRUE on an order that has an invoice discount applied, the posted prepayment amount incorrectly excludes sales tax. Removing the invoice discount produced the correct tax-inclusive prepayment, but adding a discount stripped the tax from the posted prepayment amount.
Cause: In the UpdateDifferenceAmount procedure in SalesPostPrepayments.Codeunit.al (which only runs when HasInvoiceDiscount is true), the reconciliation target was computed as SalesHeader.Amount * "Prepayment %" / 100 — i.e. the net, tax-excluded amount. The routine then subtracted the resulting difference (effectively the tax) from both Amount and "Amount Incl. VAT" of the prepayment buffer, removing the tax that the proportional PrepmtAmount calculation had correctly included.
Solution: Modified UpdateDifferenceAmount so that when SalesHeader."Prepmt. Include Tax" is true it uses SalesHeader."Amount Including VAT" * "Prepayment %" / 100 (the tax-inclusive amount) as the reconciliation target, matching the tax-inclusive values held in the prepayment buffer. This preserves the tax in the posted prepayment for the invoice-discount path, while the non-include-tax path and no-discount scenarios remain unchanged.