# Execute the Trace

::embed-section{src="../../kanoa-trace/lot-management.md#executing-lot-operations" collapsed="true" summary="Reference Materials: Executing Lot Operations"}

:::overview
You'll follow 2024 aluminum all the way to a shipped package of hardened coupling pins. Every step is a lot operation in **Ops → Lots → Lot Manager**.
:::

Each lot operation is run from the **Add A Lot Operation** popup. Click **Add Lot Operation** (**+**) above the lot table to open it. If a lot is selected in the table, it's already filled in as the input lot.

1. Choose the **Operation** and the **Asset** where it happens.
2. For an operation that takes input lots, on the **Input Lots** tab choose the input **Lot**, if it isn't filled in already, and its **Qty**. Choosing a lot fills in all of its quantity, so change it when you take only part.
3. On the **Output Lots** tab, choose **Same lot as the input lot** to keep the lot, as a transfer does, or **New lot** to make one: choose its **Item** and **Serialization**, which shows the lot's name, then its **Qty** and unit, and its **Lot State**.
4. Click **Execute**. The popup then asks whether to add another input or output to the operation. Click **Add another input** or **Add another output** to add one, or **Done** to close the popup. The lot the operation made or moved is selected in the table, with its trace on the **Trace** tab.

You can also list several inputs before you execute: on the **Input Lots** tab, click **Add** after each lot to move it to the list above the form. Once the list has entries, **Execute** records only the list, so add the last one too. A new operation's **Output Lots** tab has one output; add more with **Add another output** after **Execute**.

Lot names below end in `x`, such as `WMP000000000x`: replace the `x` with your lot's number. The number depends on what you've run before, so it can be longer than one digit; use the lot table to find your lot's full name.

:::action[Receive the raw materials]

1. Navigate to **Ops → Lots → Lot Manager**, and click **Clear selection** if a lot is selected.
2. Click **Add Lot Operation** (**+**). Choose `Receive` at `Storage\Receiving`. On the **Output Lots** tab, choose item `AL2024`, serialization `Raw Aluminum` and Qty `1000` `lbs`, and click **Execute**. Click **Done**.
3. Click **+** again and choose `Receive` at `Storage\Receiving`. Output item `STD-COAT`, serialization `Raw Blending Ingredients`, Qty `100` `Gallons`, and click **Execute**.
4. Click **Add another output**, and add item `PRM-COAT`, serialization `Raw Blending Ingredients`, Qty `50` `Gallons`. Click **Execute**, then **Done**. One `Receive` now has two output lots.

:::

:::action[Machine and blend]

1. Select the aluminum lot (`RAL000000000x`) at `Storage\Receiving` in the lot table and click **+**. Choose `Transfer` at `Machining\Machine 1`. On **Input Lots**, change the Qty to `100`. On **Output Lots**, choose **Same lot as the input lot** with Qty `100`. Click **Execute**, then **Done**. Receiving now holds 900 lbs and Machine 1 holds 100 lbs.
2. Select `RAL000000000x` at `Machine 1` and click **+**. Choose `Machine` at `Machining\Machine 1`, input Qty `100`, and a **New lot** of item `CP-2024`, serialization `WIP Machined Parts`, Qty `50` `units`. Click **Execute**, then **Done**.
3. Select the `STD-COAT` lot (`RBI000000000x`) at `Storage\Receiving` and click **+**. Choose `Blend` at `Mixing\Mixer 1` and change the input Qty to `10`. Click **Add another input**, choose the `PRM-COAT` lot (`RBI000000000x`) at `Storage\Receiving` in the **Lot** list, and enter Qty `5`. On **Output Lots**, choose a **New lot** of item `BL-HRD`, serialization `WIP Coatings/Blends`, Qty `15` `Gallons`. Click **Execute**, then **Done**. One `Blend` now has two input lots.

:::

:::action[Coat]

1. Select the blend lot (`WBL000000000x`) at `Mixer 1` and click **+**. Choose `Transfer` at `Coating\Spray Line 1`, input Qty `15`, output **Same lot as the input lot** with Qty `15`, and click **Execute**, then **Done**.
2. Select the machined parts lot (`WMP000000000x`) at `Machine 1`, and transfer all `50` units to `Coating\Spray Line 1` the same way.
3. Select the blend lot at `Spray Line 1` and click **+**. Choose `Coat` at `Coating\Spray Line 1` and change the input Qty to `2`. Click **Add another input**, choose the machined parts lot at `Spray Line 1` in the **Lot** list, and enter Qty `50`. On **Output Lots**, choose a **New lot** of item `CP-2024-HRD`, serialization `WIP Coated Parts`, Qty `50` `units`. Click **Execute**, then **Done**.

:::

:::action[Inspect]

1. Select the coated parts lot (`WCP000000000x`) at `Spray Line 1` and click **+**. Choose `Inspect` at `Finishing\QA Station`, input Qty `50`, and output **Same lot as the input lot** with Qty `45` and Lot State `OK`. Click **Execute**.
2. Click **Add another output** for the parts that failed. Choose **New lot** and item `CP-2024-HRD`. Leave **Serialization** empty and type the lot name: your coated lot's name followed by `-SCRAP`, such as `WCP0000000001-SCRAP`. Enter Qty `5` `units`, Lot State `Scrap` and Reason `Failed visual inspection`, and click **Execute**, then **Done**.
3. Select your `-SCRAP` lot and click **+**. Choose `Scrap` at `Finishing\QA Station`, input Qty `5`, and click **Execute**, then **Done**. Scrap has no output, so the lot leaves current inventory.

:::

:::action[Pack and ship]

1. Select the coated parts lot at `QA Station` and click **+**. Choose `Pack` at `Finishing\Auto Pack 1`, input Qty `45`, and a **New lot** of item `FG-CP-2024-HRD-250`, serialization `Finished Goods Packages`, Qty `1` `Cases`. Click **Execute**, then **Done**.
2. Select the package lot (`FGP000000000x`) and click **+**. Choose `Ship` at `Storage\Shipping`, input Qty `1`, and click **Execute**, then **Done**. Ship has no output.

:::

:::tip[Fixing a mistake]
Select the lot, open its **Trace** tab, click the wrong operation and click **Edit**. The operation opens in the same popup: change it and click **Save**, or click **Delete**. To correct only a lot's quantity or location, click **Edit Lot** instead: Kanoa records the change as an `Adjust` or a `Transfer`, so the lot's history stays complete.
:::

:::check

Copy this script into the Ignition Designer Script Console (**Tools → Script Console**) and run it. It checks that the coating items exist, then looks for each lot operation in this lesson at its asset, with the right input and output lots, items and quantities: the two receives, the transfer, machine and blend, the two transfers to Spray Line 1 and the coat, the inspect and scrap, and the pack and ship. Lots are matched by serialization prefix and item, so the numbers your lots got don't matter. Each check prints PASS or FAIL with what to fix. It doesn't change anything.

<details>
<summary>Show the check script</summary>

::check-script{src="trace/03-execute-the-trace.py" title="checkLesson-executeTheTrace.py"}

</details>

:::

***

## Trace Your Lots

::embed-section{src="../../kanoa-trace/lot-management.md#lot-traceability" collapsed="true" summary="Reference Materials: Lot Traceability"}

Scrap and Ship remove material from **current inventory**, but not from the **trace history**. Lot Manager shows both.

:::action[Check current inventory]

1. In **Ops → Lots → Lot Manager**, make sure **Active** is selected, to show only lots that still have material. Click **Get lots** (the refresh button above the table) to reload it.
2. Confirm the remaining quantities:

   | Lot | Remaining |
   | --- | --- |
   | `RAL000000000x` (`AL2024`) | 900 lbs at Receiving |
   | `RBI000000000x` (`STD-COAT`) | 90 gallons at Receiving |
   | `RBI000000000x` (`PRM-COAT`) | 45 gallons at Receiving |
   | `WBL000000000x` (`BL-HRD`) | 13 gallons at Spray Line 1 |

3. Clear **Active** to see every lot, including the machined, coated, scrapped and shipped ones. A date range appears in the filters: click **Get lots** to reload the table, and widen the date range if it doesn't cover the day you ran the operations.

:::

:::action[Trace the genealogy]

1. With **Active** cleared and the table reloaded, select the shipped package `FGP000000000x` and open the **Trace** tab below the table. The Trace tab draws one graph of the lot's genealogy, both what went into it and where it went.
2. The depth button above the graph sets how far the trace reaches. It starts on `M` (medium), which stops before the raw materials. Click it until it shows `D` (deep) to see the whole genealogy:

   `FGP000000000x` ← `WCP000000000x` ← `WMP000000000x` + `WBL000000000x` ← `RAL000000000x` + `RBI000000000x` + `RBI000000000x`

3. Select the aluminum lot `RAL000000000x`. With the depth still on `D`, its graph shows everywhere that aluminum went: machined, coated, inspected, split into passed and scrap, packed and shipped.
4. Select your `-SCRAP` lot and confirm the scrap branch is still connected to its inputs.

:::

Tracing forward from a raw material lot is what you do when a supplier reports a bad batch: it tells you which products, and which shipments, contain that material.
