Skip to content

[Subcontracting] Block Get Order/Receipt Lines and item charges on undone subcontracting receipts#8704

Open
alexei-dobriansky wants to merge 1 commit into
mainfrom
bugs/632785-637503-Subcon_BlockGetOrderLinesAndGetUndoneRcpt-v2
Open

[Subcontracting] Block Get Order/Receipt Lines and item charges on undone subcontracting receipts#8704
alexei-dobriansky wants to merge 1 commit into
mainfrom
bugs/632785-637503-Subcon_BlockGetOrderLinesAndGetUndoneRcpt-v2

Conversation

@alexei-dobriansky

@alexei-dobriansky alexei-dobriansky commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Fixes AB#632785 and AB#637503 by blocking subcontracting scenarios that aren't supported and corrupt cost.

632785 - subcontracting lines must not be invoiced through a separate document:

  • Exclude subcontracting receipt lines (Prod. Order No. set) from Get Receipt Lines and block copying them, in SubcPurchPostExt (Purch.-Get Receipt subscribers).
  • Exclude subcontracting purchase order lines from Get Order Lines, via the new Matched Order Line Mgmt. filter event.

637503 - item charges against undone subcontracting receipts create orphaned capacity cost:

  • Block assigning an item charge to an undone (Correction) subcontracting receipt line in SubcItemChargeAssPurchExt.
  • Block posting an item charge assigned to an undone subcontracting receipt line in SubcPurchPostExt.

Tests: lightweight mock-based tests in SubcSubcontractingTest covering all three blocks.

Recreated from #8678 on a clean branch off latest main (resolves the folder-rename conflict).

…done subcontracting receipts

Fixes ADO bugs 632785 and 637503.

632785 - subcontracting lines must not be invoiced through a separate document:
- Exclude subcontracting receipt lines (Prod. Order No. set) from Get Receipt Lines
  and block copying them, in SubcPurchPostExt (Purch.-Get Receipt subscribers).
- Exclude subcontracting purchase order lines from Get Order Lines, via the new
  Matched Order Line Mgmt. filter event.

637503 - item charges against undone subcontracting receipts create orphaned capacity cost:
- Block assigning an item charge to an undone (Correction) subcontracting receipt line
  in SubcItemChargeAssPurchExt.
- Block posting an item charge assigned to an undone subcontracting receipt line in
  SubcPurchPostExt.

Tests: lightweight mock-based tests in SubcSubcontractingTest covering all three blocks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alexei-dobriansky alexei-dobriansky requested a review from a team June 22, 2026 08:04
@github-actions github-actions Bot added the AL: Apps (W1) Add-on apps for W1 label Jun 22, 2026
@alexei-dobriansky alexei-dobriansky enabled auto-merge (squash) June 22, 2026 08:07
@github-actions github-actions Bot added this to the Version 29.0 milestone Jun 22, 2026
ItemChargeAssignmentPurch2.SetRange("Document Line No.", ItemChargeAssignmentPurch."Document Line No.");
ItemChargeAssignmentPurch2.SetRange("Applies-to Doc. Type", "Purchase Applies-to Document Type"::Receipt);
repeat
if (FromPurchRcptLine."Prod. Order No." <> '') and FromPurchRcptLine.Correction then

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\ —\ Style} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

Wrong identifier field for subcontracting check

The undone-receipt guard uses "Prod. Order No." (the standard BC field) to identify a subcontracting line, but the event handler above (line 30) uses "Subc. Prod. Order No." (the extension field) as the definitive subcontracting identifier. A real subcontracting receipt line may have "Subc. Prod. Order No." <> '' while "Prod. Order No." = '', which would allow assigning item charges to an undone line without raising an error.

Recommendation:

  • Replace FromPurchRcptLine."Prod. Order No." <> '' with FromPurchRcptLine."Subc. Prod. Order No." <> '' to be consistent with the rest of the handler and correctly identify subcontracting lines.
Suggested change
if (FromPurchRcptLine."Prod. Order No." <> '') and FromPurchRcptLine.Correction then
if (FromPurchRcptLine."Subc. Prod. Order No." <> '') and FromPurchRcptLine.Correction then
Error(AssignToUndoneRcptErr, FromPurchRcptLine."Document No.", FromPurchRcptLine."Line No.");

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

PurchRcptLine."Document No." := CopyStr(LibraryUtility.GenerateGUID(), 1, MaxStrLen(PurchRcptLine."Document No."));
PurchRcptLine."Line No." := 10000;
PurchRcptLine.Type := PurchRcptLine.Type::Item;
PurchRcptLine."No." := Item."No.";

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\ —\ Style} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

Mock missing "Subc. Prod. Order No." — test never reaches new guard

MockSubcontractingPurchRcptLine sets "Prod. Order No." but not "Subc. Prod. Order No.". The event handler OnBeforeCreateRcptChargeAssgnt exits early at if FromPurchRcptLine."Subc. Prod. Order No." = '' then exit (line 30 of the production codeunit), so CreateRcptChargeAssgnt is never called and AssignToUndoneRcptErr is never raised. The asserterror in AssignItemChargeToUndoneSubcontractingReceiptIsBlocked will therefore fail with "there was no error".

Recommendation:

  • Add PurchRcptLine."Subc. Prod. Order No." := CopyStr(LibraryUtility.GenerateGUID(), 1, MaxStrLen(PurchRcptLine."Subc. Prod. Order No.")); to MockSubcontractingPurchRcptLine so the handler proceeds past the early-exit check and reaches the new undone guard.
Suggested change
PurchRcptLine."No." := Item."No.";
PurchRcptLine."Prod. Order No." := CopyStr(LibraryUtility.GenerateGUID(), 1, MaxStrLen(PurchRcptLine."Prod. Order No."));
PurchRcptLine."Subc. Prod. Order No." := CopyStr(LibraryUtility.GenerateGUID(), 1, MaxStrLen(PurchRcptLine."Subc. Prod. Order No."));
PurchRcptLine."Routing No." := CopyStr(LibraryUtility.GenerateGUID(), 1, MaxStrLen(PurchRcptLine."Routing No."));

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

PurchRcptLine.SetRange("Prod. Order No.", '');
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Get Receipt", OnCreateInvLinesOnBeforeInsertLineIteration, '', false, false)]

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{🟡\ Medium\ Severity\ —\ Style} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

Duplicate subscribers may suppress expected error in test

ExcludeSubcontractingLinesOnAfterPurchRcptLineSetFilters adds SetRange("Prod. Order No.", '') to the iteration record, silently filtering out subcontracting lines before the loop runs. If this event fires on the same record instance that CreateInvLines iterates, BlockSubcontractingLinesOnCreateInvLinesOnBeforeInsertLineIteration (which throws GetSubcontractingRcptNotSupportedErr) will never be reached, and GetReceiptLinesBlocksSubcontractingReceiptLine's asserterror would fail because no error is thrown.

Recommendation:

  • Verify (via a debug run or base-codeunit inspection) that OnAfterPurchRcptLineSetFilters operates on a different record instance than the one iterated in OnCreateInvLinesOnBeforeInsertLineIteration. If both events touch the same record, remove the filter subscriber and rely solely on the error-throwing subscriber, or adjust the test to assert no lines are returned instead of asserting an error.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

@ChethanT ChethanT added the Subcontracting Subcontracting related activities label Jun 22, 2026
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 Subcontracting Subcontracting related activities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants