list orders

This commit is contained in:
Phuoc Nguyen
2025-11-24 16:25:54 +07:00
parent 354df3ad01
commit 75d6507719
24 changed files with 1004 additions and 982 deletions

View File

@@ -129,6 +129,42 @@ curl --location 'https://land.dbiz.com//api/method/upload_file' \
--form 'optimize="true"'
#get list order
curl --location 'https://land.dbiz.com//api/method/building_material.building_material.api.sales_order.get_list' \
--header 'Cookie: sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; full_name=Ha%20Duy%20Lam; sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; system_user=yes; user_id=lamhd%40gmail.com; user_image=/files/avatar_0986788766_1763627962.jpg' \
--header 'X-Frappe-Csrf-Token: 6ff3be4d1f887dbebf86ba4502b05d94b30c0b0569de49b74a7171a9' \
--header 'Content-Type: application/json' \
--data '{
"limit_start" : 0,
"limit_page_length" : 0
}'
#response list order
{
"message": [
{
"name": "SAL-ORD-2025-00107",
"transaction_date": "2025-11-24",
"delivery_date": "2025-11-24",
"address": "123 add dad",
"grand_total": 3355443.2,
"status": "Chờ phê duyệt",
"status_color": "Warning"
},
{
"name": "SAL-ORD-2025-00106",
"transaction_date": "2025-11-24",
"delivery_date": "2025-11-24",
"address": "123 add dad",
"grand_total": 3355443.2,
"status": "Chờ phê duyệt",
"status_color": "Warning"
},
...
]
}
#order detail
curl --location 'https://land.dbiz.com//api/method/building_material.building_material.api.sales_order.get_detail' \
--header 'Cookie: sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d; sid=a0cbe3ea6f9a7e9cf083bbe3139eada68d2357eac0167bcc66cda17d' \

View File

@@ -0,0 +1,81 @@
# Order Model API Integration Update
## Summary
Updated OrderModel and orders_provider to match the simplified API response structure from the ERPNext/Frappe backend.
## API Response Structure
```json
{
"message": [
{
"name": "SAL-ORD-2025-00107",
"transaction_date": "2025-11-24",
"delivery_date": "2025-11-24",
"address": "123 add dad",
"grand_total": 3355443.2,
"status": "Chờ phê duyệt",
"status_color": "Warning"
}
]
}
```
## Changes Made
### 1. OrderModel (`lib/features/orders/data/models/order_model.dart`)
**New Fields Added:**
- `statusColor` (HiveField 18): Stores API status color (Warning, Success, Danger, etc.)
- `transactionDate` (HiveField 19): Transaction date from API
- `addressString` (HiveField 20): Simple string address from API
**Updated Methods:**
- `fromJson()`: Made fields more nullable, added new field mappings
- `toJson()`: Added new fields to output
- Constructor: Added new optional parameters
### 2. Orders Provider (`lib/features/orders/presentation/providers/orders_provider.dart`)
**API Field Mapping:**
```dart
{
'order_id': json['name'],
'order_number': json['name'],
'status': _mapStatusFromApi(json['status']),
'total_amount': json['grand_total'],
'final_amount': json['grand_total'],
'expected_delivery_date': json['delivery_date'],
'transaction_date': json['transaction_date'],
'address_string': json['address'],
'status_color': json['status_color'],
'created_at': json['transaction_date'],
}
```
**Status Mapping:**
- "Chờ phê duyệt" / "Pending approval" → `pending`
- "Đang xử lý" / "Processing" → `processing`
- "Đang giao" / "Shipped" → `shipped`
- "Hoàn thành" / "Completed" → `completed`
- "Đã hủy" / "Cancelled" / "Rejected" → `cancelled`
### 3. Order Card Widget (`lib/features/orders/presentation/widgets/order_card.dart`)
**Display Updates:**
- Uses `transactionDate` if available, falls back to `createdAt`
- Uses `addressString` directly from API instead of parsing JSON
## Benefits
1. **Simpler mapping**: Direct field mapping without complex transformations
2. **API consistency**: Matches actual backend response structure
3. **Better performance**: No need to parse JSON addresses for list view
4. **Status colors**: API-provided colors ensure UI consistency with backend
## API Endpoint
```
POST /api/method/building_material.building_material.api.sales_order.get_list
Body: { "limit_start": 0, "limit_page_length": 0 }
```
## Testing Notes
- Ensure API returns all expected fields
- Verify Vietnamese status strings are correctly mapped
- Check that dates are in ISO format (YYYY-MM-DD)
- Confirm status_color values match StatusColor enum (Warning, Success, Danger, Info, Secondary)