Skip to content

[MAIN]-The system throws the error while posting a receipt against a Subcontracting Order. - #9729

Open
v-maheshsharma wants to merge 1 commit into
mainfrom
bugs/Bug-644092-MAIN-Error-while-posting-a-receipt-in-Subcontracting-Order
Open

[MAIN]-The system throws the error while posting a receipt against a Subcontracting Order.#9729
v-maheshsharma wants to merge 1 commit into
mainfrom
bugs/Bug-644092-MAIN-Error-while-posting-a-receipt-in-Subcontracting-Order

Conversation

@v-maheshsharma

@v-maheshsharma v-maheshsharma commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Bug 644092: Incident 51000001089716 : [BC-IN][28.1]The system throws the error while posting a receipt against a Subcontracting Order.

AB#644092

Issue:
Subcontracting receive/consume was failing with “Not enough inventory available at vendor location for this order” and showing incorrect remaining quantity in Apply Delivery Challan, especially when the same item had multiple variants.

Cause:
Remaining Quantity on Delivery Challan Line was aggregating inventory without enough granularity, so different variants/components were getting mixed. Also, in PostSubconComp, RemQtytoPost was not always reset after the last successful posting, which could trigger a false shortage error.

Solution:
Tightened the subcontracting inventory matching to be variant- and component-line-aware by refining the Delivery Challan Remaining Quantity flowfield and the ILE application logic. Also reset RemQtytoPost on final successful consumption so the shortage guard only fires for real shortages.

@github-actions github-actions Bot added the Finance GitHub request for Finance area label Jul 27, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Jul 27, 2026
@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.

@github-actions

Copy link
Copy Markdown
Contributor

$\textbf{🟠\ High\ Severity\ —\ Breaking\ Changes}$

The shipped Delivery Challan Line.Remaining Quantity FlowField now adds Variant Code, Order No., Order Line No., and Prod. Order Comp. Line No. filters to its CalcFormula. This silently changes the value returned for existing rows and for any extension code that already calls CalcFields("Remaining Quantity") on this shipped, public field — including rows created before those discriminator fields were reliably populated (e.g., historical Delivery Challan Lines where Variant Code/Order No./Order Line No. were blank or differently sourced). Because this is a field on a published table used across the app (and potentially by partner extensions), changing its CalcFormula is a behavioral break, not a purely internal fix. Consider introducing a new field/version for the narrower semantics, or verify/backfill historical data so existing rows resolve identically before switching the existing field's formula.

Line mapping was unavailable, so this was posted as an issue comment.

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

@github-actions

Copy link
Copy Markdown
Contributor

$\textbf{🟡\ Medium\ Severity\ —\ Data\ Modeling}$

The updated "Remaining Quantity" FlowField filters Item Ledger Entry by Variant Code, Order No., Order Line No., and Prod. Order Comp. Line No. (in addition to the existing filters), but no Item Ledger Entry key matches this full filter shape, and "Subcon Order No." is not indexed at all. On Delivery Challan pages/lookups this can turn CalcFields("Remaining Quantity") into an expensive residual-filter scan instead of an indexed SIFT lookup. Add or redesign an Item Ledger Entry key that matches the CalcFormula predicates, or reduce the FlowField to predicates already covered by an existing key.

Line mapping was unavailable, so this was posted as an issue comment.

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

@github-actions

Copy link
Copy Markdown
Contributor

$\textbf{🟠\ High\ Severity\ —\ Error\ Handling}$

In PostSubcontractComponent's posting loop, ItemJnlPostLine.Run(ItemJnlLine) executes and commits inventory postings for each item ledger entry processed inside the repeat...until loop. The new check if RemQtytoPost <> 0 then Error(NotEnoughInvtoryErr); is placed AFTER this loop, meaning if the loop exhausts all available Item Ledger Entry records (ItemLedgerEntry.Next() = 0) without fully covering RemQtytoPost, one or more ItemJnlPostLine.Run calls will already have executed for the entries that WERE available before the error is raised. This design relies entirely on Business Central's implicit transaction rollback semantics (the whole call chain must be inside one uncommitted write transaction) to make this atomic; if any caller wraps only part of this in an explicit COMMIT, or if this method is ever invoked from a context with an intervening COMMIT, partial postings would persist while the overall operation reports failure to the user. Given this is new logic changing existing posting flow, verify no COMMIT occurs between the loop and this new Error() call in any call path, or move the insufficient-quantity check to precede any posting (e.g., pre-calculate total available remaining quantity across matched ledger entries before starting to post) to avoid relying on rollback-by-error for correctness.

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

Line mapping was unavailable, so this was posted as an issue comment.

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

@github-actions

Copy link
Copy Markdown
Contributor

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

AppDelChallan."Applies-to Entry" already gives the full primary key for Item Ledger Entry, but the "Applies-to Entry" branch of GetApplicationLines still builds a filtered FindFirst() on a secondary key instead of a direct Get(). Use Get(...) first on the stored entry number, then validate the extra predicates (Variant Code, Open, Positive, Remaining Quantity) before falling back to the broader re-resolution path.

Knowledge:

Line mapping was unavailable, so this was posted as an issue comment.

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

@github-actions

Copy link
Copy Markdown
Contributor

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

CheckAvialibility() filters Delivery Challan Line by Variant Code after setting the current key to only "Delivery Challan No.", "Item No.", but this table declares no key that includes Variant Code. The lookup can read all rows for the challan/item pair and discard non-matching variants afterward; add or choose a key whose leading fields cover this access pattern.

Knowledge:

Line mapping was unavailable, so this was posted as an issue comment.

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

@github-actions

Copy link
Copy Markdown
Contributor

$\textbf{🟠\ High\ Severity\ —\ Breaking\ Changes}$

PostSubconComp and GetApplicationLines in SubcontractingPost.Codeunit.al are non-local posting helpers, so they are externally bindable contracts. This PR changes their behavior in place: PostSubconComp now throws a new NotEnoughInvtoryErr when residual quantity remains after posting (previously it could complete silently), and GetApplicationLines now narrows/re-resolves Item Ledger Entry selection with new Variant Code, Open, Positive, and Remaining Quantity > 0 filters. Dependent extensions that already call these helpers will observe a breaking behavioral change with no opt-in path. Either narrow these helpers to internal/local, or preserve prior behavior and introduce a separate, clearly-versioned entry point for the stricter logic.

Knowledge:

Line mapping was unavailable, so this was posted as an issue comment.

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

@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 1

Recommendation: Request Changes

What this PR does

This PR makes India GST subcontracting receipt posting choose delivery challan and item ledger entries with more filters, mainly variant and production component information. It also resets RemQtytoPost when the last posting consumes the exact remaining quantity, then raises NotEnoughInvtoryErr if quantity is still left after the loop.

The reset of RemQtytoPost fixes a clear false-shortage path. The narrower ILE filters also match the reported multi-variant case better than the previous item-only matching. But the change is in posting and challan application logic, and two important gaps remain: there is no regression test for the multi-variant receipt scenario, and one lookup path still selects the first challan line by item and variant instead of the exact component line.

Suggestions

S1 - Add a multi-variant posting regression test
Add a test in the GST Subcontracting test app that creates the same subcontracting order item with multiple component variants, applies the delivery challan, and posts the receipt. This is posting code, and the existing test app already has helpers for subcontracting send, apply, receipt, and post flows.

S2 - Match the exact component line
CheckAvialibility() still finds Delivery Challan Line by delivery challan, item, and variant only. Add the component-line filters, or use the exact selected challan line, so two lines with the same item and variant cannot choose the wrong Applies-to Entry.

S3 - Verify the FlowField compatibility impact
Changing Delivery Challan Line.Remaining Quantity adds new filters to a shipped FlowField. Verify that existing delivery challan and item ledger rows have those discriminator fields populated, or add upgrade/backfill handling before relying on the narrower formula.

Risk assessment and necessity

Risk: This is high-risk because it changes subcontracting receipt posting, item ledger application, and a FlowField used by delivery challan pages and validation. A wrong match can consume from the wrong variant or component line, and a false shortage can block receipt posting. No BaseApp publisher dependency was found in this diff; the change is local to the IN GST Subcontracting app.

Necessity: The customer incident is important, and the work item type is Bug. Without a fix, subcontracting receipt/consume can fail with “Not enough inventory available at vendor location for this order” when variants are mixed. The scope is mostly targeted, but it needs exact component-line matching and a regression test before merge.


[AI-PR-REVIEW] version=1 system=github pr=9729 round=1 by=alexei-dobriansky at=2026-08-03T10:19:41Z lastSha=fb4e06fd9ae0b7f711b80330ec83b391945caae8 suggestions=S1,S2,S3

@alexei-dobriansky alexei-dobriansky added SCM GitHub request for SCM area and removed Finance GitHub request for Finance area labels Aug 3, 2026
@github-actions github-actions Bot added Finance GitHub request for Finance area and removed SCM GitHub request for SCM area labels Aug 3, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants