Overview
The Stock Request framework extends the standard Odooprocurement.group model to ensure that procurements generated from stock requests maintain proper origin traceability. When a procurement is triggered by a stock request that belongs to an order, the extension updates the procurement’s origin to reference the stock request order name.
Model Information
procurement.group
procurement.group
Methods
Extends the procurement run method to update the origin of procurements that are linked to stock request orders.Parameters:
procurements(list): List of procurement namedtuples to processraise_user_error(bool, default=True): Whether to raise user-facing errors
- Iterates through all procurements in the list
- Checks if each procurement has a
stock_request_idin its values - If the stock request belongs to an order, creates a new procurement with updated origin
- Replaces original procurements with updated ones
- Calls the parent run method with the modified procurement list
Purpose and Behavior
Origin Traceability
The extension ensures proper traceability by updating procurement origins when they’re generated from stock requests:Processing Logic
Technical Details
Index Management
The method uses a reverse-indexed approach to safely modify the procurements list:- Forward iteration: Identifies procurements to replace and stores their indexes
- Reverse pop: Removes original procurements starting from the highest index to avoid index shifting issues
- Extension: Adds new procurements with updated origins to the end of the list
Reversing the index list before popping is crucial to prevent index shifting errors when removing multiple items from a list.
Procurement Values
The extension looks for a specific key in the procurement values dictionary:ID of the stock request that triggered this procurement. This value is added by the Stock Request framework when creating procurements.
Usage Examples
Standard Procurement Flow
Checking Procurement Origin
Integration Points
Stock Request Procurement
When stock requests generate procurements:- The
stock_request_idis added to procurement values - The procurement group run method is called
- This extension updates origins for better traceability
Downstream Documents
The updated origin flows to downstream documents:- Purchase Orders: Origin shows stock request order name
- Manufacturing Orders: Origin shows stock request order name
- Stock Moves: Origin maintains traceability to the order
This extension improves the audit trail by ensuring all documents generated from a stock request order reference the order name rather than individual request names.
Source Code References
- Stock Request extensions:
stock_request/models/procurement_group.py
