aureuserp/aureuserp · error · Exception

{$blocking->implode(', ')} have default source or destinatio

Error message

{$blocking->implode(', ')} have default source or destination locations within warehouse {$warehouse->name}, therefore you cannot archive it.

What it means

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.

Source

Thrown at plugins/webkul/inventories/src/Models/Warehouse.php:309

            $blocking = OperationType::query()
                ->whereDoesntHave('warehouse', fn ($q) => $q->whereKey($warehouse->id))
                ->where(fn ($q) => $q
                    ->whereIn('source_location_id', $childLocationIds)
                    ->orWhereIn('destination_location_id', $childLocationIds))
                ->where('deleted_at', null)
                ->pluck('id');

            $blocking = OperationType::where(
                fn ($q) => $q
                    ->whereIn('source_location_id', $childLocationIds)
                    ->orWhereIn('destination_location_id', $childLocationIds)
            )
                ->whereNotIn('id', $operationTypes->pluck('id')->all())
                ->get()
                ->pluck('id');

            if ($blocking->isNotEmpty()) {
                throw new \Exception("{$blocking->implode(', ')} have default source or destination locations within warehouse {$warehouse->name}, therefore you cannot archive it.");
            }

            $viewLocation?->delete();

            $rules = Rule::where('warehouse_id', $warehouse->id)->get();

            $routes = $warehouse->routes
                ->filter(fn ($route) => $route->warehouses()->withTrashed()->count() === 1);

            $routes->each(fn ($route) => $route->delete());

            $rules->each(fn ($rule) => $rule->delete());
        });

        static::forceDeleted(function (Warehouse $warehouse) {
            $warehouse->viewLocation()->withTrashed()->first()?->forceDelete();
        });

View on GitHub (pinned to bd7cbeeb0c)

Solutions

  1. Repoint each blocking operation type's default source/destination location to a location outside the deleted warehouse
  2. Delete operation types that are unused instead of repointing them
  3. Retry the warehouse deletion once no external references remain

Example fix

// before
$warehouse->delete(); // throws: ids 5, 12 have default locations inside WH

// after
OperationType::whereIn('id', $blockingIds)->get()->each(function ($ot) use ($replacementLocation) {
    $ot->update(['source_location_id' => $ot->source_location_id === null ? $ot->source_location_id : $replacementLocation->id]);
});
$warehouse->delete();
Defensive patterns

Strategy: validation

Validate before calling

$childIds = Location::query()
    ->whereRaw('parent_path LIKE ?', [$warehouse->viewLocation->parent_path.'%'])
    ->pluck('id');
$blocking = OperationType::where(fn ($q) => $q->whereIn('source_location_id', $childIds)->orWhereIn('destination_location_id', $childIds))
    ->whereNotIn('id', $warehouse->operationTypes->pluck('id'))
    ->count();
if ($blocking > 0) {
    abort(422, "Repoint {$blocking} operation type(s) that default into this warehouse's locations.");
}

Try / catch

try {
    $warehouse->delete();
} catch (\Exception $e) {
    // message names blocking operation type ids: repoint their default locations, then retry
    return back()->withErrors(['warehouse' => $e->getMessage()]);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of aureuserp/aureuserp@bd7cbeeb0c (2026-08-21). Data as JSON: /api/errors/325de6c2c7ea25e9. Report an issue: GitHub.