# Goods Receipt Matching

## Overview

Goods Receipt Matching records what has actually been received from the supplier. A `GoodsReceipt` carries company and supplier context and contains one or more receipt lines. Each line optionally references a purchase-order line — receipts can be created without a PO reference to support blind receipts (goods arrive before a PO is confirmed), non-PO purchases (spot buys, samples, donations), and consignment scenarios. A single receipt may span lines from multiple purchase orders, and may mix PO-linked and PO-unlinked lines.

The receipt is a record of the physical fact that goods arrived. Matching against purchase orders is a separate, downstream step. PO-linked receipt lines update purchase-order receiving progress when posted; PO-unlinked receipt lines are posted without affecting any purchase order. The PO reference can be assigned or changed on a draft receipt before posting.

Purchase owns the receipt document and the matching rules against purchase orders. The relationship between a receipt and its purchase orders is expressed through receipt lines optionally referencing purchase-order lines — the receipt header does not carry a direct purchase-order foreign key. This mirrors the same line-level referencing pattern used by PurchaseBill. For stock-item lines, posting a goods receipt directly creates a DRAFT stock movement in the inventory module. Inventory owns the subsequent stock movement lifecycle (confirmation, execution, putaway, lot or serial recording, and on-hand updates). This makes receipts usable both for stock items and for service or non-stock procurement scenarios where no stock movement is needed.

## Business Purpose

- Record the physical fact that goods arrived from a supplier, independently of whether a purchase order exists
- Confirm supplier fulfillment against the original purchase commitment when a PO reference is present
- Support blind receipts, non-PO purchases, and consignment scenarios by allowing PO-unlinked receipt lines
- Support partial deliveries and backorders without losing order-level visibility
- Enforce over-receipt and under-receipt tolerance rules on PO-linked purchase order lines
- Provide the receipt basis required for 3-way supplier bill matching
- Trigger downstream inbound stock or service-acceptance processes without moving warehouse logic into purchase
- Preserve an auditable history of what was received, when, and optionally against which supplier commitment

## Process Flow

```mermaid
flowchart TD
    A[Goods arrive from supplier] --> B[Create Goods Receipt with company and supplier]
    B --> C[Enter receipt lines — optionally reference PO lines]
    C --> D[Enter received quantities and dates]
    D --> E{Post Goods Receipt}
    E --> F{PO-linked lines}
    F --> G{Within tolerance?}
    G -->|No| H[Block or require override]
    G -->|Yes| I[Update PO line received quantities]
    I --> J{All quantities received on each PO?}
    J -->|No| K["PO receiptStatus: PARTIALLY_RECEIVED"]
    J -->|Yes| L["PO receiptStatus: RECEIVED"]
    E --> M{PO-unlinked lines}
    M --> N[Post without PO update]
    E --> O[Create DRAFT stock movement in inventory]
    E --> P[Receipt eligible for supplier bill matching]
```

## Scenario Patterns

- **Full delivery**: The supplier delivers every ordered line in one shipment and a single posted goods receipt completes the receiving side of the order
- **Consolidated shipment**: The supplier delivers against multiple purchase orders in one shipment. A single goods receipt contains lines referencing purchase-order lines from different purchase orders, and posting updates each purchase order's `receiptStatus` independently
- **Blind receipt (PO-unlinked)**: Goods arrive before a purchase order is confirmed. The receipt is created without PO references and posted to record the physical fact. The PO reference can be assigned later on a new receipt or through a future linking workflow
- **Non-PO purchase**: A spot buy, sample, or donated goods arrive without any purchase order. The receipt is created and posted with PO-unlinked lines
- **Mixed receipt**: A single receipt contains both PO-linked lines (against existing orders) and PO-unlinked lines (blind receipts). Posting updates PO progress for linked lines and skips PO validation for unlinked lines
- **Partial shipment with backorder**: Only half the quantity arrives. The receipt posts successfully, open quantity remains on the PO, and another receipt can be recorded later
- **Overdelivery within tolerance**: A supplier sends 102 units against an order for 100 where a 2 percent over-receipt tolerance is allowed, so the receipt is accepted
- **Overdelivery beyond tolerance**: A supplier sends materially more than ordered, and the receipt is blocked or requires an explicit procurement exception
- **Split line receiving**: One line on the order is fully received while another remains open, and the receipt captures both outcomes in the same document
- **Service acceptance**: A non-stock service line is marked received or accepted without creating warehouse-level stock, but the receipt still unlocks downstream bill matching
- **Receipt date tracking**: The supplier shipment arrives late, and the posted receipt captures the actual date for lead-time and supplier-performance analysis
- **Receipt correction before posting**: A receiver notices a quantity entry mistake while the receipt is still draft and corrects it before it updates PO fulfillment
- **Future receipt reversal**: A posted receipt is later found to be incorrect. A future reversal workflow will preserve the original posted receipt, emit a compensating correction, and keep the audit trail intact rather than mutating history

## Test Cases

- Creating a goods receipt against an `ORDERED` purchase order with open quantity should succeed
- Creating a goods receipt with lines from multiple purchase orders of the same supplier should succeed (consolidated shipment)
- Creating a goods receipt without any PO references (blind receipt) should succeed
- Creating a goods receipt with a mix of PO-linked and PO-unlinked lines should succeed
- A PO-linked goods receipt line must reference a valid purchase order line
- Every receipt line must record a received quantity greater than zero
- PO-linked receipt lines must reference purchase-order lines belonging to purchase orders with the same company and supplier as the receipt header
- A receipt line referencing a cancelled or closed purchase order must be rejected
- Posting a goods receipt must increase the referenced purchase order line's cumulative received quantity for PO-linked lines
- Posting PO-unlinked receipt lines must succeed without affecting any purchase order
- Posting a consolidated receipt must update each affected purchase order's `receiptStatus` independently
- Partial receipts must leave the remaining open quantity available for future receipts
- Receiving more than the ordered quantity plus configured tolerance should fail or require an explicit override (PO-linked lines only)
- Receiving against an inactive item or inactive supplier should be prevented if the order is no longer valid for execution
- A goods receipt posted for a stock item should create a DRAFT stock movement in the inventory module exactly once
- A goods receipt posted for a non-stock or service line must not create a stock movement
- Only posted goods receipts should count toward 3-way supplier bill matching
- Receipt posting must be isolated by company and must not update purchase orders belonging to another company
- If a receipt is reversed or corrected through a future workflow, the purchase order received quantity must remain auditable rather than silently overwritten
- Purchase order `receiptStatus` should move to a partial or full receipt state based on aggregate posted receipt quantities, without affecting `orderStatus` or `billingStatus`
- Only authorized receiving or procurement users should be able to post goods receipts
- A goods receipt should preserve the supplier and line references needed for audit and traceability; related purchase orders are derived from line references

## Reference Links

- [Odoo vendor bills and three-way matching](https://www.odoo.com/documentation/19.0/applications/inventory_and_mrp/purchase/manage_deals/manage.html#vendor-bills)
- [Oracle Fusion Cloud Procurement documentation](https://docs.oracle.com/en/cloud/saas/procurement/index.html)
- [SAP receipt confirmation documentation](https://help.sap.com/docs/SAP_S4HANA_CLOUD/65de2977205c403bbc107264b8eccf4b/552eb9c732c14df6a2926efce6d890ad.html)
