Skip to content

Bug 634269: [Subcontracting] Fix second return from subcontractor failing after first posted#8222

Draft
ChethanT wants to merge 2 commits into
mainfrom
bugs/Subcontracting/634269-ReturnTransferDeleteLocation
Draft

Bug 634269: [Subcontracting] Fix second return from subcontractor failing after first posted#8222
ChethanT wants to merge 2 commits into
mainfrom
bugs/Subcontracting/634269-ReturnTransferDeleteLocation

Conversation

@ChethanT
Copy link
Copy Markdown
Contributor

@ChethanT ChethanT commented May 20, 2026

Problem

Cannot create a second return from subcontractor after the first return transfer order is posted and deleted. The error is:

Transfer-from Code and Transfer-to Code cannot be the same

Root Cause

The OnAfterDeleteEvent subscriber in SubcTransferLineExt.Codeunit.al calls UpdateLocationCodeInProdOrderCompAfterDeleteTransferLine for ALL transfer line deletions, including return transfer lines. This procedure was designed only for outbound transfer cleanup (restoring the component location from SUBC back to MAIN when an outbound transfer is deleted/cancelled).

When it fires for a return line deletion (after posting), it:

  1. Restores ProdOrderComponent."Location Code" to the Original Location Code
  2. Clears "Subc. Original Location Code" to ''

On the next return attempt, the system sees Orig Location Code = '', sets it to the current (corrupted) location, and computes Transfer-from = Transfer-to = SUBC → error.

Fix

Added a guard in OnAfterDeleteEvent:

if Rec."Subc. Return Order" then
    exit;

This ensures location restoration only runs for outbound transfer line deletions, not return lines.

Testing

New test codeunit 149917 that:

  1. Creates outbound transfer, posts it
  2. Creates first return, posts it (return transfer deleted)
  3. Creates second return — verifies it succeeds without error

Fixes AB#634269

…d (bug 634269)

The OnAfterDeleteEvent subscriber in SubcTransferLineExt fired
UpdateLocationCodeInProdOrderCompAfterDeleteTransferLine unconditionally
for ALL transfer lines, including return lines. When a return transfer order
was posted and deleted, this incorrectly restored the component's location
back to its original location and cleared Subc. Original Location Code.

On the next return attempt, the system would use the corrupted component
state, computing Transfer-from = Transfer-to (both SUBC), triggering the
'Transfer-from Code and Transfer-to Code cannot be the same' error.

Fix: Add guard 'if Rec."Subc. Return Order" then exit' so the location
restoration only runs for outbound transfer line deletions.

Added test codeunit 149917 verifying second return succeeds after first
return is posted.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the AL: Apps (W1) Add-on apps for W1 label May 20, 2026
@ChethanT ChethanT changed the title [Subcontracting] Fix second return from subcontractor failing after first posted (bug 634269) Bug 634269: [Subcontracting] Fix second return from subcontractor failing after first posted May 20, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone May 20, 2026
…Subcontracting/634269-ReturnTransferDeleteLocation
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant