Warenwirtschaft: F-17 — Köln-Default zentral (Location::defaultId), auch beim Ausschuss, nur aktive Standorte
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
731b2461e2
commit
2859aa0dbb
4 changed files with 31 additions and 3 deletions
|
|
@ -41,8 +41,7 @@ class ProductionController extends Controller
|
|||
return redirect()->route('home');
|
||||
}
|
||||
|
||||
$defaultLocationId = Location::query()->where('name', 'like', '%öln%')->value('id')
|
||||
?? Location::query()->where('active', true)->first()?->id;
|
||||
$defaultLocationId = Location::defaultId();
|
||||
|
||||
$defaultProductId = (int) $request->query('product_id') ?: null;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,4 +28,17 @@ class Location extends Model
|
|||
'active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* AP-50 / Prüfung 08.09.2026 F-17: Standard-Lagerort für alle Erfassungsmasken
|
||||
* (Einkauf, Produktion, Ausschuss) — Köln, sofern aktiv; sonst der erste aktive
|
||||
* Standort. Inaktive Standorte stehen nicht zur Auswahl und werden nicht vorbelegt.
|
||||
*/
|
||||
public static function defaultId(): ?int
|
||||
{
|
||||
$id = static::query()->where('active', true)->where('name', 'like', '%öln%')->orderBy('id')->value('id')
|
||||
?? static::query()->where('active', true)->orderBy('name')->value('id');
|
||||
|
||||
return $id !== null ? (int) $id : null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@
|
|||
<select name="location_id" id="location_id" class="form-control @error('location_id') is-invalid @enderror" required>
|
||||
<option value="">{{ __('Bitte wählen') }}</option>
|
||||
@foreach ($locations as $loc)
|
||||
<option value="{{ $loc->id }}" @selected((string) old('location_id') === (string) $loc->id)>{{ $loc->name }}</option>
|
||||
<option value="{{ $loc->id }}" @selected((string) old('location_id', $defaultLocationId ?? '') === (string) $loc->id)>{{ $loc->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('location_id')
|
||||
|
|
|
|||
|
|
@ -266,3 +266,19 @@ test('chargen-endpoint liefert eingegangene chargen', function () {
|
|||
$response->assertSuccessful();
|
||||
$response->assertJsonFragment(['location_id' => $location->id]);
|
||||
});
|
||||
|
||||
test('F-17: ausschuss-formular belegt köln als lagerort vor, inaktives köln nicht', function () {
|
||||
$user = ap12MakeUser(7);
|
||||
$other = Location::factory()->create(['name' => 'Aachen', 'active' => true]);
|
||||
$koeln = Location::factory()->create(['name' => 'Köln', 'active' => true]);
|
||||
|
||||
$this->actingAs($user, 'user');
|
||||
$html = $this->get(route('admin.inventory.stock-disposals.create'))->assertOk()->getContent();
|
||||
expect($html)->toContain('value="'.$koeln->id.'" selected')
|
||||
->and(Location::defaultId())->toBe($koeln->id);
|
||||
|
||||
$koeln->forceFill(['active' => false])->save();
|
||||
expect(Location::defaultId())->toBe($other->id);
|
||||
$html = $this->get(route('admin.inventory.stock-disposals.create'))->assertOk()->getContent();
|
||||
expect($html)->toContain('value="'.$other->id.'" selected')->not->toContain('Köln');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue