Repository navigation
[Master][ALL-E] Total (LCY) on the Vendor Card FactBox is incorrectly calculated when an unposted Purchase Invoice is linked to a Purchase Order - #13818
Conversation
Good Sense Reviewer - Round 1Recommendation: Request ChangesWhat this PR doesThis change subtracts purchase order amounts already represented by matched unposted invoices from vendor totals. It updates The proportional order-price deduction handles consistent full and partial matches, uses receipt allocations when present, and caps deductions at the remaining order quantity. Existing prepayment handling stays unchanged. However, the deduction ignores RU's agreement filter and can still subtract an order amount after the matched invoice quantity becomes zero; both cases produce incorrect financial totals. Problem-solution fitFit: Partial The change addresses double counting when an open purchase invoice is matched to an order, including ordinary receipt and partial-match scenarios. It does not preserve all supported filters or ensure that a stored match quantity is still represented by the current invoice. SuggestionsS1 (🔴 High): Preserve the Russian agreement filter when deducting matches S2 (🔴 High): Check current invoice quantities before deducting matched amounts Risk assessment and necessityRisk: Vendor Statistics and its FactBox can hide an outstanding purchase commitment or show a negative agreement-filtered total. The helper is repeated across fourteen table layers and adds order/match queries when totals are displayed; RU also has an agreement-specific filter contract. No posting, ledger writes, schema changes, or public/event signature changes are introduced. Nine added tests exercise real Get Order Lines flows and focused arithmetic cases, but do not cover these two regressions; builds and tests were not run in this review. Necessity: The correction is needed because matched orders and unposted invoices otherwise overstate vendor commitments, requiring manual reconciliation. Updating the shared vendor total and the independent FactBox calculation is appropriate, but the deduction must exclude documents outside the selected filters and quantities no longer represented by the invoice.
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Bug-658521-Main-TotalLCYontheVendorCardFactBoxIs-incorrectlycalculated
Good Sense Reviewer - Round 6Recommendation: Request ChangesWhat this PR doesRemoves duplicated purchase-order amounts from vendor commitment totals, including invoices created through Get Receipt Lines without an explicit match record. This round also subtracts shipped, uninvoiced purchase returns and extends Russian agreement filtering. The current invoice/sign/quantity safeguards and earlier FlowFilter fixes remain. However, Problem-solution fitFit: Partial The change covers standard receipt-linked invoices and retains the earlier matching and filter corrections. Mixed direct and explicit links to the same receipt still produce an understated total when the order is only partly received. Status of previous suggestions
New observations (commits since round 5)S4 (🔴 High): Share receipt capacity across both invoice link types S5 (🟠 Moderate): Show the purchase return deduction in the FactBox Risk assessment and necessityRisk: Financial statistics, not posting or ledger writes, are affected. Partial receipts mixed across direct links and explicit matches can understate vendor commitments. Current invoice capacity does not prevent this because the two invoices have different IDs, and the remaining unreceived order quantity gives the second deduction room. Existing exact-value tests retain prior safeguards, but do not cover this reachable mixed-link case. Necessity: Orders linked to unposted invoices otherwise overstate commitments, so receipt recognition is needed. The fix must share receipt capacity across both link mechanisms without removing the unrelated unreceived order balance; the return deduction should also remain visible and understandable.
|
Good Sense Reviewer - Round 7Recommendation: Accept with SuggestionsWhat this PR doesRemoves purchase-order amounts already represented by linked unposted invoices from vendor totals. This round shares each receipt's remaining quantity across direct invoice links and explicit receipt matches, and displays the purchase-return deduction in the FactBox. All five previous suggestions are addressed. The shared receipt capacity preserves the unreceived order balance, while current invoice limits, signs and selected filters remain intact across all fourteen vendor implementations. A limited rounding issue remains: reconstructing receipt base quantity can leave a small duplicated amount when a fractional unit conversion rounds upward. Status of previous suggestions
New observations (commits since round 6)S6 (🟠 Moderate): Use posted base quantities for receipt capacity Risk assessment and necessityRisk: These are read-only financial statistics, not posting or ledger writes. Mixed receipt links, partial quantities, fractional conversions and filtered prepayments or returns are the main regression surfaces. The remaining rounding issue affects commitment totals, not posted entries. Matching call sites, Sales and Service parallels, country variants and focused assertions were checked; no incompatible event signature or schema change was found. Validation was limited to source inspection and decimal arithmetic; builds and tests were not run. Necessity: Without the calculation fix, linked orders and unposted invoices count the same purchase commitment twice. Sharing receipt capacity preserves unrelated unreceived commitments, and showing the return deduction makes the FactBox total understandable. Both refinements are directly related to producing a reliable vendor total.
|
Good Sense Reviewer - Round 8Recommendation: AcceptWhat this PR doesThe new commit calculates remaining receipt capacity from posted Problem-solution fitFit: Strong The common vendor calculation removes only purchase commitments already represented by current unposted invoices. The latest correction removes the remaining base-quantity rounding discrepancy: the fractional example now gives 10,000.00 LCY rather than 10,000.10 LCY. Status of previous suggestions
New observations (commits since round 7)None. The requested receipt-capacity correction is present, and all previous suggestions have positive fix evidence. Risk assessment and necessityRisk: These are read-only vendor statistics calculations, not posting or ledger writes. Fractional conversions, mixed receipt links, negative quantities and filtered prepayments are the main regression surfaces; their allocation guards remain intact. The existing handled event exit and production event signatures are preserved. Necessity: Linked purchase orders and unposted invoices must not count the same commitment twice. Using posted base quantities also prevents rounding from leaving a residual duplicated amount.
|
|
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| if MatchedOrderLine.FindSet() then | ||
| repeat | ||
| PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId"); | ||
| if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin |
There was a problem hiding this comment.
GetMatchedOrderAmountLCY iterates Matched Order Line records for each purchase order line and performs a filtered PurchaseLineInvoice.FindFirst() inside that loop, while surrounding receipt and invoice loops perform further persistent-table reads. This creates an unbounded nested N+1 access pattern in vendor statistics; use a query or otherwise batch the related order, receipt, match, and invoice data before aggregating.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
Bug 658521: [Master][ALL-E] Total (LCY) on the Vendor Card FactBox is incorrectly calculated when an unposted Purchase Invoice is linked to a Purchase Order
Fixes AB#658521
Issue:
Total (LCY) on the Vendor Statistics FactBox is overstated when an unposted purchase invoice is linked to a purchase order.
Cause:
The calculation includes both the remaining purchase order amount and the outstanding invoice amount, double-counting the matched portion.
Solution:
Subtract the matched purchase order amount from Total (LCY), accounting for partial matches, receipt matches, and applicable dimension/currency filters while preserving existing prepayment behavior.