Understanding the complete Stock Request workflow from creation to completion
The Stock Request workflow manages the complete lifecycle of a product request, from initial creation through procurement, fulfillment, and completion or cancellation.
The system prepares specific values for procurement:
def _prepare_procurement_values(self, group_id=False): """ Prepare specific key for moves or other components that will be created from a procurement rule coming from a stock request. """ return { "date_planned": self.expected_date, "warehouse_id": self.warehouse_id, "stock_request_allocation_ids": self.id, "group_id": group_id or self.procurement_group_id.id or False, "route_ids": self.route_id, "stock_request_id": self.id, }
(stock_request.py:321)
These values are passed to procurement rules and can be extended through inheritance to add custom fields.
Requests are automatically cancelled under certain conditions:
def check_cancel(self): for request in self: if request._check_cancel_allocation(): request.write({"state": "cancel"})def _check_cancel_allocation(self): precision = self.env["decimal.precision"].precision_get( "Product Unit of Measure" ) self.ensure_one() return ( self.allocation_ids and float_compare(self.qty_cancelled, 0, precision_digits=precision) > 0 )
(stock_request.py:285, stock_request.py:311)
If allocations exist but there’s cancelled quantity with no progress, the request is automatically cancelled.
Here’s a complete example demonstrating the workflow:
# 1. Create a stock requestrequest = env['stock.request'].create({ 'product_id': product.id, 'product_uom_id': product.uom_id.id, 'product_uom_qty': 100.0, 'warehouse_id': warehouse.id, 'location_id': location.id, 'expected_date': fields.Datetime.now(),})print(request.state) # 'draft'# 2. Confirm the requestrequest.action_confirm()print(request.state) # 'open'# 3. Procurement rules are evaluated# - System checks if stock is available# - If not, procurement rules generate stock moves or purchase orders# - Allocations are created linking request to movesprint(len(request.allocation_ids)) # > 0print(len(request.move_ids)) # > 0print(len(request.picking_ids)) # > 0# 4. Track progressprint(request.qty_in_progress) # Quantity being processedprint(request.qty_done) # Quantity completed# 5. Process transfers# Users process the pickings in the warehousefor picking in request.picking_ids: picking.action_confirm() picking.action_assign() # ... process the picking# 6. Request automatically moves to done when fulfilledrequest.check_done()print(request.state) # 'done'
When working with Stock Request Orders, the workflow extends to manage multiple requests:
# Create order with multiple requestsorder = env['stock.request.order'].create({ 'expected_date': fields.Datetime.now(), 'warehouse_id': warehouse.id, 'location_id': location.id,})# Add multiple requestsfor product in products: env['stock.request'].create({ 'order_id': order.id, 'product_id': product.id, 'product_uom_id': product.uom_id.id, 'product_uom_qty': 10.0, })# Confirm all requests at onceorder.action_confirm()# Order state is computed from child requestsprint(order.state) # 'open', 'done', 'cancel', or 'draft'
The order state automatically reflects the collective state of all child requests, transitioning to “done” when all children are done or cancelled.