Skip to content

[Main][all-e]Prepayment Invoice and Quantity Change Issue in Business Central - #10176

Open
Shikhverma wants to merge 4 commits into
mainfrom
bugs/Bug-646136-Master-PrepaymentInvoiceQuantityChangeIssue
Open

[Main][all-e]Prepayment Invoice and Quantity Change Issue in Business Central#10176
Shikhverma wants to merge 4 commits into
mainfrom
bugs/Bug-646136-Master-PrepaymentInvoiceQuantityChangeIssue

Conversation

@Shikhverma

@Shikhverma Shikhverma commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Bug 646718: [Master][all-e][FTE][SaaS] Prepayment Invoice and Quantity Change Issue in Business Central - Copy

Fixes AB#646718

@github-actions github-actions Bot added the SCM GitHub request for SCM area label Aug 12, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Aug 12, 2026
Co-authored-by: Shikhverma <241284522+Shikhverma@users.noreply.github.com>
@github-actions github-actions Bot added the needs-approval Workflow runs require maintainer approval to start label Aug 12, 2026
@Shikhverma Shikhverma added Finance GitHub request for Finance area and removed needs-approval Workflow runs require maintainer approval to start SCM GitHub request for SCM area labels Aug 12, 2026
@github-actions github-actions Bot added SCM GitHub request for SCM area and removed Finance GitHub request for Finance area labels Aug 12, 2026
@Shikhverma Shikhverma closed this Aug 13, 2026
@Shikhverma Shikhverma reopened this Aug 13, 2026
@Shikhverma Shikhverma added Finance GitHub request for Finance area and removed SCM GitHub request for SCM area labels Aug 13, 2026
@github-actions github-actions Bot added SCM GitHub request for SCM area and removed Finance GitHub request for Finance area labels Aug 13, 2026
@neeleshsinghal
neeleshsinghal requested a lite review from Copilot August 13, 2026 05:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a prepayment scenario where reducing a Sales Order line’s Quantity to the already invoiced quantity after posting a prepayment and partial invoice could bypass prepayment-amount validation. The change adjusts prepayment amount update logic to ensure validations still run when Quantity changes, and adds regression tests covering the scenario.

Changes:

  • Update Sales Line prepayment amount update logic to not early-exit when the line Quantity has changed (so CheckPrepmtAmounts() can detect invalid prepayment amounts).
  • Add regression tests (W1 + RU) reproducing the “reduce quantity after prepayment + partial invoice” scenario and asserting the expected error.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Layers/W1/Tests/Prepayment/ERMPrepayment.Codeunit.al Adds regression test for reducing Sales Order quantity after prepayment + partial invoicing.
src/Layers/W1/BaseApp/Sales/Document/SalesLine.Table.al Prevents early-exit in UpdatePrepmtAmounts() when Quantity changes so prepayment validation runs.
src/Layers/SE/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for SE layer.
src/Layers/RU/Tests/Prepayment/ERMPrepayment.Codeunit.al Adds the same regression test for RU layer.
src/Layers/RU/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for RU layer.
src/Layers/NO/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for NO layer.
src/Layers/NA/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for NA layer.
src/Layers/IT/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for IT layer.
src/Layers/GB/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for GB layer.
src/Layers/FI/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for FI layer.
src/Layers/ES/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for ES layer.
src/Layers/CH/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for CH layer.
src/Layers/BE/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for BE layer.
src/Layers/APAC/BaseApp/Sales/Document/SalesLine.Table.al Same UpdatePrepmtAmounts() guard change as W1 for APAC layer.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Shikhverma Shikhverma added Finance GitHub request for Finance area and removed SCM GitHub request for SCM area labels Aug 13, 2026
@github-actions github-actions Bot added SCM GitHub request for SCM area and removed Finance GitHub request for Finance area labels Aug 13, 2026
@Shikhverma Shikhverma added Finance GitHub request for Finance area and removed SCM GitHub request for SCM area labels Aug 13, 2026
@github-actions github-actions Bot added SCM GitHub request for SCM area and removed Finance GitHub request for Finance area labels Aug 13, 2026
@Shikhverma
Shikhverma marked this pull request as ready for review August 14, 2026 04:41
@Shikhverma
Shikhverma requested a review from a team August 14, 2026 04:41
@Shikhverma
Shikhverma enabled auto-merge August 14, 2026 04:41
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 1

Recommendation: Accept with Suggestions

What this PR does

This PR changes Sales Line.UpdatePrepmtAmounts() in the Sales layers so a fully shipped and invoiced line does not skip prepayment validation when the user changes Quantity. With that guard, reducing the quantity after a posted prepayment and a partial invoice recalculates the prepayment line amount and lets CheckPrepmtAmounts() block the inconsistent amount.

The Sales fix is narrow and preserves the previous early exit when quantity did not change. The W1 and RU tests cover the reported flow: post a 50% prepayment invoice, post a partial sales invoice, reopen the order, and try to reduce Quantity to Quantity Invoiced.

Suggestions

S1 - Align the purchase prepayment mirror
Apply the same quantity-change guard to Purchase Line.UpdatePrepmtAmounts() and add the purchase regression test. The purchase code has the same early exit, so reducing a partially invoiced order can leave vendor prepayments inconsistent.

Risk assessment and necessity

Risk: This is a financial control path for posted prepayments, partial invoicing, and later quantity changes. The Sales change is small and does not change a public API or event signature, but the same prepayment pattern exists in Purchase.

Necessity: The AB#646718 scenario is valid and important because it can leave a customer prepayment out of balance with the final sales order quantity. Blocking the quantity reduction is the right point to stop the later delete path from hiding the mismatch.


[AI-PR-REVIEW] version=1 promptVersion=2 system=github pr=10176 round=1 by=alexei-dobriansky at=2026-08-14T08:56:15Z lastSha=91da96b542d6a7ae8db3b7053d8af16bc497ce4a reviewKey=na suggestions=S1@65e8761f

@alexei-dobriansky alexei-dobriansky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the purchase side.

@Shikhverma

Copy link
Copy Markdown
Contributor Author

Please check the purchase side.

Done for purchase side also

Comment thread src/Layers/W1/BaseApp/Purchases/Document/PurchaseLine.Table.al
Comment thread src/Layers/W1/BaseApp/Sales/Document/SalesLine.Table.al
@Shikhverma Shikhverma closed this Aug 15, 2026
auto-merge was automatically disabled August 15, 2026 02:54

Pull request was closed

@Shikhverma Shikhverma reopened this Aug 15, 2026
exit;

if (Rec.Quantity <> 0) and (Rec."Outstanding Quantity" = 0) and (Rec."Qty. Shipped Not Invoiced" = 0) then
if (Rec.Quantity <> 0) and (Rec."Outstanding Quantity" = 0) and (Rec."Qty. Shipped Not Invoiced" = 0) and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Testing}$

APAC Sales Line receives the same prepayment quantity-guard fix as W1, but this PR adds no matching APAC regression even though src/Layers/APAC/Tests/Prepayment/ERMPrepaymentII.Codeunit.al already carries layer-local partial-posted-invoice prepayment tests. Add an APAC test that reopens a partially invoiced prepayment sales order and verifies reducing Quantity to Quantity Invoiced still raises the expected Prepmt. Line Amount error, so the APAC override is proven independently of the W1 test suite.

Agent judgement — not directly backed by a BCQuality knowledge article.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.33.4

exit;

if (Rec.Quantity <> 0) and (Rec."Outstanding Quantity" = 0) and (Rec."Qty. Shipped Not Invoiced" = 0) then
if (Rec.Quantity <> 0) and (Rec."Outstanding Quantity" = 0) and (Rec."Qty. Shipped Not Invoiced" = 0) and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Testing}$

NA Sales Line receives the same prepayment quantity-guard fix as W1, but this PR adds no matching NA regression even though src/Layers/NA/Tests/Prepayment/ERMPrepaymentII.Codeunit.al and src/Layers/NA/Tests/Local/ERMSalesPurchasePrepayment.Codeunit.al already host layer-local prepayment quantity validations. Add an NA test that covers the partially invoiced case introduced here-reopen the order after prepayment plus partial invoicing and validate that reducing Quantity to Quantity Invoiced still fails with the Prepmt. Line Amount error.

Agent judgement — not directly backed by a BCQuality knowledge article.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.33.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SCM GitHub request for SCM area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants