Skip to content

Bug 648535: Reprice subcontracting lines after scheduling - #11292

Merged
Chethan Thopaiah (ChethanT) merged 11 commits into
mainfrom
bugs/648535-followup-202609091030
Sep 22, 2026
Merged

Chethan Thopaiah (ChethanT) merged 11 commits into
mainfrom
bugs/648535-followup-202609091030

Conversation

@ChethanT

@ChethanT Chethan Thopaiah (ChethanT) commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

What & why

Follow-up to #10917 and AB#648535.

The original date-effective repricing fix exposed four uncovered paths:

  • carry-out could replace a calculated time/UOM worksheet cost with the raw routing rate when no price matched;
  • date edits on released subcontracting purchase orders could fail through line-discount validation's open-status check;
  • carry-out could overwrite a manually entered worksheet cost;
  • lead-time-only rescheduling could change Order Date without changing Planned Receipt Date and therefore skip repricing.

This change detects whether the transferred worksheet value is the automatically selected price before repricing it, uses the standard subcontracting worksheet cost formula as the no-price fallback, skips financial repricing for non-open purchase orders, and keys planned-date repricing on the resulting Order Date.

Coverage

Adds regression tests for:

  • no matching price with a time-based routing multiplier;
  • manual worksheet Direct Unit Cost preservation;
  • Planned Receipt Date and Order Date edits on a released subcontracting purchase order;
  • lead-time-only Order Date movement across a price boundary.

Backports

The same correction is applied to:

Validation

  • git diff --check passes.
  • Local compile/test execution is blocked because CoreXT initialization cannot write its generated package state under the current sandbox policy. Global AL symbol download is also unavailable. The PR build is the executable validation gate; no local runtime pass is claimed.

Preserve manual and calculated worksheet costs, retain released-order scheduling, and reprice lead-time-only date changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 255f96a1-3a67-418c-9b69-ca50ae31e5b0

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.

🔵 Needs a closer look

It changes core subcontracting pricing/scheduling behavior in multiple event-driven paths where subtle functional regressions are hard to rule out without a full CI run.

Pull request overview

This PR is a follow-up to #10917 / AB#648535 to address remaining subcontracting repricing regressions around carry-out cost preservation, released-order date edits, and lead-time-only rescheduling.

Changes:

  • Reprices subcontracting lines based on resulting Order Date (not Planned Receipt Date) and skips repricing when the purchase header is not Open.
  • Refines no-price fallback to use the standard subcontracting worksheet cost formula, and avoids overwriting manually entered worksheet Direct Unit Cost during carry-out.
  • Adds regression tests covering the newly fixed edge paths (no matching price, manual overrides, released-order date edits, lead-time-only boundary crossing).
File summaries
File Description
src/Apps/W1/Subcontracting/Test/Tests/SubcPricingTest.Codeunit.al Adds regression tests for the uncovered subcontracting repricing/carry-out scenarios.
src/Apps/W1/Subcontracting/App/src/Purchase/SubcPurchaseLineExt.Codeunit.al Reprices on Order Date changes and bypasses repricing for non-open purchase headers to preserve released-order scheduling behavior.
src/Apps/W1/Subcontracting/App/src/Purchase/SubcPriceManagement.Codeunit.al Splits price-list lookup from fallback cost calculation and uses worksheet-consistent fallback logic when no price matches.
src/Apps/W1/Subcontracting/App/src/Manufacturing/SubcReqWkshMakeOrd.Codeunit.al Avoids repricing during carry-out unless the transferred worksheet value matches the automatically selected price-list value.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Apps/W1/Subcontracting/App/src/Purchase/SubcPriceManagement.Codeunit.al Outdated
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 1

Recommendation: Request Changes

What this PR does

This change tightens subcontracting repricing so carry-out keeps manual or calculated worksheet costs when it should, avoids repricing released purchase orders, and reprices when Order Date changes even if Planned Receipt Date does not. The pricing logic is now split so callers can detect whether the current worksheet value came from the automatic price lookup before replacing it.

The fix matches the main code paths. The requisition-to-purchase event fires after manufacturing fields are transferred and before the line is inserted, so it has the routing context needed to reprice. The purchase-line date logic assigns Order Date directly from Planned Receipt Date in some paths, so gating the Planned Receipt Date subscriber on the resulting Order Date is the right shape. The added tests cover the reported regressions, but a new CodeCop warning currently fails the W1 build.

Problem-solution fit

Fit: Partial

The reported regressions are about keeping subcontracting Direct Unit Cost aligned with the correct pricing date without overwriting intentional worksheet or released-order values. The functional diff addresses those paths directly, but the PR cannot pass its required build until the new analyzer warning is fixed.

Suggestions

S1 (🔴 High): Fix the new CodeCop warning that fails the build
The new NewLeadTime declaration is after Date variables, but CodeCop requires DateFormula variables before the remaining variable types. CI reports this as a new AA0021 warning at line 394, and the W1 build fails because new warnings fail the PR. Move NewLeadTime before the Decimal and Date variables so the build can pass.

Risk assessment and necessity

Risk: Direct Unit Cost drives subcontracting purchase costs, so wrong repricing can affect purchasing amounts. The implementation is narrow: it stays in the Subcontracting app, uses existing price logic, skips temporary and upgrade contexts, and avoids changing released-order financial terms. The current concrete blocker is merge readiness because the PR introduces a warning that fails the W1 build.

Necessity: The functional change is justified. Without it, subcontracting purchase lines can keep a cost selected for the wrong effective date, or a follow-up reprice can overwrite a valid worksheet value. The scope is focused on those regressions, but the build-blocking declaration order must be corrected before merge.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=11292 round=1 by=alexei-dobriansky at=2026-09-10T00:18:57.9626275Z lastSha=c6acb74ab120e9415ce860a5b15fba9f2abeb06b reviewKey=60d008a5b5ca6b99457fe55a9b3177c69ec87b7af8c53167079b774ca7c97cce suggestions=S1@f03922c3

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 255f96a1-3a67-418c-9b69-ca50ae31e5b0
Comment thread src/Apps/W1/Subcontracting/App/src/Purchase/SubcPriceManagement.Codeunit.al Outdated
Comment thread src/Apps/W1/Subcontracting/App/src/Purchase/SubcPriceManagement.Codeunit.al Outdated
@ChethanT Chethan Thopaiah (ChethanT) changed the title Fix subcontracting repricing regressions Bug 648535: Reprice subcontracting lines after scheduling Sep 10, 2026
Guard zero expected output, avoid unnecessary record loads, and cover direct no-price fallback calculations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 255f96a1-3a67-418c-9b69-ca50ae31e5b0

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.

🟡 Changes recommended

There is a confirmed pricing-path correctness issue in TryGetSubcPriceListCostForPurchLine (treating zero as a successful lookup) and a non-deterministic test record reload via PurchaseLine.Find() that should be fixed before merge.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/Apps/W1/Subcontracting/Test/Tests/SubcPricingTest.Codeunit.al:421

  • PurchaseLine.Find() here runs without filters and can reposition the record to an unrelated purchase line, making the test non-deterministic when other purchase lines exist in the test company. Reload the specific line by primary key after releasing the header.
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

@github-actions

Copy link
Copy Markdown
Contributor

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

In OnInsertPurchOrderLineOnAfterTransferFromReqLineToPurchLine, the guard if PurchOrderLine."Direct Unit Cost" <> ReqLineDatePriceListCost then exit; uses exact Decimal equality to decide whether the requisition line's cost was price-list-derived (and therefore safe to recompute for the purchase line) versus manually overridden (and therefore must be preserved). ReqLineDatePriceListCost is recomputed from the purchase line's own quantity/UOM/vendor context via TryGetSubcPriceListCostForPurchLine, while the compared value already sitting on PurchOrderLine."Direct Unit Cost" was computed earlier from the requisition line's context (via the analogous requisition-line pricing procedure) and merely copied across during the transfer. If quantity, UOM-conversion factors, or rounding differ even slightly between the requisition-line and purchase-line contexts, this exact equality check can produce a false 'looks manually overridden' result and silently skip the intended repricing, or vice versa. Consider comparing with a small tolerance, or restructuring to reuse the exact same computed value instead of re-deriving and comparing.

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

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

@github-actions

Copy link
Copy Markdown
Contributor

$\textbf{🟡\ Medium\ Severity\ —\ Error\ Handling}$

TryGetSubcPriceListCostForPurchLine() returns false both for the expected 'no matching price list' case and for the unexpected case where TryFindProdOrderRtngLine() cannot find the production routing line. This new early exit treats both outcomes as benign, so a missing routing line is silently swallowed here instead of surfacing as a defect the way GetSubcPriceForPurchLine() still does on its fallback path (which calls the non-Try GetProdOrderRtngLine() that raises an error via FindFirst() if no routing line exists). Consider distinguishing the two failure causes, or raising an explicit error when the routing line is missing, so a data/setup problem is not masked as 'no applicable price'.

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

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 255f96a1-3a67-418c-9b69-ca50ae31e5b0

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.

🔵 Needs a closer look

One newly added test has a setup bug (Work Center Direct Unit Cost is created as 0) that can make its assertions unreliable and cause test failures unrelated to the intended behavior.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/Apps/W1/Subcontracting/Test/Tests/SubcPricingTest.Codeunit.al:253

  • In NoMatchPriceListPreservesCalculatedWorksheetCostForTimeBasedRouting, the Work Center is created via CreateSubcontractingItemWithSingleOperationRouting, which calls LibraryMfgManagement.CreateWorkCenterWithCalendar(WorkCenter, 0) (Direct Unit Cost = 0). With a zero routing rate, both RoutingRate and the calculated worksheet cost can end up 0, making Assert.AreNotEqual(RoutingRate, CalculatedWorksheetCost) unreliable and potentially failing the test for the wrong reason. Set a nonzero Work Center Direct Unit Cost as part of this test’s setup so the routing multiplier produces a distinguishable worksheet cost.
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Comment thread src/Apps/W1/Subcontracting/App/src/Manufacturing/SubcReqWkshMakeOrd.Codeunit.al Outdated
@github-actions

Copy link
Copy Markdown
Contributor

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

This test hand-rolls Requisition Wksh. Name setup with Init/Validate/Insert even though the Subcontracting test libraries already provide fixture helpers for that record. Reusing the library helper would keep the worksheet fixture aligned with future schema changes instead of duplicating record-construction logic inside the test.

Knowledge:

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

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

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.

🟡 Changes recommended

Subc price fallback logic risks runtime/incorrect behavior due to partial-record SetLoadFields use and a possible divide-by-zero in minimum-amount pricing.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread src/Apps/W1/Subcontracting/App/src/Purchase/SubcPriceManagement.Codeunit.al Outdated
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 3

Recommendation: Request Changes

What this PR does

Since round 2, the change now compares the worksheet value with the requisition line's own automatic cost before repricing the final purchase line. It also stops the requisition-line minimum-quantity miss from writing an automatic zero and adds tests for the two previously open paths.

The functional changes fit the reported pricing problem: the final purchase-line date is used when the worksheet value is automatic, and intentional worksheet values are preserved. The remaining issue is merge readiness: the current build fails on a new analyzer warning in the added test helper.

Status of previous suggestions
ID Title Status Author response
S1 Fix the new CodeCop warning that fails the build Addressed Declaration order remains fixed.
S2 Do not skip final-date pricing when the requisition date has no price Addressed The new automatic-cost comparison uses the requisition line's pricing context, then reprices the scheduled purchase line.
S3 Respect the minimum-quantity lookup result for requisition lines Addressed The requisition-line caller now consumes the Boolean result and exits before writing zero when no tier applies.
New observations (commits since round 2)

S4 (🔴 High): Rename helper parameter to unblock CI
The current build fails because this new helper parameter has the same name as the codeunit global variable UnitCostCalculation. Rename the parameter and update its use so the new AA0244 warning is removed.

Risk assessment and necessity

Risk: Direct Unit Cost on subcontracting purchase lines affects purchase costs, so the functional area is money-sensitive. The code change is narrow and the event timing was verified against the publisher side, but the PR cannot merge while the current build reports a new warning.

Necessity: The change is needed because generated subcontracting purchase lines can be backward-scheduled to an Order Date different from the first price lookup date. Without it, users can get the wrong price or must manually correct generated purchase costs.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=11292 round=3 by=alexei-dobriansky at=2026-09-11T09:35:48.529Z lastSha=57e15f71cfceb2c78ee329d04e4557386b3de5bc reviewKey=f4d9a1621117ffa0f183da78e463338157f34ada0227071777cef4a40ec4fd5f suggestions=S1@f03922c3:addressed,S2@d13a1cdd:addressed,S3@94f8b60d:addressed,S4@76c46cf5:new parentRound=2

- Guard GetPriceByUOM against divide-by-zero when PriceListQty is 0
  while a Minimum Amount is configured.
- Extend SetLoadFields on the fallback Prod. Order Routing Line so
  Type, Unit Cost Calculation, Direct Unit Cost, Expected Operation
  Cost Amt. and Expected Capacity Ovhd. Cost are available when the
  no-price-list fallback path runs (previously only Standard Task
  Code was loaded, which could error or silently zero out on
  fallback).
- Add SetLoadFields to the Prod. Order Line lookup in
  GetNonPriceListDirectCost to avoid materializing unused columns.
- Avoid computing the subcontracting price twice per requisition line
  during Carry Out / Make Order: GetAutomaticSubcCostForReqLine now
  has an overload that returns the Prod. Order Routing Line it looked
  up, and GetSubcPriceForPurchLine accepts that record to skip a
  redundant Prod. Order Routing Line lookup for the same operation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 4

Recommendation: Request Changes

What this PR does

The latest commit reuses the production routing line between the automatic worksheet-cost check and final purchase-line repricing, adds load-field declarations, and avoids a minimum-amount division when the price quantity is zero. These changes are consistent with the existing pricing fix, but the round 3 analyzer blocker is still present in the test helper.

Status of previous suggestions
ID Title Status Author response
S1 Fix the new CodeCop warning that fails the build Addressed The original declaration-order warning remains fixed.
S2 Do not skip final-date pricing when the requisition date has no price Addressed The final-date pricing path remains in place.
S3 Respect the minimum-quantity lookup result for requisition lines Addressed The minimum-quantity fallback remains corrected.
S4 Rename helper parameter to unblock CI Not addressed CreateNoPriceSubcontractingPurchaseLine still declares a parameter named UnitCostCalculation, which conflicts with the codeunit global.
New observations (commits since round 3)

None. The routing-line reuse and zero-quantity guard do not introduce a new review issue.

Risk assessment and necessity

Risk: Subcontracting Direct Unit Cost affects purchase costs, so the functional path is money-sensitive. The latest product changes are targeted, but the PR still cannot pass the required analyzer gate while the parameter-name warning remains.

Necessity: The repricing change is needed to select the correct effective-date cost without overwriting manual values. Rename the helper parameter so the tested fix can pass validation and merge.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=11292 round=4 by=alexei-dobriansky at=2026-09-17T12:47:00Z lastSha=d538bdcd94cf47a11631cad7721765c0322938f9 reviewKey=5974d45b64a4b11e212f1c8f371ea2e2731cfed55f453aaddb457690d38a26e7 suggestions=S1@f03922c3:addressed,S2@d13a1cdd:addressed,S3@94f8b60d:addressed,S4@76c46cf5:notaddressed parentRound=3

Chethan Thopaiah (ChethanT) added a commit that referenced this pull request Sep 17, 2026
…ling (#10917) (#11198)

## Backport of #10917 to `releases/29.0`

Backports [#10917](#10917) —
*Bug 648535: Reprice subcontracting lines after scheduling* — to the
`releases/29.0` release branch.

### What & why
Subcontracting purchase lines were priced before backward scheduling had
finalized the purchase-line Order Date and before routing context was
transferred from the requisition line, so a subcontractor price valid
for the purchase-header date could be selected instead of the price
valid for the final purchase-line date.

The review follow-up also:
- preserves the worksheet's calculated Units/Time cost when no
subcontractor price matches;
- preserves manually overridden worksheet costs during carry-out;
- keeps date scheduling editable on released purchase orders without
changing financial terms;
- reprices lead-time-only changes when the resulting Order Date crosses
a price boundary.

### Source
- Source PR: #10917
- Source squash-merge commit: `049258b463302e36649979d241a6f122c7eb87c0`
- Original backport commit: `c1924162a`
- Corrective follow-up commit: `327c1d82c5`
- Main follow-up PR: #11292
- ADO:
[AB#648535](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/648535)

### Cherry-pick / conflict resolution
The product changes applied cleanly. The test file conflicted because
the release branch predates the `Subc. Management Library` helper
refactor. Only the relevant regression tests were applied, using
equivalent local helper procedures already required by this backport. No
unrelated `main` tests were introduced. The resolution is identical to
the `releases/29.x` backport.

### Validation
- Static verification: no conflict markers or duplicate procedures; `git
diff --check` passes.
- Four corrective regressions cover no-price fallback, manual worksheet
overrides, released-order date edits, and lead-time-only Order Date
changes.
- Full AL compile and test execution are deferred to the AL-Go PR build
because local symbol packages are unavailable and sandbox policy blocks
CoreXT package-state initialization.

⚠️ Do not merge until the AL-Go PR build passes. **Not** auto-merged.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 255f96a1-3a67-418c-9b69-ca50ae31e5b0
Chethan Thopaiah (ChethanT) added a commit that referenced this pull request Sep 17, 2026
…ling (#10917) (#11197)

## Backport of #10917 to `releases/29.x`

Backports [#10917](#10917) —
*Bug 648535: Reprice subcontracting lines after scheduling* — to the
`releases/29.x` release branch.

### What & why
Subcontracting purchase lines were priced before backward scheduling had
finalized the purchase-line Order Date and before routing context was
transferred from the requisition line, so a subcontractor price valid
for the purchase-header date could be selected instead of the price
valid for the final purchase-line date.

The review follow-up also:
- preserves the worksheet's calculated Units/Time cost when no
subcontractor price matches;
- preserves manually overridden worksheet costs during carry-out;
- keeps date scheduling editable on released purchase orders without
changing financial terms;
- reprices lead-time-only changes when the resulting Order Date crosses
a price boundary.

### Source
- Source PR: #10917
- Source squash-merge commit: `049258b463302e36649979d241a6f122c7eb87c0`
- Original backport commit: `6a3802a0a`
- Corrective follow-up commit: `02e7a0dba2`
- Main follow-up PR: #11292
- ADO:
[AB#648535](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/648535)

### Cherry-pick / conflict resolution
The product changes applied cleanly. The test file conflicted because
the release branch predates the `Subc. Management Library` helper
refactor. Only the relevant regression tests were applied, using
equivalent local helper procedures already required by this backport. No
unrelated `main` tests were introduced.

### Validation
- Static verification: no conflict markers or duplicate procedures; `git
diff --check` passes.
- Four corrective regressions cover no-price fallback, manual worksheet
overrides, released-order date edits, and lead-time-only Order Date
changes.
- Full AL compile and test execution are deferred to the AL-Go PR build
because local symbol packages are unavailable and sandbox policy blocks
CoreXT package-state initialization.

⚠️ Do not merge until the AL-Go PR build passes. **Not** auto-merged.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 255f96a1-3a67-418c-9b69-ca50ae31e5b0
- Rename UnitCostCalculation parameter to UnitCostCalculationType in
  CreateNoPriceSubcontractingPurchaseLine to avoid shadowing the codeunit's
  global variable of the same name (AA0244).
- Reorder var declarations in OnInsertPurchOrderLineOnAfterTransferFromReqLineToPurchLine
  so the Record var precedes the Codeunit var, per AA0021 ordering rules.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 5

Recommendation: Accept

What this PR does

The latest commit fixes the remaining analyzer warnings by renaming the conflicting test-helper parameter and ordering the local variables correctly. These changes are behavior-neutral, preserve the subcontracting pricing fix, and allow the validated code to pass the required build and analyzer checks.

Status of previous suggestions
ID Title Status Author response
S1 Fix the new CodeCop warning that fails the build Addressed The declaration-order warning remains fixed.
S2 Do not skip final-date pricing when the requisition date has no price Addressed The final-date pricing path remains in place.
S3 Respect the minimum-quantity lookup result for requisition lines Addressed The minimum-quantity fallback remains corrected.
S4 Rename helper parameter to unblock CI Addressed The helper parameter was renamed, and the analyzer checks now pass.
New observations (commits since round 4)

None - the latest commit only resolves analyzer warnings and introduces no behavioral change.

Risk assessment and necessity

Risk: Subcontracting Direct Unit Cost is financially sensitive, but the functional changes are targeted and covered by focused tests. The latest commit changes only names and declaration order, and all current build and analyzer checks pass.

Necessity: The pricing changes are needed to use the final scheduled date while preserving manual and fallback costs. The latest cleanup is needed to clear the analyzer gate and make the PR mergeable.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=11292 round=5 by=alexei-dobriansky at=2026-09-17T18:16:56Z lastSha=5358ef1271e8ab65b2f8ed87094b9e52f66cd5bb reviewKey=cbf2070a8dd0b017a054e0f046c21192d26ed1339e0aac19dba7beb2eee7d793 suggestions=S1@f03922c3:addressed,S2@d13a1cdd:addressed,S3@94f8b60d:addressed,S4@76c46cf5:addressed parentRound=4

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.

The final-date repricing flow and no-price fallback formulas are well covered, but requisition-line recalculation can retain stale price-list metadata when no minimum-quantity tier applies. This is a correctness regression already fixed in the merged 29.x backport. Please clear that state on the no-match path and add focused regression coverage.

…ForReqLine early exit

When GetPriceByUOM finds no applicable price tier, GetSubcPriceForReqLine now
clears Subc. Pricelist Cost, Subc. UoM for Pricelist, and both conversion
ratios (restoring them to 1) instead of leaving stale values from a prior
calculation on the requisition line. Adds regression coverage that starts
with populated price-list metadata, recalculates with no applicable tier,
and verifies all four fields are reset.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…SubcCostForReqLine

Adds SetLoadFields (Standard Task Code, Type, Unit Cost Calculation, Direct
Unit Cost, Expected Operation Cost Amt., Expected Capacity Ovhd. Cost) before
fetching the routing line, matching the equivalent restriction already
applied in the sibling TryGetSubcPriceListCostForPurchLine, avoiding an
inconsistent full-row load on this per-line hot path. Found by local AL
review (al-performance-review).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 6

Recommendation: Request Changes

What this PR does

The latest commits clear stale price-list fields when no minimum-quantity tier applies and restrict the routing-line fields loaded by the automatic-cost calculation. These product-code changes preserve the earlier pricing corrections, but the new regression test changes a primary-key field with Modify(true) and will fail before it exercises the recalculation.

Status of previous suggestions
ID Title Status Author response
S1 Fix the new CodeCop warning that fails the build Addressed The declaration-order warning remains fixed.
S2 Do not skip final-date pricing when the requisition date has no price Addressed The final-date pricing path remains in place.
S3 Respect the minimum-quantity lookup result for requisition lines Addressed The minimum-quantity fallback remains corrected.
S4 Rename helper parameter to unblock CI Addressed The helper parameter remains renamed.
New observations (commits since round 5)

S5 (🔴 High): Recreate the price tier with the new key
Minimum Quantity is part of the primary key, so Modify(true) cannot persist this key change. Rename or recreate the price record so the test reaches the recalculation and assertions.

Risk assessment and necessity

Risk: Subcontracting Direct Unit Cost affects purchase costs, so the stale-state correction needs executable regression coverage. The product changes are narrow, but the new test currently stops while changing the price record key and therefore does not validate the corrected path.

Necessity: Clearing stale price-list state is needed when recalculation no longer finds an applicable quantity tier. Fix the test setup so the financially sensitive fallback behavior is validated before merge.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=11292 round=6 by=alexei-dobriansky at=2026-09-18T12:26:22.9103615Z lastSha=5fcf2f85a0bb70cecf9712c987ca4f0d992dee65 reviewKey=34ce421e74dc4572a45e1fdf642b564f0d0c47e5a24d789ba30f9e942ceb100b suggestions=S1@f03922c3:addressed,S2@d13a1cdd:addressed,S3@94f8b60d:addressed,S4@76c46cf5:addressed,S5@c24ef376:new parentRound=5

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.

The final pricing flow correctly preserves manual worksheet overrides while repricing automatically calculated costs against the resulting purchase-line Order Date. The no-price fallback matches the standard unit/time calculations, guards zero expected output, distinguishes an intentional zero price from a missing tier, and resets stale requisition price-list metadata. Released-order date edits retain their financial terms. The regression coverage exercises each changed path. No blocking issues found.

Use Record.Rename when changing Minimum Quantity because it is part of the Subcontractor Price primary key.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 7

Recommendation: Accept

What this PR does

The latest commit fixes the regression test setup by renaming the subcontractor price tier when changing Minimum Quantity, instead of trying to modify a primary-key field. That addresses the remaining blocker from the previous round, so the test can reach the recalculation and assertion path.

The product changes still match the reported bug: subcontracting purchase lines are repriced from the final line Order Date, no-price fallback uses the standard calculated subcontracting cost, released date edits avoid financial repricing, manual worksheet costs are preserved, and lead-time-only Order Date shifts are covered.

Status of previous suggestions
ID Title Status Author response
S1 Fix the new CodeCop warning that fails the build Addressed The declaration-order warning remains fixed.
S2 Do not skip final-date pricing when the requisition date has no price Addressed The final-date pricing path remains in place.
S3 Respect the minimum-quantity lookup result for requisition lines Addressed The minimum-quantity fallback remains corrected.
S4 Rename helper parameter to unblock CI Addressed The helper parameter remains renamed.
S5 Recreate the price tier with the new key Addressed The test now uses Rename when changing the Minimum Quantity key.
New observations (commits since round 6)

None - the latest commit only addresses the previous test setup blocker.

Risk assessment and necessity

Risk: Subcontracting Direct Unit Cost affects purchase costs, so the pricing paths remain financially sensitive. The latest commit only changes test setup, not runtime behavior, and it removes the remaining blocker by using the proper key-change operation.

Necessity: The latest change is necessary because the regression test must reach the recalculation path instead of failing while changing a primary-key field. The overall fix remains needed to price subcontracting purchase lines from the final Order Date and to preserve correct fallback and manual-cost behavior.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=11292 round=7 by=alexei-dobriansky at=2026-09-21T12:22:46.0488495Z lastSha=9e5ba15e7173b615c98ce773981b8d42b271c276 reviewKey=8623686efbcef6169dc3b4ef3cd656704112a51ac95e356761c374fddafa7d08 suggestions=S1@f03922c3:addressed,S2@d13a1cdd:addressed,S3@94f8b60d:addressed,S4@76c46cf5:addressed,S5@c24ef376:addressed parentRound=6

@ChethanT
Chethan Thopaiah (ChethanT) added this pull request to the merge queue Sep 22, 2026
Merged via the queue into main with commit 8b8571b Sep 22, 2026
171 of 172 checks passed
@ChethanT
Chethan Thopaiah (ChethanT) deleted the bugs/648535-followup-202609091030 branch September 22, 2026 10:41
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 Team: SCM GitHub request for SCM area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants