| models | ||
| static/src/js | ||
| views | ||
| __init__.py | ||
| __manifest__.py | ||
| .gitignore | ||
| README.md | ||
Stock Restrict Source Location (Odoo 19 Stable)
This module implements a robust, context-aware stock location restriction strategy for Manufacturing Orders (MO) and Inventory Transfers. It ensures that users only select component lots and quants from authorized warehouse zones while maintaining absolute stability for backend reservations and record saving.
Key Features
- Dynamic Catalog Restriction: When "Adding a line" in an MO, the stock catalog is automatically filtered to show only inventory from your permitted source locations (e.g., Packaging, Preparation, Production).
- Sub-location Support: Uses the
child_ofoperator to ensure that stock in all sub-shelves/aisles within an allowed zone is correctly visible. - Null-Safe Guard: Includes a critical backend safety patch for
stock.move.linethat prevents "Missing product_id" validation errors during the cleanup of temporary/virtual records. - RPC Synchronized Loading: Uses a high-performance Javascript pre-fetch mechanism to retrieve allowed zones from the server before loading the UI.
- Lot Dropdown Filtering: Restricts the Lot dropdown selection to ensure only lots available in authorized zones are displayed.
Dependencies
stockmrpstock_picking_type_m2m(Provides theallowed_source_location_idsconfiguration on Operation Types)
Usage
- Configure: On an Operation Type (e.g., WHBK/Manufacturing), set the Allowed Source Locations (e.g., Packaging, Preparation).
- Operation: Create a Manufacturing Order using that Operation Type.
- Component Selection: In the "Components" tab, click "Add a line" or use the magnifier icon. The catalog will only show stock from the configured zones.
- Saving: Click "Save" on the component line. The system will process reservations normally without any validation errors.
Technical Implementation (V19 Stable)
Javascript (Frontend)
- Patches the
SMLX2ManyFieldcomponent. - Executes an RPC call to
get_allowed_locations_for_moto fetch authorized zone IDs. - Injects a custom
domainandcontext(reinforced withdefault_product_id) into theselectCreatemodal. - Includes a fail-safe fallback that defaults to the standard location if the server is unreachable.
Python (Backend)
StockMoveLine: Overridesunlink()to skip technical reservation updates for records missing aproduct_id. This prevents crashes during the disposal of temporary "virtual" records.StockLot: Overridesname_search()andweb_search_read()to ensure lot-only dropdowns are also restricted to allowed zones.StockLocation: Provides a publicget_allowed_locations_for_momethod for browser RPC accessibility.
Logging & Debugging
- All identification traces are logged at the ERROR level under the tag
DEBUG_RESTRICT. This ensures visibility in remote server consoles.