Branch-Warehouse Syncing
Dokumentasi lengkap untuk sync dan mapping branch dengan warehouse yang tersedia, termasuk support multiple warehouses per branch dengan priority system.π― Overview
Fitur branch-warehouse syncing memungkinkan:- β Auto-detect branch yang belum punya warehouse valid
- β List available warehouses untuk dipilih
- β Easy mapping via API
- β Multiple warehouses per branch (1 default + multiple backup)
- β Priority system untuk fallback inventory allocation
- β Monitoring dashboard untuk admin
π Database Schema
Table: branch_warehouses
Priority System
- 0 = Default warehouse (primary)
- 1 = Backup warehouse 1 (fallback pertama)
- 2 = Backup warehouse 2 (fallback kedua)
- 3+ = Backup warehouse berikutnya
π‘ API Endpoints
1. Get Branch Warehouse Status (Single Branch)
Cek status branch dan warehouse nya, apakah sudah ter-mapping atau belum.2. Get All Branches Warehouse Status
Cek status semua branch (untuk admin/dashboard monitoring).3. Sync Branch Warehouse (Single Mapping)
Mapping branch ke warehouse yang dipilih.4. Get Branch Warehouses (Multiple)
Get list semua warehouses untuk 1 branch (default + backups).5. Sync Branch Multiple Warehouses
Set multiple warehouses untuk 1 branch sekaligus (replace existing).π Use Cases
Use Case 1: Branch Belum Punya Warehouse
-
Cek status branch:
-
Response menunjukkan
needs_mapping: truedan listavailable_warehouses -
Pilih warehouse dan mapping:
- Branch sekarang sudah ter-mapping ke warehouse
Use Case 2: Setup Default + Backup Warehouses
Branch perlu setup 1 default warehouse dan 2 backup warehouses untuk redundancy.Use Case 3: Inventory Allocation Logic
Saat create transaction, sistem akan cek stock dengan priority: Implementation:Use Case 4: Monitoring Dashboard (Admin)
-
Get all branches status:
-
Dashboard menampilkan:
- β Branch yang sudah ter-mapping (hijau)
- β οΈ Branch yang needs mapping (kuning/merah)
- List available warehouses untuk mapping
- Admin bisa langsung mapping dari dashboard
π Response Fields Explanation
ResponseBranchWarehouseStatus
| Field | Type | Description |
|---|---|---|
branch_id | int64 | ID branch |
branch_code | string | Kode branch |
branch_name | string | Nama branch |
default_warehouse_id | int64 (nullable) | Warehouse ID yang ter-assign di branch |
warehouse_exists | boolean | Apakah warehouse ID tersebut exist di database |
warehouse_info | object (nullable) | Info warehouse jika sudah ter-mapping |
available_warehouses | array | List warehouse yang tersedia untuk mapping (hanya muncul jika needs_mapping: true) |
needs_mapping | boolean | Apakah branch perlu di-mapping ke warehouse |
WarehouseInfo
| Field | Type | Description |
|---|---|---|
id | int64 | Warehouse ID |
warehouse_code | string | Kode warehouse |
warehouse_name | string | Nama warehouse |
warehouse_type | string | Tipe: warehouse atau distribution_center |
π§ Integration Example
Frontend: Check & Fix Branch Warehouse
π Benefits
- β High Availability: Jika default warehouse stock habis, auto fallback ke backup
- β Flexibility: Bisa define berapa banyak backup warehouses sesuai kebutuhan
- β Clear Priority: Priority system yang jelas (0=default, 1+=backup)
- β Easy Management: Single API call untuk setup multiple warehouses
- β Redundancy: Mengurangi risk βstock tidak cukupβ dengan backup warehouses
- β Auto-detect: Sistem otomatis detect branch yang belum ter-mapping
- β Monitoring: Dashboard untuk admin monitoring status semua branch
β οΈ Important Notes
- Priority 0 wajib ada: Setiap branch harus punya minimal 1 warehouse dengan priority=0 (default)
- Unique constraint: 1 branch tidak boleh punya warehouse yang sama 2x
- Soft delete: Gunakan
deleted_atuntuk soft delete, jangan hard delete - Backward compatible: Existing
branches.default_warehouse_idtetap bisa digunakan sebagai fallback
π Testing
Postman Collection
π Related Documentation
Inventory Flow
Inventory management & warehouse stocks
Transaction Flow
Transaction creation & inventory consumption
Database ERD
Complete database schema
Need Help? Contact backend team atau check GitHub Issues