# Nesting & execution

How assembly BOMs are recursively expanded when a parent bill fires, with worked examples.

import Term from '~/components/Term.astro';
import { Aside } from '@astrojs/starlight/components';
import DocUpdated from '~/components/DocUpdated.astro';

In Assemblified, when a finished good's bill containing an assembly BOM (defining a
<Term def="sub-assembly">subassembly</Term>) fires, the assembly is **recursively expanded** into its own
components. Quantities multiply through each layer; <Term def="pre-assembled">pre-assembled stock</Term> at each
layer is consumed first.

This page walks through the expansion mechanics with worked examples.

## On this page

- Quantity multiplication through layers
- Pre-assembled drawdown at each layer
- A worked end-to-end example
- Waste percentage handling
- Loops, and why you cannot create one

## Quantity multiplication

A bill containing an assembly BOM carries a **quantity** on that reference. The assembly's own components are
then multiplied by `(parent quantity × reference quantity)`.

Example. Order 4 units of finished good B, where:
- B contains 2 × Assembly BOM S (the reference quantity is 2).

The expansion produces 4 × 2 = **8** of whatever is inside S, before any pre-assembled drawdown.

This compounds across layers. If S contains 3 × Assembly BOM T, and T contains 5 × Raw R, then:
- 4 units of B → 8 of S → 24 of T → 120 of R.

## Pre-assembled drawdown at each layer

At each layer of the recursion, the assembly's pre-assembled shelf is consumed before falling through to its
components.

Example. Same setup as above. S has 3 in pre-assembled stock.

```
Order 4 of B.
  Frame { B, multiplier=4 }:
    No B-level pre-assembled.
    Recurse into S edge with multiplier 4 × 2 = 8.
  
  Frame { S, multiplier=8 }:
    Consume from S's shelf: min(3, 8) = 3. Shelf → 0. Remainder = 5.
    Recurse into T edge with multiplier 5 × 3 = 15.
  
  Frame { T, multiplier=15 }:
    No T-level pre-assembled.
    Emit Raw R × (15 × 5) = 75.
```

Net effect: 75 of Raw R consumed, plus 3 of S's pre-assembled shelf. **Without** S's pre-assembled, you'd have consumed 24 of T (which would have consumed 120 of R). The shelf cut consumption by 60%.

<Aside type="note" title="A cut-off assembly stops the descent">
If an assembly BOM has [Only consume pre-assembled](/features/sub-assemblies/only-consume-preassembled/) on, the
recursion **stops at that node** for a sales order: the full remaining demand is taken from its pre-assembled
shelf (going negative if short) and the walk never descends into its components. In the example above, if S were
set that way, the order would consume 8 from S's shelf and *never* touch T or R.

A [per-location rule](/features/bill-of-materials/location-rules/) in **Disabled** or **Pre-assembled only** mode
produces exactly the same cut-off, but at one location only: at that location the assembly is a shelf, everywhere
else it cascades as usual.

Either way this applies to sales and order demand only. Deliberate builds still descend and consume materials.
</Aside>

## Waste percentage

Waste is a percentage on one line of one BOM, and it is applied there. It does not compound across layers. If
a material carries 10% waste on its line in the assembly's BOM, the multiplier is `1.10` at that single
emission. A nested assembly reference carries no waste percentage of its own.

So a chain like:

- B has 1 × Assembly BOM S (no waste on that line).
- S has 5 × Raw R with 10% waste.

For an order of 4 units of B: emit Raw R × (4 × 1 × 5 × 1.10) = 22.

If you want waste at several layers (for example, the assembly itself has assembly loss), model it as an extra
material on the parent bill, not as cumulative percentages.

## A worked end-to-end example

A "Vanilla Candle 8oz" finished good contains:

- 1 × Glass jar
- 1 × Assembly BOM "Wick assembly" (qty 1)
- 1 × Vanilla scent oil (material)

The "Wick assembly" assembly BOM contains:
- 1 × Raw wick (8% waste)
- 0.5 × Wick clip
- 1 × Assembly BOM "Wax block" (qty 1)

The "Wax block" assembly BOM contains:
- 0.25 × Wax (1kg block, 5% waste)

Setup:
- "Wick assembly" pre-assembled stock: 5
- "Wax block" pre-assembled stock: 0
- Finished good pre-assembled: 0

Customer orders 4 units of "Vanilla Candle 8oz".

Expansion:

1. **Finished-good level.** No pre-assembled there. Order quantity 4.
2. **Direct components.** Emit:
   - 4 × Glass jar (qty 1) = **4 jars**.
   - 4 × Vanilla scent oil (qty 1) = **4 oils**.
3. **Recurse into "Wick assembly"** with multiplier 4.
4. **"Wick assembly" pre-assembled.** Consume `min(5, 4) = 4`. Shelf → 1. Remainder = 0.
5. Recursion into "Wick assembly"'s children **stops** because remainder is 0. No raw wick, wick clip, or wax block needed!

Final result: 4 jars, 4 oils, and a -4 to "Wick assembly" pre-assembled shelf.

If the order had been for 7 units instead:
- "Wick assembly" pre-assembled covers 5; remainder = 2.
- Recurse into "Wick assembly"'s children with multiplier 2.
- Emit Raw wick × (2 × 1 × 1.08) = 2.16.
- Emit Wick clip × (2 × 0.5) = 1.
- Recurse into "Wax block" with multiplier 2 × 1 = 2.
- "Wax block" has no pre-assembled. Emit Wax × (2 × 0.25 × 1.05) = 0.525.

## Loops, and why you cannot create one

An assembly BOM cannot contain itself, directly or through a chain (S → T → S, or any longer one). The app
checks every nesting before it is written and **refuses** the save if it would close a loop, naming the loop in
the message: *Cannot add "T" to "S": "T" already contains "S", so this would create a loop*, followed by the
path. Adding a bill to itself is refused with *"S" cannot contain itself*.

The check runs on the write, not in the browser, so it covers every way a nesting can be made: the Materials tab,
the structure canvas, a bulk material edit and a version restore. The pickers also leave out the bills that would
be refused, so in normal use you never see the message.

That means the expansion described on this page always terminates. There is no loop for it to fall into.

A second check runs alongside it. If a bill of materials uses this assembly BOM — directly or through other
assembly BOMs — the assembly BOM may not gain that bill's own product as a component, nor a nested assembly
BOM that holds it: every build of the finished good would otherwise consume one of its own units. The save is
refused with a message naming the component to remove. See [A recipe cannot contain its own
product](/features/bill-of-materials/composition/#a-recipe-cannot-contain-its-own-product).

## Where to next

- [Pre-assembled stock](/features/sub-assemblies/pre-assembled/) — managing the shelf.
- [Keep-assembled cascade](/features/sub-assemblies/keep-assembled/) — what happens on cancel and refund.
- [Execution model](/features/bill-of-materials/execution/) — the parent perspective.

<DocUpdated date="2026-11-19" />