Skip to main content

Overview

The Stock Request framework extends the standard Odoo stock.picking model to provide visibility into which stock requests are associated with a picking. This enables users to track the relationship between pickings and the stock requests they fulfill.

Model Information

_inherit
string
stock.picking
_name
string
stock.picking

Fields

Stock Request Module

stock_request_ids
One2many
Computed field that returns all stock requests linked to this picking through its moves.
stock_request_count
Integer
Number of stock requests associated with this picking. Used for displaying smart buttons in the UI.

Stock Return Request Module

stock_return_request_id
Many2one
Links this picking to a stock return request when the picking is created as part of a return process.

Methods

Stock Request Module

_compute_stock_request_ids
method
Computes both the stock_request_ids and stock_request_count fields by aggregating stock requests from all moves in the picking.Depends on: move_ids
@api.depends("move_ids")
def _compute_stock_request_ids(self):
    for rec in self:
        rec.stock_request_ids = rec.move_ids.mapped("stock_request_ids")
        rec.stock_request_count = len(rec.stock_request_ids)
action_view_stock_request
method
Action method to view stock requests associated with this picking. Opens either a list view (if multiple requests) or a form view (if single request).Returns: Dictionary representing an ir.actions.act_window action
def action_view_stock_request(self):
    """
    :return dict: dictionary value for created view
    """
    action = self.env["ir.actions.act_window"]._for_xml_id(
        "stock_request.action_stock_request_form"
    )

    requests = self.mapped("stock_request_ids")
    if len(requests) > 1:
        action["domain"] = [("id", "in", requests.ids)]
    elif requests:
        action["views"] = [
            (self.env.ref("stock_request.view_stock_request_form").id, "form")
        ]
        action["res_id"] = requests.id
    return action
This method is typically called from a smart button in the picking form view to navigate to related stock requests.

Stock Return Request Module

_create_backorder
method
Extends the backorder creation to ensure that backorders inherit the stock_return_request_id from their parent picking.Returns: Recordset of created backorders
def _create_backorder(self):
    """When we make a backorder of a picking in a return request, we
    want to have it linked to the return request itself"""
    backorders = super()._create_backorder()
    rbo = backorders.filtered("backorder_id.stock_return_request_id")
    for backorder in rbo:
        backorder.stock_return_request_id = (
            backorder.backorder_id.stock_return_request_id
        )
    return backorders
This ensures continuity of the return request link when a picking is partially processed and a backorder is created.

Usage Examples

Accessing Stock Requests from a Picking

# Get all stock requests linked to a picking
picking = self.env['stock.picking'].browse(picking_id)
stock_requests = picking.stock_request_ids

# Get the count of stock requests
request_count = picking.stock_request_count

Opening Stock Requests View

# Open the stock requests view from a picking
picking = self.env['stock.picking'].browse(picking_id)
action = picking.action_view_stock_request()
return action

Working with Return Request Pickings

# Check if a picking is linked to a return request
picking = self.env['stock.picking'].browse(picking_id)
if picking.stock_return_request_id:
    return_request = picking.stock_return_request_id
    # Process return request logic

Creating Backorders with Return Requests

# When processing a return picking partially
picking = self.env['stock.picking'].browse(picking_id)
if picking.stock_return_request_id:
    # Create backorder - it will automatically inherit the return request link
    backorder = picking._create_backorder()
    # The backorder.stock_return_request_id will be set automatically

Integration Points

Smart Buttons

The stock_request_count field is used to display a smart button in the picking form view. When clicked, it calls action_view_stock_request() to show the related stock requests.

Backorder Handling

When a picking linked to a return request is partially processed:
  1. A backorder is created using _create_backorder()
  2. The extension automatically links the backorder to the same return request
  3. This maintains traceability throughout the return process

Source Code References

  • Stock Request extensions: stock_request/models/stock_picking.py
  • Stock Return Request extensions: stock_return_request/models/stock_picking.py

Build docs developers (and LLMs) love