# Stock Restrict Source Location This module implements targeted location filtering for Stock Moves and Manufacturing Orders, ensuring users can only pick components and stock from authorized source locations defined in the Operation Type. ## Features - **Surgical UI Filtering**: Restricts the "Pick From" (Quant) and "Lot/Serial Number" (Lot) selection in both standard Transfers and MO "Detailed Operations" dialogs. - **Backend Sync Safety**: Specifically designed to bypass restrictions for background Odoo operations (reservation, unreservation, record-linking) to prevent "Missing Product" validation errors. - **Context-Aware MO Support**: Handles the complex Manufacturing Order "Components" view by injecting the correct picking type and source location into the search context. - **Frontend Patch**: Includes a JavaScript patch to ensure location context is correctly passed from the UI to the backend search methods. ## Dependencies - `stock` - `mrp` - `stock_picking_type_m2m` (Used to configure the list of allowed locations on the Operation Type) ## Usage 1. **Configure**: On a **Picking Type** (Operation Type), set the **Allowed Source Locations** (M2M field). 2. **Operation**: Create an MO or Transfer using that Picking Type. 3. **Lot Selection**: When a user clicks to select a Lot or a Quant in the UI, the list will be filtered to only show availability from the allowed locations. 4. **Backend**: Odoo's internal "Check Availability" and "Save" processes will still function normally, ensuring that reservations are linked correctly to existing stock. ## Technical Implementation (V19) - Overrides `StockQuant` and `StockLot` `_search` methods with a **UI-only bypass**. - Only restricts queries that include UI indicators (like `params`, `search_view_ref`, or `bin_size`). - Bypasses restrictions for the system user (`uid=False`) and searches by direct ID to maintain ORM integrity.