Skip to content

[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

Open
sanjmaurya wants to merge 14 commits into
mainfrom
bugs/Bug-658521-Main-TotalLCYontheVendorCardFactBoxIs-incorrectlycalculated
Open

sanjmaurya wants to merge 14 commits into
mainfrom
bugs/Bug-658521-Main-TotalLCYontheVendorCardFactBoxIs-incorrectlycalculated

Conversation

@sanjmaurya

@sanjmaurya sanjmaurya commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the Team: Finance GitHub request for Finance area label Nov 9, 2026
@github-actions github-actions Bot added this to the Version 30.0 milestone Nov 9, 2026
@sanjmaurya
sanjmaurya marked this pull request as ready for review November 10, 2026 02:48
@sanjmaurya
sanjmaurya requested a review from a team as a code owner November 10, 2026 02:49
v-ankitgoyal
v-ankitgoyal previously approved these changes Nov 10, 2026
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 1

Recommendation: Request Changes

What this PR does

This change subtracts purchase order amounts already represented by matched unposted invoices from vendor totals. It updates Vendor.GetTotalAmountLCY() across fourteen table layers and the separate Vendor Statistics FactBox calculation.

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 fit

Fit: 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.

Suggestions

S1 (🔴 High): Preserve the Russian agreement filter when deducting matches
Copy Agreement Filter to the order line's Agreement No. before copying the invoice filters. RU's order and invoice FlowFields apply this filter, but this deduction does not. With no entries for agreement A and a 100-LCY matched order/invoice for agreement B, selecting A now returns -100 LCY instead of 0.

S2 (🔴 High): Check current invoice quantities before deducting matched amounts
Check the current invoice quantity, not only whether the line exists, before deducting its matched order quantity. After Get Order Lines copies a 10-unit, 100-LCY unreceived order, changing the invoice quantity to zero leaves the match at 10. Both totals then show 0 although the 100-LCY order remains outstanding.

Risk assessment and necessity

Risk: 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.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=13818 round=1 by=alexei-dobriansky at=2026-11-10T08:21:27Z lastSha=17bce37cf8a071a4b3fef22f9ccc76b2a9393fa2 reviewKey=5e4f0b1471aa584814c4cdbd7e498c3a8ae267ba594decf21b72a66255597d4f suggestions=S1@ce298ca3,S2@151f8a0d

sanjmaurya and others added 3 commits November 10, 2026 16:38
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Bug-658521-Main-TotalLCYontheVendorCardFactBoxIs-incorrectlycalculated
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 6

Recommendation: Request Changes

What this PR does

Removes 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, Vendor.GetMatchedOrderAmountLCY spends receipt capacity without sharing the remainder with explicit matches on other invoice lines. Both standard invoice-creation actions allow these documents to coexist unposted, so a partly received order can lose some of its still-unreceived commitment from the total. The same calculation is present across the fourteen vendor implementations.

Problem-solution fit

Fit: 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
ID Title Status Current evidence
S1 Preserve the Russian agreement filter when deducting matches Addressed The agreement filter reaches order lines before their filters are copied to invoice lines. Exact excluded, included, combined and differing-agreement assertions remain.
S2 Check current invoice quantities before deducting matched amounts Addressed Both paths retain current invoice existence, sign checks and shared invoice capacity. The new issue below concerns receipt capacity shared across different invoices, not those existing safeguards.
S3 Apply FlowFilters before subtracting invoiced vendor prepayments Addressed Dimension and currency filters precede summation; the FactBox selects the linked filter group first. Agreement-filtered prepayment assertions now also cover the table, Statistics page and Vendor List FactBox.
New observations (commits since round 5)

S4 (🔴 High): Share receipt capacity across both invoice link types
Share each receipt's remaining base quantity between receipt-linked invoices and explicit receipt matches. With a 10-unit order, 4 units received, and two 4-unit invoices using these two links, the helper deducts 8 units although both invoices refer to the same 4 received units. At 10 LCY per unit, the vendor total becomes 100 LCY instead of 140 LCY.

S5 (🟠 Moderate): Show the purchase return deduction in the FactBox
Show the shipped, uninvoiced purchase return amount in the Vendor Statistics FactBox, as the Customer FactBox does for received returns. This amount now reduces Total (LCY), but no visible field explains the deduction.

Risk assessment and necessity

Risk: 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.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=13818 round=6 by=alexei-dobriansky at=2026-11-24T08:34:30.6510212Z lastSha=d1e241824772c595dea32f213938a2676ad2aca4 reviewKey=bf0c94617f3cbcd89d9fdfb337d6cc002cbfcc43a21bd783b1f6503ed484ce46 suggestions=S1@ce298ca3:addressed,S2@151f8a0d:addressed,S3@bc45b1ef:addressed,S4@dcebbae8:new,S5@7f768380:new parentRound=5

@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 7

Recommendation: Accept with Suggestions

What this PR does

Removes 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
ID Title Status Author response
S1 Preserve the Russian agreement filter when deducting matches Addressed The agreement filter still reaches the order before its filters are copied to the invoice. Exact agreement-filter assertions remain.
S2 Check current invoice quantities before deducting matched amounts Addressed Both link types use the current signed invoice quantity and shared invoice capacity. Reduced, zero, opposite-sign and deleted-invoice cases remain covered.
S3 Apply FlowFilters before subtracting invoiced vendor prepayments Addressed Dimension, currency and applicable agreement filters precede summation. The FactBox selects its filter group before deductions; exact table and page assertions remain.
S4 Share receipt capacity across both invoice link types Addressed Both paths consume one dictionary keyed by receipt ID. Exhausted receipt matches cannot fall back to the order quantity; positive and negative mixed-link regressions check exact totals.
S5 Show the purchase return deduction in the FactBox Addressed The new return field displays the same filtered value subtracted from Total (LCY). Tests check its visibility and value.
New observations (commits since round 6)

S6 (🟠 Moderate): Use posted base quantities for receipt capacity
Use the receipt's posted Quantity (Base) less Qty. Invoiced (Base) as its capacity. Multiplying the document quantity by the conversion factor can lose base-quantity rounding. A fully received and matched 10,000 LCY order with quantity and conversion factor both 0.33333 then leaves Total (LCY) at 10,000.10 instead of 10,000.00.

Risk assessment and necessity

Risk: 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.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=13818 round=7 by=alexei-dobriansky at=2026-11-24T14:57:01.4959114Z lastSha=08b223949cf90d95389ce4c5eb10106d1704d009 reviewKey=66e52cf61f251de6c16387d33430e5708624a708e739146a0b50f1580b536126 suggestions=S1@ce298ca3:addressed,S2@151f8a0d:addressed,S3@bc45b1ef:addressed,S4@dcebbae8:addressed,S5@7f768380:addressed,S6@4d66ea64:new parentRound=6

@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 8

Recommendation: Accept

What this PR does

The new commit calculates remaining receipt capacity from posted Quantity (Base) minus Qty. Invoiced (Base), instead of reconstructing it from document quantities and the conversion factor. All fourteen implementations use the same correction. It preserves shared invoice/receipt allocation and sign checks, and adds exact fractional-conversion and partly/fully invoiced receipt assertions.

Problem-solution fit

Fit: 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
ID Title Status Response / evidence
S1 Preserve the Russian agreement filter when deducting matches Addressed Both order and invoice lookups retain the agreement filter, with exact filtered assertions.
S2 Check current invoice quantities before deducting matched amounts Addressed Current invoice capacity, sign checks and shared limits govern deductions; deleted and zero-quantity invoices are covered.
S3 Apply FlowFilters before subtracting invoiced vendor prepayments Addressed Dimension, currency and applicable agreement filters are applied before sums and FactBox deductions.
S4 Share receipt capacity across both invoice link types Addressed Direct receipt links and explicit matches consume the same capacity; exhausted matches cannot fall back to order allocation.
S5 Show the purchase return deduction in the FactBox Addressed The visible LCY return field displays the same amount deducted from the total.
S6 Use posted base quantities for receipt capacity Addressed Posted base quantities replace reconstruction across all fourteen implementations, with fractional and partial-invoicing regression assertions.
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 necessity

Risk: 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.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=13818 round=8 by=alexei-dobriansky at=2026-11-25T08:21:54.5794071Z lastSha=d3ee0a73b9db91263ab4d3ca723dc320edfb7369 reviewKey=c6a3d7f8d2f39b652bb827fd0621b1ac913b9609bad16479e5b9d7d3d60c03d4 suggestions=S1@ce298ca3:addressed,S2@151f8a0d:addressed,S3@bc45b1ef:addressed,S4@dcebbae8:addressed,S5@7f768380:addressed,S6@4d66ea64:addressed parentRound=7

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Stale Status Check Deleted

The Pull Request Build workflow run for this PR was older than 72 hours and has been deleted.

📋 Why was it deleted?

Status checks that are too old may no longer reflect the current state of the target branch. To ensure this PR is validated against the latest code and passes up-to-date checks, a fresh build is required.


🔄 How to trigger a new status check:

  1. 📤 Push a new commit to the PR branch, or
  2. 🔁 Close and reopen the PR

This will automatically trigger a new Pull Request Build workflow run.

@sanjmaurya sanjmaurya closed this Nov 30, 2026
@sanjmaurya sanjmaurya reopened this Nov 30, 2026
@github-actions github-actions Bot added Ownership: Needs Review Ownership is Other, low confidence, or needs manual correction Team: Other GitHub request for other area than SCM, Finance or Integration and removed Team: Finance GitHub request for Finance area labels Nov 30, 2026
if MatchedOrderLine.FindSet() then
repeat
PurchaseLineInvoice.SetRange(SystemId, MatchedOrderLine."Document Line SystemId");
if PurchaseLineInvoice.FindFirst() and not ReceiptLinkedInvoices.ContainsKey(PurchaseLineInvoice.SystemId) then begin

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

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{🟠\ High\ Severity\ —\ Performance}$

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

This branch was successfully deployed

1 active deployment
triage — d3ee0a73 Deployed Nov 30, 2026 by sanjmaurya via Classify team ownership #12341
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ownership: Needs Review Ownership is Other, low confidence, or needs manual correction Team: Other GitHub request for other area than SCM, Finance or Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants