[FIX] 修復所有 E2E 模組測試的標題定位器以及將測試帳號還原為 admin 權限
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 55s

This commit is contained in:
2026-03-09 16:53:06 +08:00
parent 2437aa2672
commit 197df3bec4
23 changed files with 593 additions and 89 deletions

View File

@@ -170,14 +170,18 @@ class ProductionOrderController extends Controller
// 2. 處理明細
if (!empty($request->items)) {
$itemsToInsert = [];
foreach ($request->items as $item) {
ProductionOrderItem::create([
$itemsToInsert[] = [
'production_order_id' => $productionOrder->id,
'inventory_id' => $item['inventory_id'],
'quantity_used' => $item['quantity_used'] ?? 0,
'unit_id' => $item['unit_id'] ?? null,
]);
'created_at' => now(),
'updated_at' => now(),
];
}
ProductionOrderItem::insert($itemsToInsert);
}
});
@@ -380,14 +384,18 @@ class ProductionOrderController extends Controller
$productionOrder->items()->delete();
if (!empty($request->items)) {
$itemsToInsert = [];
foreach ($request->items as $item) {
ProductionOrderItem::create([
$itemsToInsert[] = [
'production_order_id' => $productionOrder->id,
'inventory_id' => $item['inventory_id'],
'quantity_used' => $item['quantity_used'] ?? 0,
'unit_id' => $item['unit_id'] ?? null,
]);
'created_at' => now(),
'updated_at' => now(),
];
}
ProductionOrderItem::insert($itemsToInsert);
}
});
@@ -407,8 +415,16 @@ class ProductionOrderController extends Controller
}
DB::transaction(function () use ($newStatus, $productionOrder, $request) {
// 使用鎖定重新獲取單據,防止併發狀態修改
$productionOrder = ProductionOrder::where('id', $productionOrder->id)->lockForUpdate()->first();
$oldStatus = $productionOrder->status;
// 再次檢查狀態轉移(在鎖定後)
if (!$productionOrder->canTransitionTo($newStatus)) {
throw new \Exception('不合法的狀態轉移或權限不足');
}
// 1. 執行特定狀態的業務邏輯
if ($oldStatus === ProductionOrder::STATUS_APPROVED && $newStatus === ProductionOrder::STATUS_IN_PROGRESS) {
// 開始製作 -> 扣除原料庫存