# Purchase Requisition to PO Conversion

## Overview

Purchase Requisition to PO Conversion transforms an approved internal purchase request into a formal supplier commitment. When a `PurchaseRequisition` reaches `APPROVED` status, its lines can be converted into a new `PurchaseOrder` in `DRAFT` status. Each generated purchase order line is linked to its source requisition line through a `PurchaseRequisitionLineAllocation` record, preserving end-to-end traceability from the original demand through supplier fulfillment.

The conversion bridges the gap between the internal request (PR) and the supplier commitment (PO). If the requisition carries a suggested supplier, that supplier is used as the default on the new purchase order; otherwise the user must specify a supplier at conversion time. Supplier purchase pricing rules may be resolved to default prices onto the generated PO lines, and a payment term must be specified at conversion time. After successful conversion the requisition transitions to `CONVERTED` status, and the resulting purchase order enters the standard purchase order approval lifecycle independently.

## Business Purpose

- Convert approved internal demand into a formal, actionable supplier commitment
- Eliminate manual re-entry of item, quantity, and specification data already captured on the requisition
- Maintain full traceability from the original business need through to supplier delivery and billing
- Default supplier pricing and payment terms onto the purchase order to reduce procurement cycle time
- Enforce that only approved requisitions can generate purchase orders, preserving the approval gate
- Keep requisition and purchase order lifecycles independent so each document progresses through its own controls

## Process Flow

```mermaid
flowchart TD
    A["Purchase Requisition in APPROVED status"] --> B{Suggested supplier?}
    B -->|Yes| C[Use suggested supplier]
    B -->|No| D[User specifies supplier]
    C --> E[Resolve supplier pricing and payment terms]
    D --> E
    E --> F[Generate PO lines from PR lines]
    F --> G["Create Purchase Order in DRAFT status"]
    G --> H[Record PurchaseRequisitionLineAllocation for each line pair]
    H --> I["PR status → CONVERTED"]
    I --> J[PO enters standard approval lifecycle]
```

## Scenario Patterns

- **Standard conversion with suggested supplier**: A requisition with a suggested supplier is approved, and conversion generates a draft purchase order pre-populated with that supplier's pricing and the specified payment term
- **Conversion without suggested supplier**: A requisition is approved without a supplier preference, and the buyer selects the appropriate supplier at conversion time before the purchase order is created
- **Price resolution from supplier rules**: The conversion resolves the supplier's purchase price list to default unit prices onto the generated PO lines, which the buyer may still override before submitting the order
- **Payment term assignment**: A payment term must be specified at conversion time and is assigned to the generated purchase order; the caller may resolve a default from the supplier profile
- **Full requisition conversion**: All lines on an approved requisition are converted into a single purchase order, and the requisition transitions to converted status
- **Post-conversion PO revision**: After conversion the purchase order is still in draft, so the buyer adds shipping instructions or adjusts quantities before submitting the order for its own approval
- **Duplicate conversion prevention**: Attempting to convert a requisition that has already been converted should be rejected to prevent duplicate purchase orders
- **Conversion of requisition with inactive supplier**: If the suggested supplier has become inactive since the requisition was approved, conversion should fail rather than create an invalid purchase order

## Test Cases

- Converting an `APPROVED` purchase requisition should create a new purchase order in `DRAFT` status
- Each generated purchase order line must be linked to its source requisition line through a `PurchaseRequisitionLineAllocation` record
- Converting a requisition that is not in `APPROVED` status should fail
- Converting a requisition that has already been converted should fail
- If the requisition has a suggested supplier, the generated purchase order should use that supplier
- If the requisition has no suggested supplier, the conversion must require a supplier to be specified
- Conversion against an inactive supplier should be rejected
- Generated PO line quantities must match their source requisition line quantities
- Generated PO line items must match their source requisition line items
- Supplier pricing rules should be resolved and applied as default unit prices on the generated PO lines when available
- A payment term must be specified at conversion time and is assigned to the generated purchase order
- After successful conversion the purchase requisition status must transition to `CONVERTED`
- The generated purchase order must be associated with the same company as the source requisition
- Conversion must not modify the source requisition's line data
- Only authorized procurement users should be able to perform requisition-to-PO conversion

## Reference Links

- [Odoo Purchase Requisition to Purchase Order](https://www.odoo.com/documentation/19.0/applications/inventory_and_mrp/purchase.html)
- [Oracle Fusion Cloud Procurement documentation](https://docs.oracle.com/en/cloud/saas/procurement/index.html)
- [SAP purchase requisition to purchase order conversion](https://help.sap.com/docs/SAP_S4HANA_CLOUD)
