Overview
Thestock.request.abstract model is an abstract model that provides common fields, computed fields, constraints, and business logic shared by both stock.request and stock.request.order models. It cannot be instantiated directly but serves as a foundation for concrete models.
Model Name: stock.request.abstract
Type: Abstract Model
Inherits: mail.thread, mail.activity.mixin
Fields
Core Fields
Unique identifier for the record.Properties:
copy=False, required=True, readonly=True, default="/"Typically auto-generated from a sequence in concrete models.Location & Warehouse Fields
Reference to
stock.warehouse. The warehouse where stock is requested or stored.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 for this record.Related:
company_id.stock_request_allow_virtual_locProperties: readonly=TrueProduct Fields
Reference to
product.product. The product being requested.Domain: [('type', 'in', ['product', 'consu'])]Properties: ondelete="cascade", required=TrueOnly storable and consumable products are allowed.Reference to
uom.category. The allowed UoM category for this product.Related: product_id.uom_id.category_idReference to
uom.uom. Product unit of measure.Domain: [('category_id', '=?', allowed_uom_categ_id)]Properties: required=TrueDefault: From context product_uom_id if availableQuantity specified in the unit of measure indicated in the request.Digits:
Product Unit of MeasureProperties: required=TrueHelp: Quantity, specified in the unit of measure indicated in the request.Real quantity in the default UoM of the product.Properties:
compute="_compute_product_qty", store=True, copy=FalseDigits: Product Unit of MeasureHelp: Quantity in the default UoM of the productProcurement & Routing Fields
Reference to
procurement.group. Moves created through this stock request will be put in this procurement group.Help: If none is given, the moves generated by procurement rules will be grouped into one big picking.Reference to
stock.route. The route to use for procurement.Domain: [('id', 'in', route_ids)]Properties: ondelete="restrict"Reference to
stock.route records. Available routes based on product, warehouse, and location.Properties: compute="_compute_route_ids", readonly=TrueCompany Field
Reference to
res.company. The company this record belongs to.Default: self.env.companyProperties: required=TrueMethods
Compute Methods
Converts product quantity from request UoM to product’s default UoM.Depends on:
product_idproduct_uom_idproduct_uom_qtyproduct_id.product_tmpl_id.uom_id
- Uses UoM conversion with
HALF-UProunding - Converts from
product_uom_idto product template’s base UoM
stock_request/models/stock_request_abstract.py:26
Computes available routes based on product, warehouse, and location.Depends on:
product_id, warehouse_id, location_idLogic:- Gets routes from product (direct and category routes)
- Gets routes from warehouse
- Filters routes where any rule’s destination location is a parent of
location_id - Returns union of matching routes
stock_request/models/stock_request_abstract.py:116
Utility Methods
Returns all parent locations up to the root for the record’s location.Returns:
stock.location recordset containing the location and all its parentsBehavior:- Starts with
location_id - Recursively adds parent locations via
location_idfield - Returns full hierarchy from location to root
stock_request/models/stock_request_abstract.py:141
Provides default values for warehouse and location based on company.Decorator:
@api.modelBehavior:- Searches for a warehouse in the specified company
- Sets
warehouse_idandlocation_id(to warehouse’slot_stock_id)
stock_request/models/stock_request_abstract.py:13
Onchange Methods
Updates location and company when warehouse changes.Decorator:
@api.onchange("warehouse_id")Behavior:- Updates
location_idto warehouse’slot_stock_idif warehouse changed - Updates
company_idif warehouse company differs - Skips for
stock.requestrecords with anorder_id(handled at order level)
stock_request/models/stock_request_abstract.py:210
Updates warehouse when location changes.Decorator:
@api.onchange("location_id")Behavior:- If location has a warehouse, updates
warehouse_idto match - Calls
onchange_warehouse_id()with context to prevent child updates
stock_request/models/stock_request_abstract.py:226
Sets a default warehouse when the company is changed.Decorator:
@api.onchange("company_id")Behavior:- Searches for a warehouse in the new company
- Calls
onchange_warehouse_id()to update related fields
stock_request/models/stock_request_abstract.py:234
Sets the product’s default UoM when product changes.Decorator:
@api.onchange("product_id")stock_request/models/stock_request_abstract.py:250
Constraints
SQL Constraints
Python Constraints
_check_company_constrains
Validates that related models belong to the same company.Constraint:
company_id, product_id, warehouse_id, location_id, route_idChecks:- Product company (if set) must match record company
- Location company (if set) must match record company
- Warehouse company must match record company
- Route company (if set) must match record company
ValidationError with specific message for each mismatchstock_request/models/stock_request_abstract.py:149
_check_product_uom
Validates that the UoM category matches the product’s UoM category.Constraint:
product_idRule: product_id.uom_id.category_id must equal product_uom_id.category_idRaises: ValidationErrorstock_request/models/stock_request_abstract.py:194
Field Behaviors
UoM Handling
The abstract model handles unit of measure conversions:Route Filtering
Routes are filtered based on multiple criteria:Location Hierarchy
Theget_parents() method is used for route filtering:
Domain Specifications
Product Domain
Domain:
[('type', 'in', ['product', 'consu'])]Only allows:product- Storable products (tracked inventory)consu- Consumable products (not tracked, but can be requested)
service- Service products (no inventory)
Location Domain
Domain:
[('usage', 'in', ['internal', 'transit'])] (when virtual locations not allowed)Allows:internal- Internal locations (normal warehouse locations)transit- Transit locations (inter-warehouse transfers)
allow_virtual_location settingUoM Domain
Domain:
[('category_id', '=?', allowed_uom_categ_id)]Restricts UoM selection to the same category as the product’s base UoM.Example: If product uses “Units” (category: Unit), can select “Units”, “Dozens”, “Dozens”, but not “kg” or “Liters”Route Domain
Domain:
[('id', 'in', route_ids)]Restricts route selection to computed available routes based on product, warehouse, and location.Usage in Inheritance
Concrete Models
Two models inherit from this abstract model:Actually, looking at the code,
stock.request.order does NOT inherit from stock.request.abstract. It defines its own similar fields. Only stock.request inherits from the abstract model.Shared Logic
The abstract model provides shared logic for:- UoM conversion via
_compute_product_qty() - Route computation via
_compute_route_ids() - Company constraints via
_check_company_constrains() - Onchange handlers for warehouse, location, company, product
See Also
- stock.request - Main concrete implementation
- stock.request.order - Order grouping (has similar fields but doesn’t inherit)
- stock.request.allocation - Links requests to moves
