refactor: 調整倉庫自動建立機制,統一使用門市倉類型 (retail)
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Has been skipped
Koori-ERP-Deploy-System / deploy-production (push) Successful in 54s

This commit is contained in:
2026-02-23 13:49:36 +08:00
parent 6dd3396fb7
commit 62dcf04e95
2 changed files with 13 additions and 5 deletions

View File

@@ -599,11 +599,21 @@ class InventoryService implements InventoryServiceInterface
*/
public function findOrCreateWarehouseByName(string $warehouseName)
{
// 1. 優先查找名稱完全匹配且啟用的倉庫(不限類型)
$warehouse = Warehouse::where('name', $warehouseName)
->where('is_active', true)
->first();
if ($warehouse) {
return $warehouse;
}
// 2. 若找不到對應倉庫,則統一進入「整合銷售倉」(類型retail)
return Warehouse::firstOrCreate(
['name' => $warehouseName],
['name' => '整合銷售倉'],
[
'code' => 'SALES-' . strtoupper(bin2hex(random_bytes(4))),
'type' => 'system_sales',
'code' => 'INT-RETAIL-001',
'type' => 'retail',
'is_active' => true,
]
);