{"record":{"id":"325de6c2c7ea25e9","repo":"aureuserp/aureuserp","slug":"blocking-implode-have-default-source-or","errorCode":null,"errorMessage":"{$blocking->implode(', ')} have default source or destination locations within warehouse {$warehouse->name}, therefore you cannot archive it.","messagePattern":"(.+?) have default source or destination locations within warehouse (.+?), therefore you cannot archive it\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"plugins/webkul/inventories/src/Models/Warehouse.php","lineNumber":309,"sourceCode":"            $blocking = OperationType::query()\n                ->whereDoesntHave('warehouse', fn ($q) => $q->whereKey($warehouse->id))\n                ->where(fn ($q) => $q\n                    ->whereIn('source_location_id', $childLocationIds)\n                    ->orWhereIn('destination_location_id', $childLocationIds))\n                ->where('deleted_at', null)\n                ->pluck('id');\n\n            $blocking = OperationType::where(\n                fn ($q) => $q\n                    ->whereIn('source_location_id', $childLocationIds)\n                    ->orWhereIn('destination_location_id', $childLocationIds)\n            )\n                ->whereNotIn('id', $operationTypes->pluck('id')->all())\n                ->get()\n                ->pluck('id');\n\n            if ($blocking->isNotEmpty()) {\n                throw new \\Exception(\"{$blocking->implode(', ')} have default source or destination locations within warehouse {$warehouse->name}, therefore you cannot archive it.\");\n            }\n\n            $viewLocation?->delete();\n\n            $rules = Rule::where('warehouse_id', $warehouse->id)->get();\n\n            $routes = $warehouse->routes\n                ->filter(fn ($route) => $route->warehouses()->withTrashed()->count() === 1);\n\n            $routes->each(fn ($route) => $route->delete());\n\n            $rules->each(fn ($rule) => $rule->delete());\n        });\n\n        static::forceDeleted(function (Warehouse $warehouse) {\n            $warehouse->viewLocation()->withTrashed()->first()?->forceDelete();\n        });\n","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/aureuserp/aureuserp/blob/bd7cbeeb0c620985dfd9b88c56be7f3ea86be6b4/plugins/webkul/inventories/src/Models/Warehouse.php#L291-L327","documentation":"Also on Warehouse's `deleted` event: after checking ongoing moves, it looks for OperationType records outside this warehouse whose default source_location_id or destination_location_id points inside the warehouse's location subtree. Those external references block archiving because the referenced locations are about to be removed.","triggerScenarios":"Deleting/archiving a warehouse while other operation types (belonging to other warehouses or global) use one of its locations (e.g. WH/Stock or children) as default source or destination. The message lists the blocking operation type ids.","commonSituations":"Cross-warehouse or transit operation types pointing at another warehouse's stock; operation types copied from templates that kept the old warehouse's locations; cleanup scripts deleting warehouses in the wrong order.","solutions":["Repoint each blocking operation type's default source/destination location to a location outside the deleted warehouse","Delete operation types that are unused instead of repointing them","Retry the warehouse deletion once no external references remain"],"exampleFix":"// before\n$warehouse->delete(); // throws: ids 5, 12 have default locations inside WH\n\n// after\nOperationType::whereIn('id', $blockingIds)->get()->each(function ($ot) use ($replacementLocation) {\n    $ot->update(['source_location_id' => $ot->source_location_id === null ? $ot->source_location_id : $replacementLocation->id]);\n});\n$warehouse->delete();","handlingStrategy":"validation","validationCode":"$childIds = Location::query()\n    ->whereRaw('parent_path LIKE ?', [$warehouse->viewLocation->parent_path.'%'])\n    ->pluck('id');\n$blocking = OperationType::where(fn ($q) => $q->whereIn('source_location_id', $childIds)->orWhereIn('destination_location_id', $childIds))\n    ->whereNotIn('id', $warehouse->operationTypes->pluck('id'))\n    ->count();\nif ($blocking > 0) {\n    abort(422, \"Repoint {$blocking} operation type(s) that default into this warehouse's locations.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $warehouse->delete();\n} catch (\\Exception $e) {\n    // message names blocking operation type ids: repoint their default locations, then retry\n    return back()->withErrors(['warehouse' => $e->getMessage()]);\n}","preventionTips":["Keep cross-warehouse operation types pointed at shared/transit locations, not another warehouse's tree","Before archiving a warehouse, audit OperationType rows referencing its locations","Delete warehouses in dependency order (children/custom types first)"],"tags":["inventory","warehouse","archive","operation-type","locations"],"backgroundTag":"delete-blocked-by-child-records","analyzedSha":"bd7cbeeb0c620985dfd9b88c56be7f3ea86be6b4","analyzedAt":"2026-08-21T06:41:00.338Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}