Skip to content

[Closed][Subcontracting] Fix subcontracting order opening wrong purchase order after creation#8811

Closed
6CRIPT wants to merge 15 commits into
mainfrom
bugs/639381-subcontracting-order-opens-old-purchase-order
Closed

[Closed][Subcontracting] Fix subcontracting order opening wrong purchase order after creation#8811
6CRIPT wants to merge 15 commits into
mainfrom
bugs/639381-subcontracting-order-opens-old-purchase-order

Conversation

@6CRIPT

@6CRIPT 6CRIPT commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

CLOSED BECAUSE COPILOT ADDED NOISE WITHOUT PERMISSION.
CREATING A NEW CLEAN PR: #9396

Fixes AB#639381

Problem

When a subcontracting operation already had a received purchase order and the production order quantity was increased, clicking Create Subcontracting Order again created a new PO for the delta quantity but opened the old, already-received PO instead of the newly created one. The user had to manually navigate to find the correct order.

Root cause

ShowCreatedPurchaseOrder re-derived which PO to open by filtering purchase lines (Prod. Order No. + Operation No. + Routing Reference No.). That filter matched both the old and the new lines, so FindFirst returned the lowest Document No. (the old one). The code never tracked which document was actually created during the current run.

Fix

We now capture the purchase order(s) actually created/affected in the current invocation: we snapshot the existing subcontracting POs before Carry Out and Mark the newly created (or updated) header afterwards, then open only the marked set. Filtering was aligned with PurchLineExists (open, unreceived lines), the confirmation count/branching is derived from the marked headers, and a fallback keeps working when Carry Out updates an existing open PO instead of creating a new one. Added two integration tests covering the delta-PO and updated-open-PO scenarios.

@6CRIPT 6CRIPT requested a review from a team June 25, 2026 06:54
@github-actions github-actions Bot added the AL: Apps (W1) Add-on apps for W1 label Jun 25, 2026
@6CRIPT 6CRIPT changed the title Fix subcontracting order opening wrong purchase order after creation [Subcontracting] Fix subcontracting order opening wrong purchase order after creation Jun 25, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Jun 25, 2026
@6CRIPT 6CRIPT requested a review from Copilot June 25, 2026 07:03
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Copilot PR Review

Iteration 15 · Outcome: completed

Knowledge source: https://github.com/microsoft/BCQuality@822cae1b2771ac25f665f73369f69093bd4fd630

Findings by domain

Findings split into Knowledge-backed (cite a BCQuality article) and Agent (the agent's own judgement, no matching BCQuality rule).

Domain Findings Knowledge-backed Agent Inline Fallback
Agent 1 0 1 1 0

Totals: 0 knowledge-backed · 1 agent findings.

Orchestrator pre-filter (13 file(s) excluded)

  • layer-disabled (knowledge) : 13 file(s)

Findings produced by the Copilot CLI agent against BCQuality at 822cae1b2771ac25f665f73369f69093bd4fd630. Reply 👎 on any inline comment to flag false positives.

Copilot AI left a comment

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.

Pull request overview

This PR addresses an issue in the Subcontracting app where, after creating subcontracting purchase orders from production order routing lines, the UI could open the wrong purchase order (typically an existing one matching the same routing-line filters).

Changes:

  • Track and mark newly created purchase order headers by diffing purchase lines before/after running “Carry Out Action Msg. - Req.”.
  • Update the “show created purchase order(s)” flow to open the marked purchase order(s) instead of searching by routing/operation fields.
  • Remove now-unneeded operation/routing-reference state plumbing from the routing page extension.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Apps/W1/Subcontracting/App/src/Purchase/SubcPurchaseOrderCreator.Codeunit.al Adds logic to collect existing PO numbers, mark newly created PO headers, and use marked headers when showing created orders.
src/Apps/W1/Subcontracting/App/src/Manufacturing/SubcProdOrderRtng.PageExt.al Removes operation/routing-reference setter calls since the creator codeunit now tracks created orders internally.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Apps/W1/Subcontracting/App/src/Purchase/SubcPurchaseOrderCreator.Codeunit.al Outdated

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/Apps/W1/Subcontracting/App/src/Purchase/SubcPurchaseOrderCreator.Codeunit.al Outdated
@6CRIPT 6CRIPT self-assigned this Jun 25, 2026

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/Apps/W1/Subcontracting/App/src/Purchase/SubcPurchaseOrderCreator.Codeunit.al Outdated
Comment thread src/Apps/W1/Subcontracting/App/src/Purchase/SubcPurchaseOrderCreator.Codeunit.al Outdated

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@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.

@6CRIPT 6CRIPT closed this Jun 29, 2026
@6CRIPT 6CRIPT reopened this Jun 29, 2026
@ChethanT

Copy link
Copy Markdown
Contributor

Should we add a test?

@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 4

Recommendation: Accept with Suggestions

What this PR does

The round-4 commit only updates the two regression tests by removing the extra RefreshProdOrder call after increasing the production order line quantity. This makes the tests closer to the ADO repro steps, where the quantity is changed and the subcontracting action is run again without an explicit refresh.

The production code did not change. The tests still exercise the affected navigation paths: the received-old-PO case opens the newly created PO, and the open-existing-PO case reopens the affected existing PO.

Status of previous suggestions
ID Title Status Author response
S1 Scope existing order list filters Disputed / open The response says S1 is out of scope. The round-4 commit does not change this; ShowExistingPurchaseOrdersForRoutingLines still opens a list filtered only by Prod. Order No..
S2 Protect direct public callers Addressed Round 2 added XML documentation for the public method contract. The round-4 commit does not change that.
New observations (commits since round 3)

None. The only new commit adjusts the tests and does not introduce a new functional issue.

Risk assessment and necessity

Risk: The round-4 change is test-only, so it does not add product regression risk. The main fix remains narrow and tested for the old-received-PO delta case and the open-existing-PO update case. The remaining risk is still the existing-orders prompt, which can show broader purchase lines for the production order because it drops the routing filters before opening the list.

Necessity: AB#639381 is a clear Bug with strong repro steps. The created-order navigation fix is needed because users can otherwise be sent to the old received PO and must find the new PO manually. The round-4 test change is reasonable because it keeps the regression tests aligned with the repro flow.


[AI-PR-REVIEW] version=1 system=github pr=8811 round=4 by=alexei-dobriansky at=2026-07-10T11:03:57Z lastSha=cbd610534662965187f0222bccc90e39d3595527 suggestions=S1:disputed,S2:addressed parentRound=3

…tstanding Amount

- SalesDocTotalsSalesEntryUI: disable Foundation app area to prevent auto invoice discount calculation
- PurchDocTotalsSalesEntryUI: same fix for purchase doc totals tests
- ERMSalesPurchaseDocument (CA): use Amount Including VAT for customer GL entry ACY calculation
- SalesPurchaseReports (CA): use Outstanding Amount (includes tax) for report verification"
@github-actions github-actions Bot added the needs-approval Workflow runs require maintainer approval to start label Jul 13, 2026
@github-actions github-actions Bot removed the needs-approval Workflow runs require maintainer approval to start label Jul 13, 2026
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 5

Recommendation: Accept with Suggestions

What this PR does

The round-5 diff has one net AL product change in SubcPurchaseOrderCreator: it removes CreatedPurchaseHeader.MarkedOnly(false) before the early exit when no purchase header is marked.

This is safe on that path. After NoOfMarkedPurchaseOrders = 0, the procedure exits and does not use CreatedPurchaseHeader again. The next normal creation call resets CreatedPurchaseHeader, disables MarkedOnly, and clears marks before reuse. The two CA/NA test-fix commits cancel each other out; the clean three-dot diff since round 4 contains only this subcontracting file change.

Status of previous suggestions
ID Title Status Author response
S1 Scope existing order list filters Disputed / open Previous response says S1 is out of scope. No new reply or code change after round 4 changes this.
S2 Protect direct public callers Addressed Round 2 added XML documentation for the public method contract. The round-5 change does not change that contract.
New observations (commits since round 4)

None. Commit cd26c516 changes CA/NA legacy tests, and commit 412ff88f reverts those same changes, so they are net-zero. Commit e024f649 only removes an unnecessary MarkedOnly(false) call on an early-exit path and does not introduce a new functional issue.

Risk assessment and necessity

Risk: The round-5 product change is very small and only affects the no-marked-header early-exit path in the created-purchase-order display flow. It does not change the successful path that opens the marked purchase order or list. The remaining risk is still the existing-orders prompt, which can show broader purchase lines for the production order because it drops the routing filters before opening the list.

Necessity: AB#639381 is a Bug with clear repro steps and an AI repro score of 9/10. The main created-order navigation fix is needed because users can otherwise be sent to the old received PO and must find the new PO manually. The round-5 cleanup is reasonable because resetting MarkedOnly before an immediate exit has no useful effect on the traced path.


[AI-PR-REVIEW] version=1 system=github pr=8811 round=5 by=alexei-dobriansky at=2026-07-13T11:05:03Z lastSha=412ff88fbced9caea2ceb5cb7188f46bf058eb3a suggestions=S1:disputed,S2:addressed parentRound=4

Copilot AI requested a review from a team July 14, 2026 06:52
@microsoft microsoft deleted a comment from Copilot AI Jul 14, 2026
@microsoft microsoft deleted a comment from Copilot AI Jul 14, 2026
@6CRIPT 6CRIPT closed this Jul 14, 2026
auto-merge was automatically disabled July 14, 2026 07:03

Pull request was closed

@6CRIPT 6CRIPT reopened this Jul 14, 2026
@6CRIPT 6CRIPT force-pushed the bugs/639381-subcontracting-order-opens-old-purchase-order branch from 18b61c6 to 785995f Compare July 14, 2026 07:03
@6CRIPT 6CRIPT closed this Jul 14, 2026
@6CRIPT 6CRIPT changed the title [Subcontracting] Fix subcontracting order opening wrong purchase order after creation [Closed][Subcontracting] Fix subcontracting order opening wrong purchase order after creation Jul 14, 2026
PurchaseLine.SetRange("Routing Reference No.", ProdOrderRoutingLine."Routing Reference No.");
PurchaseLine.SetRange("Operation No.", ProdOrderRoutingLine."Operation No.");
PurchaseLine.SetRange("Planning Flexibility", "Reservation Planning Flexibility"::Unlimited);
PurchaseLine.SetRange("Quantity Received", 0);

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

In MarkNewlyCreatedSubcPurchaseOrder (SubcPurchaseOrderCreator.Codeunit.al), when Carry Out updates an existing open purchase order instead of creating a new one (MarkedPurchaseOrderNos.Count() = 0 after the first pass), the fallback loop marks every purchase line still matching FilterSubcPurchaseLineForRoutingLine as 'affected', not just the one order Carry Out actually touched.

If more than one open, unreceived purchase order already matches that exact routing line (same Prod. Order No./Line No./Routing No./Operation No., Planning Flexibility = Unlimited, Quantity Received = 0) -- e.g. a user previously split the order manually -- all of them get Marked, and ShowCreatedPurchaseOrder will subsequently open/list orders the current Carry Out run did not modify. Recommend narrowing the fallback to the specific document Carry Out changed (for example by diffing quantities/dates against a snapshot taken in CollectExistingSubcPurchaseOrderNos) rather than marking every remaining filter match.

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

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 SCM GitHub request for SCM area Subcontracting Subcontracting related activities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants