Files
worker/docs/md/order_model_update_summary.md
Phuoc Nguyen 65f6f825a6 update md
2025-11-28 15:16:40 +07:00

2.8 KiB

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

{
    "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:

{
  '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)