Warenwirtschaft: F-06 — Chargenzeilen nach Validierungsfehler aus old() wiederherstellen

Vorbelegung der Chargen-Zeilen zentral in ProductionController::existingLines();
old('ingredient_lines') hat Vorrang vor dem gespeicherten Stand.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-09-08 10:57:07 +00:00
parent a803e956e1
commit 122d28bc4f
5 changed files with 78 additions and 25 deletions

View file

@ -393,3 +393,35 @@ test('F-04: derselbe rohstoff in zwei phasen behält beim wiederöffnen je phase
->and($done->productionIngredients()->where('recipe_phase_id', $phaseB->id)->sum('quantity_used'))->toEqual(4)
->and((float) app(InventoryService::class)->remainingByIngredient([$ing->id])[$ing->id])->toBe(990.0);
});
test('F-06: nach einem validierungsfehler bleiben die eingegebenen chargenzeilen im formular erhalten', function () {
$user = draftUser();
$location = Location::factory()->create();
$supplier = Supplier::factory()->create();
$ing = draftIngredient();
$product = draftRecipeProduct($ing); // Soll 10 g
$stock = draftStock($ing, $location, $supplier, $user);
$key = $stock->batchGroupKey();
Passport::actingAs($user);
$this->actingAs($user, 'user');
// 20 g statt 10 g → Toleranzfehler beim Abschluss, Redirect zurück mit old().
$this->from(route('admin.inventory.productions.create'))
->post(route('admin.inventory.productions.store'), [
'save_mode' => 'complete',
'product_id' => $product->id, 'location_id' => $location->id, 'produced_at' => '2026-08-01', 'quantity' => 1,
'ingredient_lines' => [['ingredient_id' => $ing->id, 'batch_key' => $key, 'quantity_used' => '20,0']],
'outputs' => [['product_id' => $product->id, 'quantity' => 1, 'batch_number' => null]],
])
->assertRedirect(route('admin.inventory.productions.create'))
->assertSessionHasErrors('ingredient_lines');
$html = $this->get(route('admin.inventory.productions.create'))->assertOk()->getContent();
$start = strpos($html, 'var existingLines = ') + strlen('var existingLines = ');
$existing = json_decode(substr($html, $start, strpos($html, ';', $start) - $start), true);
expect($existing)->toHaveKey($ing->id.'|')
->and($existing[$ing->id.'|'][0]['batch_key'])->toBe($key)
->and($existing[$ing->id.'|'][0]['quantity_used'])->toBe('20,0');
});