5032

Assemble to Stock: Post the Kit and Report What It Consumed

Transactions
Medium
Pro
assembly
assembly-bom
item-ledger-entry
partial-posting
inventory-costing

Assemble to Stock: Post the Kit and Report What It Consumed

The warehouse builds gift kits all day: two bottles and three glasses go into one box, and the box is what the webshop sells. Most mornings the team posts only part of an order — a component ran short, or the pallet is only half packed — and finance still wants a truthful line for every posting: how many kits actually went into stock, and what came out of the component bins to make them.

Your codeunit builds the assembly order from the item's assembly BOM, posts it, and then reads the answer back out of the inventory ledger — where the truth about a partial post lives, and where the order header cannot lie to you.

Requirements

Implement the codeunit "Assembly Kit Mgt." with exactly these four procedures — the grading tests bind to every name below character for character:

procedure PostAssemblyOrder(ParentItemNo: Code[20]; OrderQuantity: Decimal; QuantityToAssemble: Decimal; PostingDate: Date): Code[20]
procedure GetOutputQuantity(PostedAssemblyNo: Code[20]): Decimal
procedure GetOutputCost(PostedAssemblyNo: Code[20]): Decimal
procedure GetConsumption(PostedAssemblyNo: Code[20]; var ConsumedQuantity: Dictionary of [Code[20], Decimal]; var ConsumedCost: Dictionary of [Code[20], Decimal])

Rules for PostAssemblyOrder:

  1. Create an assembly order for OrderQuantity units of ParentItemNo whose component lines come from that item's assembly BOM — one line per BOM component, each for OrderQuantity × the component's "Quantity per".
  2. Post QuantityToAssemble units of it, on PostingDate. QuantityToAssemble is at least 1 and never more than OrderQuantity. The whole flow must run silently: the grading tests declare no UI handlers, so any Confirm or Message your code triggers fails the test as unhandled UI. Two of them lurk in the order header — validating any of its three dates ("Starting Date", "Ending Date", "Due Date") asks whether to move the other two along with it, and a component line that falls due before the work date makes the header show a warning message. Keep the header's dates on PostingDate; the component lines take their due date from the header's "Starting Date" the moment they are created, so the dates must be in place before the lines are.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 14 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade