Understanding Stock Request Orders and how they group multiple requests
A Stock Request Order is a container model that groups multiple Stock Requests together. It provides a way to manage several product requests as a single unit with shared parameters.
The Stock Request Order model (stock.request.order) allows you to create and manage multiple stock requests that share common attributes like warehouse, location, expected date, and shipping policy.
Stock Request Orders are defined in stock_request/models/stock_request_order.py:8
Unlike Stock Requests, the order’s state is computed from its child requests:
@api.depends("stock_request_ids.state")def _compute_state(self): for item in self: states = item.stock_request_ids.mapped("state") if not item.stock_request_ids or all(x == "draft" for x in states): item.state = "draft" elif all(x == "cancel" for x in states): item.state = "cancel" elif all(x in ("done", "cancel") for x in states): item.state = "done" else: item.state = "open"
def action_confirm(self): if not self.stock_request_ids: raise UserError( _("There should be at least one request item for confirming the order.") ) self.mapped("stock_request_ids").action_confirm() return True
Confirming an order confirms all child stock requests simultaneously (stock_request_order.py:300).
An order must have at least one child stock request before it can be confirmed.
Orders provide intelligent route computation based on all child requests:
@api.depends("warehouse_id", "location_id", "stock_request_ids")def _compute_route_ids(self): # Computes available routes based on warehouse and location # Filters routes valid for the destination # If requests exist, finds common routes across all requests
You can set a route on the order, and it will apply to all child requests:
@api.depends("stock_request_ids")def _compute_route_id(self): for order in self: if order.stock_request_ids: first_route = order.stock_request_ids[0].route_id or False if any(r.route_id != first_route for r in order.stock_request_ids): first_route = False order.route_id = first_routedef _inverse_route_id(self): for order in self: if order.route_id: order.stock_request_ids.write({"route_id": order.route_id.id})