Reference for purchase_requests in procurement, with request and item fields, statuses, actions, routes, and the rules that apply before an order.
This page describes the purchase_requests sub-module in src/cluster_erp/modules/procurement/purchase_requests/. A purchase request (PurchaseRequest) collects materials to be bought, with estimated prices, before an order or an RFQ exists. Requests are created by users or from MRP run items; MRP is described on material requirements planning.
Defined in: models.py (PurchaseRequest, PurchaseRequestItem), services.py (PurchaseRequestService), routes.py, metadata.py, and item_metadata.py of the sub-module.
In prose: a request starts as draft. submit_approval moves it to pending_approval, approve to approved, and creating an order from it to po_issued (src/cluster_erp/modules/procurement/purchase_requests/services.py:493-531, src/cluster_erp/modules/procurement/purchase_orders/services.py:409-410). cancel is open from draft, pending_approval, and approved. The table allows po_issued to closed, but a grep for "closed" in the sub-module finds only the table and a metadata filter value; no route sets it.
Each item's product breakdown is checked with ensure_product_breakdown (src/cluster_erp/modules/procurement/purchase_requests/services.py:233, src/cluster_erp/modules/procurement/purchase_requests/services.py:378).
The line estimate is quantity times unit price, rounded with ROUND_HALF_EVEN; the header total is the sum (src/cluster_erp/modules/procurement/purchase_requests/services.py:48-60, src/cluster_erp/modules/procurement/purchase_requests/services.py:120-122).
If any item's product is an active critical material, the request priority becomes high (src/cluster_erp/modules/procurement/purchase_requests/services.py:124-138, src/cluster_erp/modules/procurement/purchase_requests/services.py:270-273).
The header and items can change only in draft or pending_approval (src/cluster_erp/modules/procurement/purchase_requests/services.py:297, src/cluster_erp/modules/procurement/purchase_requests/services.py:372, src/cluster_erp/modules/procurement/purchase_requests/services.py:421, src/cluster_erp/modules/procurement/purchase_requests/services.py:460).
Only a draft request can be deleted; delete sets deleted_at (src/cluster_erp/modules/procurement/purchase_requests/services.py:324-336).
An order can be created from a request only when it is approved; deleted items are skipped (src/cluster_erp/modules/procurement/purchase_orders/services.py:369-381).
Events: PrCreated on create, PrApproved on approve, PrCancelled on cancel (src/cluster_erp/modules/procurement/purchase_requests/services.py:278-285, src/cluster_erp/modules/procurement/purchase_requests/services.py:522-529, src/cluster_erp/modules/procurement/purchase_requests/services.py:547).