[Main][all-e]Prepayment Invoice and Quantity Change Issue in Business Central - #10176
[Main][all-e]Prepayment Invoice and Quantity Change Issue in Business Central#10176Shikhverma wants to merge 4 commits into
Conversation
Co-authored-by: Shikhverma <241284522+Shikhverma@users.noreply.github.com>
There was a problem hiding this comment.
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 Lineprepayment amount update logic to not early-exit when the line Quantity has changed (soCheckPrepmtAmounts()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.
Agentic PR Review - Round 1Recommendation: Accept with SuggestionsWhat this PR doesThis 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. SuggestionsS1 - Align the purchase prepayment mirror Risk assessment and necessityRisk: 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.
|
alexei-dobriansky
left a comment
There was a problem hiding this comment.
Please check the purchase side.
…ssue' of https://github.com/microsoft/BCApps into bugs/Bug-646136-Master-PrepaymentInvoiceQuantityChangeIssue
Done for purchase side also |
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
Bug 646718: [Master][all-e][FTE][SaaS] Prepayment Invoice and Quantity Change Issue in Business Central - Copy
Fixes AB#646718