Skip to content

[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

Open
DhavalMore88 wants to merge 1 commit into
microsoft:mainfrom
DhavalMore88:bugs/Bug-641621-Main-issuing-a-prepayment-invoice-2
Open

[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
DhavalMore88 wants to merge 1 commit into
microsoft:mainfrom
DhavalMore88:bugs/Bug-641621-Main-issuing-a-prepayment-invoice-2

Conversation

@DhavalMore88

@DhavalMore88 DhavalMore88 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added From Fork Pull request is coming from a fork Linked Issue is linked to a Azure Boards work item labels Jul 8, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Jul 8, 2026
@DhavalMore88 DhavalMore88 added the Finance GitHub request for Finance area label Jul 8, 2026
@DhavalMore88 DhavalMore88 self-assigned this Jul 8, 2026
@DhavalMore88 DhavalMore88 marked this pull request as ready for review July 8, 2026 13:37
@DhavalMore88 DhavalMore88 requested a review from a team July 8, 2026 13:37
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Copilot PR Review

Iteration 2 · Outcome: completed

All applicable sub-skills completed with no findings; upgrade and UI leaves were not-applicable (no upgrade codeunits or page/UI files changed); security and privacy leaves found no applicable knowledge files for this diff.

Knowledge source: https://github.com/microsoft/BCQuality@822cae1b2771ac25f665f73369f69093bd4fd630

Orchestrator pre-filter (13 file(s) excluded)

  • layer-disabled (knowledge) : 13 file(s)

Findings produced by the Copilot CLI agent against BCQuality at 822cae1b2771ac25f665f73369f69093bd4fd630. Reply 👎 on any inline comment to flag false positives.

@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 1

Recommendation: Request Changes

What this PR does

This PR changes NA sales prepayment posting so the invoice-discount reconciliation target uses the discounted tax-inclusive total when Prepmt. Include Tax is true. That matches the buffer built earlier: the sales tax path puts the tax-inclusive prepayment amount into the buffer, then UpdateDifferenceAmount only adjusts it when an invoice discount exists.

The fix is narrow and the normal no-invoice-discount path stays unchanged because HasInvoiceDiscount still gates the adjustment. The purchase prepayment analog does not have this extra UpdateDifferenceAmount path, so I did not find the same bug there. No event subscribers or publisher contracts are changed.

Suggestions

S1 - Add Prices Including VAT coverage
The new tests cover invoice discount plus tax with Prices Including VAT = false only. Add the same exact amount check with Prices Including VAT = true, because that setup changes how line amounts and tax-inclusive totals are built before UpdateDifferenceAmount uses "Amount Including VAT".

Risk assessment and necessity

Risk: 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 Prices Including VAT = true setup is still part of the same tax-inclusive amount path.

Necessity: ADO Bug 641621 is a valid and important bug; the repro data is concrete, although there is no [AI-REPRO] comment. The fix is needed because customers can post a prepayment invoice that excludes tax even when Prepmt. Include Tax is enabled. The scope is right, but the missing test case should be added before merge.


[AI-PR-REVIEW] version=1 system=github pr=9222 round=1 by=alexei-dobriansky at=2026-07-08 lastSha=7d096545e8304143d1e860a3787201d2c76e8280 suggestions=S1

@DhavalMore88 DhavalMore88 reopened this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Finance GitHub request for Finance area From Fork Pull request is coming from a fork Linked Issue is linked to a Azure Boards work item

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants