Skip to content

[Subcontracting] [28.x] Item Charge for Last-Operation Subcontracting Receipt Linked to Wrong Ledger Entry#8808

Merged
alexei-dobriansky merged 3 commits into
microsoft:releases/28.xfrom
GOB-Software-Systeme-DevOps:w/grosss/28.x_SubcontractingItemChargesFix
Jun 26, 2026
Merged

[Subcontracting] [28.x] Item Charge for Last-Operation Subcontracting Receipt Linked to Wrong Ledger Entry#8808
alexei-dobriansky merged 3 commits into
microsoft:releases/28.xfrom
GOB-Software-Systeme-DevOps:w/grosss/28.x_SubcontractingItemChargesFix

Conversation

@stevengrossGOB

@stevengrossGOB stevengrossGOB commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Bug: Item Charge for Last-Operation Subcontracting Receipt Linked to Wrong Ledger Entry

Scenario ID

AB#640042

Affected Objects

Type Name ID
Codeunit (App) Subc. Purch. Post Ext 99001535
Codeunit (Base App) Item Jnl.-Post Line 22

Reproduction Steps

  1. Manufacturing item with a single-operation routing (subcontracting work center = last operation). Certified routing + BOM.
  2. Released production order → subcontracting purchase order.
  3. Post purchase receipt (Receive = Yes, Invoice = No).
  4. Create a separate purchase invoice with an item charge assigned to the receipt line and post it.

False Behavior

ValueEntry."Item Ledger Entry No." points to an arbitrary, unrelated ILE whose entry number coincidentally equals the Capacity Ledger Entry number from the receipt — or posting fails with "The Item Ledger Entry does not exist". The production order reference and serial number on the linked ILE are wrong.

Expected Behavior

Tracked items (serial / lot)

ValueEntry."Item Ledger Entry No." = Output ILE, "Capacity Ledger Entry No." = 0.
Order Type = Production, correct Order No. and serial number.

Non-tracked items

ValueEntry."Capacity Ledger Entry No." = Capacity Ledger Entry from the service receipt, "Item Ledger Entry No." = 0.
Order Type = Production, correct Order No.

Root Cause

CopySubcontractingProdOrderFieldsToItemJnlLine unconditionally set Entry Type = Output and Subcontracting = true on the item journal line — including for last-operation item charges. This routed posting through PostOutput / InsertCapValueEntry regardless of item tracking, producing wrong value entry linkages.

Tracked items

PurchRcptLine."Item Rcpt. Entry No." = 0 for tracked items. PostItemChargePerRcpt uses CollectItemEntryRelation to distribute the charge across each Output ILE. With Entry Type = Output still set, PostOutput was called per ILE using the Output ILE entry number as a Capacity Ledger Entry key → error or wrong entry.

Non-tracked items

PurchRcptLine."Item Rcpt. Entry No." = CapLedgEntryNo. With Entry Type = Purchase (default from Purch.-Post, before our code ran), PostItem called GlobalItemLedgEntry.Get(CapLedgEntryNo) — loading whichever ILE happened to carry that number.

Fix

CopySubcontractingProdOrderFieldsToItemJnlLine now distinguishes last-operation from non-last-operation and tracked from non-tracked:

if PurchRcptLineIsLastOperation(PurchRcptLine) then begin
    if Item."Item Tracking Code" <> '' then begin
        // Tracked: PostItem path — Output ILE found via Item Entry Relation.
        // Order info comes from the ILE in InitValueEntry; no explicit setting needed.
        ItemJournalLine.Subcontracting := false;
        ItemJournalLine."Entry Type" := "Item Ledger Entry Type"::Purchase;
    end else begin
        // Non-tracked: PostOutput path — links to the Capacity Ledger Entry.
        // Order info must be set explicitly; InsertCapValueEntry reads it from the journal line.
        ItemJournalLine.Subcontracting := true;
        ItemJournalLine."Order Type"     := "Inventory Order Type"::Production;
        ItemJournalLine."Order No."      := PurchRcptLine."Prod. Order No.";
        ItemJournalLine."Order Line No." := PurchRcptLine."Prod. Order Line No.";
        ItemJournalLine."Entry Type"     := "Item Ledger Entry Type"::Output;
        // ... Type, No., Routing, Work Center fields ...
    end;
    exit;
end;
// Non-last-op: Subcontracting = true, Entry Type = Output (unchanged)

"Inventory Posting Group" and "Subc. Item Charge Assign." are set before the check for both paths.

Related Work Items / PRs

@stevengrossGOB stevengrossGOB requested a review from a team June 24, 2026 15:05
@stevengrossGOB stevengrossGOB requested a review from a team as a code owner June 24, 2026 15:05
@github-actions github-actions Bot added AL: Apps (W1) Add-on apps for W1 From Fork Pull request is coming from a fork Linked Issue is linked to a Azure Boards work item labels Jun 24, 2026
@github-actions github-actions Bot added this to the Version 28.3 milestone Jun 24, 2026
@github-actions github-actions Bot added needs-approval Workflow runs require maintainer approval to start and removed needs-approval Workflow runs require maintainer approval to start labels Jun 24, 2026
@github-actions github-actions Bot added the needs-approval Workflow runs require maintainer approval to start label Jun 25, 2026
@alexei-dobriansky alexei-dobriansky enabled auto-merge (squash) June 25, 2026 11:01
@github-actions github-actions Bot removed the needs-approval Workflow runs require maintainer approval to start label Jun 25, 2026
auto-merge was automatically disabled June 26, 2026 06:18

Head branch was pushed to by a user without write access

@github-actions github-actions Bot added the needs-approval Workflow runs require maintainer approval to start label Jun 26, 2026
@alexei-dobriansky alexei-dobriansky enabled auto-merge (squash) June 26, 2026 07:57
@github-actions github-actions Bot removed the needs-approval Workflow runs require maintainer approval to start label Jun 26, 2026
@alexei-dobriansky alexei-dobriansky merged commit 2160e1d into microsoft:releases/28.x Jun 26, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1 From Fork Pull request is coming from a fork Linked Issue is linked to a Azure Boards work item

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants