Overview
Thestock.request.order model acts as a container for grouping multiple stock requests together. It provides unified control over warehouse, location, expected date, and shipping policy for all contained requests. The order’s state is computed based on the states of its child requests.
Model Name: stock.request.order
Inherits: mail.thread, mail.activity.mixin
Order: id desc
Fields
Core Fields
Unique identifier for the stock request order. Auto-generated from sequence
stock.request.order if not provided.Properties: copy=False, readonly=True, default="/"Current status of the stock request order. Computed from child request states.Options:
draft- Draft (all requests are draft)open- In progress (mixed states)done- Done (all requests are done or cancelled)cancel- Cancelled (all requests are cancelled)
copy=False, default="draft", index=True, readonly=True, tracking=True, compute="_compute_state", store=TrueReference to
res.users. The user who requested the stock.Default: Current user (self.env.uid)Properties: tracking=TrueDate when you expect to receive the goods. Applied to all child requests.Default:
fields.Datetime.nowProperties: index=True, required=TrueDefines how products should be received for all requests in the order.Options:
direct- Receive each product when availableone- Receive all products at once
"direct"Location & Warehouse Fields
Reference to
stock.warehouse. The warehouse where stock is requested.Properties: check_company=True, ondelete="cascade", required=TrueReference to
stock.location. The specific location within the warehouse.Domain: [('usage', 'in', ['internal', 'transit'])] (when virtual locations not allowed)Properties: ondelete="cascade", required=TrueWhether virtual locations are allowed.Related:
company_id.stock_request_allow_virtual_locProperties: readonly=TrueProcurement & Company Fields
Reference to
procurement.group. Moves created through stock requests in this order will be put in this procurement group.Help: If none is given, moves generated by procurement rules will be grouped into one big picking.Reference to
res.company. The company this order belongs to.Default: self.env.companyRoute Fields
Reference to
stock.route. The route related to a stock request order. When set, applied to all child requests.Properties: compute="_compute_route_id", inverse="_inverse_route_id", readonly=True, store=TrueReference to
stock.route. Available routes based on warehouse and location.Properties: compute="_compute_route_ids", readonly=True, store=TrueRelational Fields
Reference to
stock.request records with inverse_name="order_id".All stock requests contained in this order.Properties: copy=TrueNumber of stock requests in this order.Properties:
compute="_compute_stock_request_count", readonly=TrueReference to
stock.move records from all child requests.Properties: compute="_compute_move_ids", readonly=TrueReference to
stock.picking records from all child requests.Properties: compute="_compute_picking_ids", readonly=TrueNumber of delivery orders/pickings.Properties:
compute="_compute_picking_ids", readonly=TrueMethods
Action Methods
Confirms all stock requests in the order.Returns:
TrueRaises: UserError if there are no stock request items in the orderBehavior:- Validates that at least one request exists
- Calls
action_confirm()on all childstock_request_ids
stock_request/models/stock_request_order.py:300
Resets all stock requests in the order to draft state.Returns:
Truestock_request/models/stock_request_order.py:308
Cancels all stock requests in the order.Returns:
Truestock_request/models/stock_request_order.py:312
Marks the order as done (currently no-op, state computed from requests).Returns:
Truestock_request/models/stock_request_order.py:316
Opens the transfer/picking view for all pickings in this order.Returns:
dict - Action dictionary for viewing pickingsBehavior:- Shows tree view if multiple pickings
- Shows form view if single picking
stock_request/models/stock_request_order.py:319
Opens the view for stock requests in this order.Returns:
dict - Action dictionary for viewing stock requestsBehavior:- Shows tree view if multiple requests
- Shows form view if single request
stock_request/models/stock_request_order.py:332
Compute Methods
Computes the order state based on child request states.Depends on:
stock_request_ids.stateLogic:draft: No requests OR all requests aredraftcancel: All requests arecanceldone: All requests aredoneorcancelopen: Mixed states (in progress)
stock_request/models/stock_request_order.py:211
Computes available routes based on warehouse, location, and child requests.Depends on:
warehouse_id, location_id, stock_request_idsBehavior:- Finds routes associated with the warehouse
- Filters routes based on location hierarchy
- If requests exist, computes common routes across all requests
stock_request/models/stock_request_order.py:150
Computes the single route ID if all child requests use the same route.Depends on:
stock_request_idsLogic:- If all requests have the same route, sets that route
- If routes differ across requests, sets to
False
stock_request/models/stock_request_order.py:191
Computes all pickings from child requests.Depends on:
stock_request_ids.allocation_idsstock_request/models/stock_request_order.py:224
Computes all stock moves from child requests.Depends on:
stock_request_idsstock_request/models/stock_request_order.py:230
Computes the number of stock requests in the order.Depends on:
stock_request_idsstock_request/models/stock_request_order.py:235
Inverse Methods
Applies the order’s route to all child requests.Behavior:
- When
route_idis set on the order, writes it to allstock_request_ids
stock_request/models/stock_request_order.py:200
Onchange Methods
Updates all child requests when route changes.Decorator:
@api.onchange("route_id")stock_request/models/stock_request_order.py:205
Propagates
requested_by change to child requests.Decorator: @api.onchange("requested_by")Propagates
expected_date change to child requests.Decorator: @api.onchange("expected_date")Propagates
picking_policy change to child requests.Decorator: @api.onchange("picking_policy")Updates warehouse when location changes and propagates to child requests.Decorator:
@api.onchange("location_id")Behavior:- If location has a different warehouse, updates
warehouse_id - Calls
change_childs()to update child requests
Updates location and company when warehouse changes.Decorator:
@api.onchange("warehouse_id")Behavior:- Updates
location_idto warehouse’slot_stock_id - Updates
company_idif warehouse company differs - Calls
change_childs()to update child requests
Propagates
procurement_group_id change to child requests.Decorator: @api.onchange("procurement_group_id")Updates warehouse when company changes.Decorator:
@api.onchange("company_id")Behavior:- Searches for a warehouse in the new company
- Calls
change_childs()to update child requests
Propagates order-level changes to all child stock requests.Updated fields:
warehouse_idlocation_idcompany_idpicking_policyexpected_daterequested_byprocurement_group_id
Skipped when context contains
no_change_childs=Truestock_request/models/stock_request_order.py:289
Utility Methods
Returns all parent locations up to the root for the order’s location.Returns:
stock.location recordsetstock_request/models/stock_request_order.py:183
Provides default values for warehouse and location based on company.Decorator:
@api.modelBehavior:- Searches for a warehouse in the specified company
- Sets
location_idto warehouse’slot_stock_id
stock_request/models/stock_request_order.py:14
Constraints
SQL Constraints
Python Constraints
_check_warehouse_company
Validates that warehouse company matches order company.Constraint:
warehouse_id, company_idRaises: ValidationErrorstock_request/models/stock_request_order.py:362
_check_location_company
Validates that location company (if set) matches order company.Constraint:
location_id, company_idRaises: ValidationErrorstock_request/models/stock_request_order.py:374
Lifecycle
Create
Creates new stock request order records with auto-generated names.Decorator:
@api.model_create_multiBehavior:- Auto-generates
namefrom sequencestock.request.orderif not provided or equals ”/“
stock_request/models/stock_request_order.py:345
Unlink
Deletes stock request order records.Raises:
UserError if any record is not in draft statestock_request/models/stock_request_order.py:357
Special Methods
Create From Product Multiselect
Creates a stock request order from a multi-selection of products.Decorator:
@api.modelParameters:products- Recordset ofproduct.productorproduct.template
ValidationError if called outside product contextBehavior:- Creates one stock request per product with quantity 1.0
- Uses default expected date
- Opens the created order in form view
stock_request/models/stock_request_order.py:388
Usage Example
See Also
- stock.request - Individual stock request within an order
- stock.request.allocation - Allocation linking requests to stock moves
- stock.request.abstract - Base abstract model
