Skip to content

[Subcontracting] Use Base Unit of Measure for WIP Ledger Entries#8585

Open
stevengrossGOB wants to merge 3 commits into
microsoft:mainfrom
GOB-Software-Systeme-DevOps:w/grosss/636809_ChangeToBaseUOM
Open

[Subcontracting] Use Base Unit of Measure for WIP Ledger Entries#8585
stevengrossGOB wants to merge 3 commits into
microsoft:mainfrom
GOB-Software-Systeme-DevOps:w/grosss/636809_ChangeToBaseUOM

Conversation

@stevengrossGOB

@stevengrossGOB stevengrossGOB commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What & why

  • Refactor fields in various codeunits and pages to replace "Unit of Measure Code" with "Base Unit of Measure".
  • Implement event subscriber to set quantity per unit of measure to zero for transfer WIP items.
  • Enhance test coverage for WIP transfer to ensure base unit of measure is used correctly.

Linked work

Internal workitem: AB#636809

How I validated this

  • I read the full diff and it contains only changes I intended.
  • I built the affected app(s) locally with no new analyzer warnings.
  • I ran the change in Business Central and confirmed it behaves as expected.
  • I added or updated tests for the new behavior, or explained below why none are needed.

What I tested and the outcome (required — be specific: scenarios, commands, screenshots for UI changes)

-Manually changed document Unit of Measure - checked if Base Unit of Measure is set correctly

  • Automated Tests

- Refactor fields in various codeunits and pages to replace "Unit of Measure Code" with "Base Unit of Measure".
- Implement event subscriber to set quantity per unit of measure to zero for transfer WIP items.
- Enhance test coverage for WIP transfer to ensure base unit of measure is used correctly.
@stevengrossGOB stevengrossGOB requested a review from a team as a code owner June 11, 2026 14:47
@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 11, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Jun 11, 2026
@alexei-dobriansky alexei-dobriansky enabled auto-merge (squash) June 11, 2026 15:13
WIPLedgerEntry."In Transit" := InTransit;
WIPLedgerEntry."Unit of Measure Code" := ProdOrderLine."Unit of Measure Code";
Item.SetLoadFields("Base Unit of Measure");
if Item.Get(ItemNo) 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\ —\ Performance} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

Incomplete WIP entry when Item.Get fails in library

The same silent-skip pattern used in production code is repeated in CreateWIPLedgerEntry: if Item.Get(ItemNo) fails, WIPLedgerEntry."Base Unit of Measure" is never set and the entry is inserted with a blank value. This can cause tests to pass even when the UOM field is empty, giving false confidence.

Recommendation:

  • Either assert that the item must exist (using Item.Get(ItemNo) with a direct error on failure) or use TestField after the insert to verify the field was populated, ensuring the test library catches missing items early.
Suggested change
if Item.Get(ItemNo) then
Item.SetLoadFields("Base Unit of Measure");
Item.Get(ItemNo);
WIPLedgerEntry."Base Unit of Measure" := Item."Base Unit of Measure";
WIPLedgerEntry.Insert();

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

@github-actions

Copy link
Copy Markdown
Contributor

$\textbf{🟡\ Medium\ Severity\ —\ Performance} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

Stale cache returned when Item.Get fails

GetItemBaseUnitOfMeasure only calls Item.Get(ItemNo) when ItemNo <> Item."No.". If Item.Get() fails (item not found), the function skips the assignment but proceeds to exit(Item."Base Unit of Measure"), which returns the previously loaded item's base UOM — silently returning a wrong value rather than an empty code.

Recommendation:

  • Guard the exit against a failed Get call by checking the return value and returning an empty string (or erroring) when the item is not found.
local procedure GetItemBaseUnitOfMeasure(ItemNo: Code[20]): Code[10]
begin
    if ItemNo = '' then
        exit('');
    Item.SetLoadFields("Base Unit of Measure");
    if ItemNo <> Item."No." then
        if not Item.Get(ItemNo) then
            exit('');
    exit(Item."Base Unit of Measure");
end;

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

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

@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 1

Recommendation: Accept with Suggestions

What this PR does

This makes Subcontractor WIP Ledger Entries record the item's base unit of measure: field 8 on the table is renamed from "Unit of Measure Code" to "Base Unit of Measure", the two WIP pages and the posting codeunit are updated to match, and AssignFieldsFromTransferLine now reads the base UOM from the item rather than copying the (possibly alternative) transfer-line UOM. The change is sound because the entry only ever stores Quantity (Base), so previously labelling that quantity with the document UOM was inconsistent; there is no quantity recalculation or rounding involved, only the UOM label. I confirmed every in-app reference to the old field name was updated (pages, posting codeunit, adjustment buffer page, test library) and that the reports declaring this record do not touch the field. The added test exercises a genuine non-base UOM (6 base units per unit) and asserts the resulting WIP ledger entries carry the item base UOM, which is the right assertion at the right point.

Suggestions

S1 - Reconcile description with the actual diff
The PR description lists "Implement event subscriber to set quantity per unit of measure to zero for transfer WIP items", but no such subscriber appears in the diff and this table has no qty-per-UOM field. Please confirm nothing was dropped and update the description so the change set is accurately documented.

S2 - Fail closed when the item lookup fails
In AssignFieldsFromTransferLine, Base Unit of Measure is only set when Item.Get(TransferLine."Item No.") succeeds, so a missing item silently leaves the field blank. Since a transfer line always references an existing item, consider a guaranteed Get (or clear error) so an unexpected lookup miss surfaces instead of writing an empty UOM.

Risk assessment and necessity

Risk: Low and contained to the Subcontracting WIP area (SubcontractorWIPLedgerEntry.Table.al, SubcTransferWIPPosting.Codeunit.al, the two WIP pages). The field keeps its id, type, and Item Unit of Measure table relation, and quantities are untouched, so no entry math changes. CI is green. The field rename is not a compatibility concern because this app is new and not yet released.

Necessity: Justified — recording an alternative document UOM next to a base quantity was misleading on the WIP ledger entry and its adjustment/display pages; aligning the stored UOM with the base quantity is the correct, minimal fix, and it is covered by a meaningful regression test.


[AI-PR-REVIEW] version=1 system=github pr=8585 round=1 by=alexei-dobriansky at=2026-06-11T15:20:00Z lastSha=1eb3e617cd961eb726808f36bd09063f36d6de64 suggestions=S1,S2

@alexei-dobriansky alexei-dobriansky self-assigned this Jun 11, 2026
@alexei-dobriansky alexei-dobriansky added the Subcontracting Subcontracting related activities label Jun 11, 2026
auto-merge was automatically disabled June 12, 2026 09:15

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 12, 2026
@alexei-dobriansky alexei-dobriansky enabled auto-merge (squash) June 12, 2026 11:15
[IntegrationEvent(false, false)]
local procedure OnBeforeInsertWIPLedgerEntry(var SubcontractorWIPLedgerEntry: Record "Subcontractor WIP Ledger Entry"; var WIPLedgEntryNo: Integer)
begin
end; No newline at end of file

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.

Suggested change
end;
end;
}

@github-actions github-actions Bot removed the needs-approval Workflow runs require maintainer approval to start label Jun 12, 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 From Fork Pull request is coming from a fork Linked Issue is linked to a Azure Boards work item Subcontracting Subcontracting related activities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Subcontracting] WIP Ledger Entries missing Quantity and UOM columns

4 participants