# Lot and Batch Tracking

## Overview

Lot and Batch Tracking assigns lot or batch identifiers to groups of identical products that were produced or received together, enabling full traceability through the supply chain. Each lot carries key attributes such as lot number, manufacture date, expiration date, and supplier lot reference, allowing organizations to trace products forward (from lot to which customers received it) and backward (from lot to which supplier provided it).

Stock quantities are tracked at the lot level per storage location, providing granular visibility into which specific batches are on hand, where they are stored, and when they expire. This lot-level granularity supports expiration alerting, First Expired First Out (FEFO) picking strategies, and regulatory compliance for industries such as food, pharmaceuticals, and chemicals.

## Business Purpose

- Enable forward traceability — given a lot, determine which customers, orders, or locations received stock from that lot
- Enable backward traceability — given a lot, determine which supplier, purchase order, or production run produced it
- Track expiration dates to prevent shipping or consuming expired stock
- Support FEFO (First Expired, First Out) strategies by providing expiration-date-sorted lot lists for operator-driven picking decisions
- Maintain compliance with regulatory requirements including FDA regulations, EU food safety directives, and FSMA Section 204
- Provide lot-level stock visibility per warehouse and storage location for precise inventory management
- Record supplier lot references to correlate internal lot numbers with supplier-provided identifiers
- Support recall workflows by quickly identifying all locations and recipients of an affected lot

## Process Flow

```mermaid
flowchart TD
    A[Goods Receipt] --> B{Lot-Tracked Item?}
    B -->|No| C[Standard Stock Update]
    B -->|Yes| D[Create or Select Lot]
    D --> E[Record Lot Attributes]
    E --> F[Assign Lot to Received Quantity]
    F --> G[Update Lot-Level Stock per Location]
    G --> H[Lot In Stock]
    H --> I{Stock Movement?}
    I -->|Transfer| J[Move Lot Quantity Between Locations]
    I -->|Issue / Ship| K[Deduct Lot Quantity]
    I -->|Adjustment| L[Adjust Lot Quantity with Reason]
    J & K & L --> M[Record Movement Against Lot]
    M --> H
    H --> N{Expiration Check}
    N -->|Approaching Expiry| O[Trigger Expiration Alert]
    N -->|Expired| P[Block or Flag Lot]
    O --> Q[Prioritize for FEFO Picking]
    H --> R{Recall or Inquiry?}
    R -->|Forward Trace| S[Lot -> Movements -> Recipients]
    R -->|Backward Trace| T[Lot -> Receipt -> Supplier / PO]
```

## Scenario Patterns

- **Goods Receipt with Lot Assignment**: A shipment of 500 units arrives from a supplier. The receiver creates lot "LOT-2026-0312" with manufacture date 2026-03-01, expiration date 2027-03-01, and supplier lot reference "SUP-A-8834". All 500 units are recorded against this lot at the receiving location.
- **Multi-Lot Receipt**: A single purchase order delivery contains items from two different production runs. The receiver creates two lots, each with distinct manufacture and expiration dates, and splits the received quantity accordingly.
- **FEFO Picking**: Warehouse has lot A (expires 2026-06-01) and lot B (expires 2026-09-01) for the same item. When a goods issue is requested, the operator refers to the expiration-date-sorted lot list and manually selects lot A first because it expires sooner. Automated FEFO picking assignment is not in scope.
- **Expiration Alert**: A nightly or periodic check identifies lots expiring within a configurable threshold (e.g., 30 days). Alerts are generated so warehouse staff can prioritize these lots for outbound orders or mark them for review.
- **Forward Traceability (Recall)**: A quality issue is discovered in lot "LOT-2026-0312". The system traces all outbound movements for that lot, identifying every sales order, customer, and destination location that received units from the affected lot.
- **Backward Traceability (Root Cause)**: A customer reports a defect. The shipped lot is identified, and the system traces backward to the originating supplier, purchase order, and supplier lot reference to isolate the source.
- **Lot Transfer Between Locations**: 100 units of lot "LOT-2026-0312" are transferred from Warehouse A, Bin 01 to Warehouse B, Bin 05. Both the source deduction and destination addition are recorded against the same lot.
- **Lot-Level Inventory Adjustment**: During a physical count, 10 units of a specific lot are found missing. An inventory adjustment is recorded against that lot with a reason code, updating the lot-level stock balance.
- **Expired Lot Handling**: A lot passes its expiration date. The system flags the lot as expired, preventing it from being selected for outbound shipments. The lot quantity may be routed to scrap management for disposal.

## Test Cases

- Creating a lot requires a unique lot number within the scope of the item
- Lot number is immutable after creation
- Manufacture date, expiration date, and supplier lot reference are recorded at lot creation and can be updated before the lot is fully consumed
- Goods receipt for a lot-tracked item must specify a lot; receipts without lot assignment should be rejected
- Stock quantities are tracked per lot per storage location; on-hand balances reflect lot-level granularity
- A goods issue against a specific lot reduces that lot's quantity at the specified location
- Issuing more quantity than a lot's on-hand balance at a location should be rejected
- Internal transfers preserve the lot association — the destination stock record references the same lot
- Inventory adjustments are recorded at the lot level with a mandatory reason code
- Forward traceability query for a lot returns all outbound stock movements and their destinations
- Backward traceability query for a lot returns the originating receipt, supplier, and purchase order reference
- Expiration alert is triggered when a lot's expiration date is within the configured threshold
- Expired lots are excluded from FEFO picking recommendations
- Lots with no remaining on-hand quantity across all locations are marked as fully consumed
- A single item can have multiple active lots simultaneously at the same storage location

## Reference Links

- [SAP Batch Management](https://help.sap.com/docs/SAP_S4HANA_ON-PREMISE/f47f7a5b49084709aac9f60498bab8cd/4517edda2c8c7744e10000000a174cb4.html)
- [Odoo Lot and Serial Number Tracking](https://www.odoo.com/documentation/19.0/applications/inventory_and_mrp/inventory/product_management/product_tracking.html)
- [FDA FSMA Section 204 Traceability Rule](https://www.fda.gov/food/food-safety-modernization-act-fsma/fsma-final-rule-requirements-additional-traceability-records-certain-foods)
- [Oracle Lot Control](https://docs.oracle.com/en/cloud/saas/supply-chain-management/24d/faims/lot-and-serial-control.html)
