Overview
Thestock.request model represents an individual stock request in the system. It inherits from stock.request.abstract and manages the lifecycle of requests from draft through to completion, including procurement rule execution, allocation tracking, and integration with Odoo’s stock moves and pickings.
Model Name: stock.request
Inherits: stock.request.abstract, mail.thread, mail.activity.mixin
Order: id desc
Fields
Core Fields
Unique identifier for the stock request. Auto-generated from sequence
stock.request if not provided.Current status of the stock request.Options:
draft- Draftopen- In progressdone- Donecancel- Cancelled
copy=False, default="draft", index=True, readonly=True, tracking=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.Properties:
index=True, required=TrueDefines how products should be received.Options:
direct- Receive each product when availableone- Receive all products at once
"direct"Product & Quantity Fields
Reference to
product.product. The product being requested.Domain: [('type', 'in', ['product', 'consu'])]Inherited from: stock.request.abstractReference to
uom.uom. Product unit of measure.Inherited from: stock.request.abstractQuantity specified in the unit of measure indicated in the request.Digits:
Product Unit of MeasureInherited from: stock.request.abstractQuantity in progress (not yet completed).Properties:
readonly=True, compute="_compute_qty", store=TrueDigits: Product Unit of MeasureQuantity completed.Properties:
readonly=True, compute="_compute_qty", store=TrueDigits: Product Unit of MeasureQuantity cancelled.Properties:
readonly=True, compute="_compute_qty", store=TrueDigits: Product Unit of MeasureLocation & Warehouse Fields
Reference to
stock.warehouse. The warehouse where stock is requested.Inherited from: stock.request.abstractReference to
stock.location. The specific location within the warehouse.Domain: [('usage', 'in', ['internal', 'transit'])] (when virtual locations not allowed)Inherited from: stock.request.abstractProcurement & Routing Fields
Reference to
stock.route. The route to use for procurement.Domain: [('id', 'in', route_ids)]Inherited from: stock.request.abstractReference to
procurement.group. Moves created through this stock request will be put in this procurement group.Inherited from: stock.request.abstractRelational Fields
Reference to
stock.request.order. The parent order if this request is part of an order.Properties: readonly=TrueReference to
stock.request.allocation records with inverse_name="stock_request_id".Links to all allocations associated with this stock request.Reference to
stock.move records.Properties: compute="_compute_move_ids", readonly=TrueAll stock moves related to this request (including origin moves).Reference to
stock.picking records.Properties: compute="_compute_picking_ids", readonly=TrueAll pickings associated with this stock request.Number of delivery orders/pickings.Properties:
compute="_compute_picking_ids", readonly=TrueReference to
res.company. The company this request belongs to.Inherited from: stock.request.abstractMethods
Action Methods
Confirms the stock request and launches procurement rules.Returns:
TrueBehavior:- Calls
_action_confirm()internally - Changes state from
drafttoopen - Triggers procurement rule execution via
_action_launch_procurement_rule()
stock_request/models/stock_request.py:268
Resets the stock request to draft state.Returns:
Truestock_request/models/stock_request.py:272
Cancels the stock request and all associated stock moves.Returns:
TrueBehavior:- Cancels all related stock moves using
sudo() - Sets state to
cancel
stock_request/models/stock_request.py:276
Marks the stock request as done.Returns:
Truestock_request/models/stock_request.py:281
Opens the transfer/picking view for this stock request.Returns:
dict - Action dictionary for viewing pickingsBehavior:- Shows tree view if multiple pickings
- Shows form view if single picking
stock_request/models/stock_request.py:442
Procurement Methods
Prepares values for procurement group execution.Parameters:
group_id(int/bool, optional) - Procurement group ID
dict - Values dictionary for procurementKeys in returned dict:date_planned: Expected date for the procurementwarehouse_id: Target warehousestock_request_allocation_ids: ID of this stock requestgroup_id: Procurement group IDroute_ids: Route to usestock_request_id: ID of this stock request
stock_request/models/stock_request.py:321
Launches procurement rules to fulfill the stock request.Returns:
TrueRaises: UserError if procurement failsBehavior:- Skips if state is not
draftor product type is not storable - Checks if stock is available first (if company setting enabled)
- Creates procurement group request
- Executes procurement rules (
_run_move,_run_buy, or_run_manufacture)
If
company_id.stock_request_check_available_first is enabled and sufficient stock is available in the location, it will use available stock instead of creating procurement.stock_request/models/stock_request.py:381
Creates stock moves for available stock and marks them as done.Behavior:
- Gathers available quants from the location
- Creates stock moves for available quantities
- Confirms and immediately completes the moves
- Creates allocations linking moves to the request
stock_request/models/stock_request.py:360
Preparation Methods
Prepares values for creating a stock move.Parameters:
qty(float) - Quantity for the move
dict - Values for stock move creationKeys in returned dict:name: Product display namecompany_id: Company IDproduct_id: Product IDproduct_uom_qty: Quantityproduct_uom: Product UoM IDlocation_id: Source location IDlocation_dest_id: Destination location IDstate: Move state (“draft”)reference: Stock request name
stock_request/models/stock_request.py:340
Prepares values for creating a stock request allocation.Parameters:
move(stock.move) - The stock move record
dict - Values for allocation creationstock_request/models/stock_request.py:353
Status Check Methods
Checks if the stock request should be marked as done.Returns:
TrueBehavior:- Compares allocated quantity with requested quantity
- Automatically calls
action_done()if fully allocated - Calls
write({"state": "cancel"})if cancelled but not fulfilled
stock_request/models/stock_request.py:290
Checks if the stock request should be cancelled.Behavior:
- Calls
_check_cancel_allocation()to determine if cancellation is appropriate - Automatically sets state to
cancelif conditions are met
stock_request/models/stock_request.py:285
Compute Methods
Computes all stock moves related to this request, including origin moves.Depends on:
allocation_ids, allocation_ids.stock_move_idstock_request/models/stock_request.py:133
Computes all pickings related to this request.Depends on:
allocation_ids, allocation_ids.stock_move_id, allocation_ids.stock_move_id.picking_idstock_request/models/stock_request.py:142
Computes quantity fields:
qty_done, qty_in_progress, and qty_cancelled.Depends on:allocation_idsallocation_ids.stock_move_id.stateallocation_ids.stock_move_id.move_line_idsallocation_ids.stock_move_id.move_line_ids.quantity
qty_done: Absolute difference between incoming and outgoing allocated quantitiesqty_in_progress: Sum of open product quantities from allocationsqty_cancelled: Remaining quantity that won’t be fulfilled
stock_request/models/stock_request.py:156
Constraints
SQL Constraints
Python Constraints
_check_qty
Validates product quantity based on state.Constraint:
state, product_qtyRules:- In
draftstate: quantity must be strictly positive (> 0) - In other states: quantity cannot be negative (>= 0)
ValidationErrorcheck_order_requested_by
Ensures
requested_by matches the parent order’s requested_by.Constraint: order_id, requested_byRaises: ValidationErrorcheck_order_warehouse_id
Ensures
warehouse_id matches the parent order’s warehouse_id.Constraint: order_id, warehouse_idRaises: ValidationErrorcheck_order_location
Ensures
location_id matches the parent order’s location_id.Constraint: order_id, location_idRaises: ValidationErrorcheck_order_procurement_group
Ensures
procurement_group_id matches the parent order’s procurement_group_id.Constraint: order_id, procurement_group_idRaises: ValidationErrorcheck_order_company
Ensures
company_id matches the parent order’s company_id.Constraint: order_id, company_idRaises: ValidationErrorcheck_order_expected_date
Ensures
expected_date matches the parent order’s expected_date.Constraint: order_id, expected_dateRaises: ValidationErrorcheck_order_picking_policy
Ensures
picking_policy matches the parent order’s picking_policy.Constraint: order_id, picking_policyRaises: ValidationErrorLifecycle
Create
Creates new stock request records with auto-generated names and expected dates.Decorator:
@api.model_create_multiBehavior:- Auto-generates
namefrom sequencestock.requestif not provided or equals ”/” - Sets
expected_datefrom order iforder_idis provided, otherwise uses_get_expected_date()
stock_request/models/stock_request.py:454
Unlink
Deletes stock request records.Raises:
UserError if any record is not in draft statestock_request/models/stock_request.py:469
Usage Example
See Also
- stock.request.order - Parent order grouping multiple requests
- stock.request.allocation - Allocation linking requests to stock moves
- stock.request.abstract - Base abstract model
