f1cf8f4b95
Inventory/InventoryLog fromJson 从嵌套对象读取字段: warehouse['name']、product['name'/'code'/'spec'/'unit'/'brand'/'min_stock'] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
93 lines
2.8 KiB
Dart
93 lines
2.8 KiB
Dart
class Inventory {
|
|
final int warehouseId;
|
|
final String? warehouseName;
|
|
final int productId;
|
|
final String? productName;
|
|
final String? productCode;
|
|
final String? productSpec;
|
|
final String? productUnit;
|
|
final String? productBrand;
|
|
final int? minStock;
|
|
final double quantity;
|
|
|
|
const Inventory({
|
|
required this.warehouseId,
|
|
this.warehouseName,
|
|
required this.productId,
|
|
this.productName,
|
|
this.productCode,
|
|
this.productSpec,
|
|
this.productUnit,
|
|
this.productBrand,
|
|
this.minStock,
|
|
required this.quantity,
|
|
});
|
|
|
|
factory Inventory.fromJson(Map<String, dynamic> json) {
|
|
final warehouse = json['warehouse'] as Map<String, dynamic>?;
|
|
final product = json['product'] as Map<String, dynamic>?;
|
|
return Inventory(
|
|
warehouseId: (json['warehouse_id'] as num).toInt(),
|
|
warehouseName: warehouse?['name'] as String?,
|
|
productId: (json['product_id'] as num).toInt(),
|
|
productName: product?['name'] as String?,
|
|
productCode: product?['code'] as String?,
|
|
productSpec: product?['spec'] as String?,
|
|
productUnit: product?['unit'] as String?,
|
|
productBrand: product?['brand'] as String?,
|
|
minStock: product?['min_stock'] != null
|
|
? (product!['min_stock'] as num).toInt()
|
|
: null,
|
|
quantity: (json['quantity'] as num).toDouble(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class InventoryLog {
|
|
final int warehouseId;
|
|
final String? warehouseName;
|
|
final int productId;
|
|
final String? productName;
|
|
final String direction; // in | out
|
|
final double quantity;
|
|
final double? qtyBefore;
|
|
final double? qtyAfter;
|
|
final String? refType;
|
|
final int? refId;
|
|
final String? createdAt;
|
|
|
|
const InventoryLog({
|
|
required this.warehouseId,
|
|
this.warehouseName,
|
|
required this.productId,
|
|
this.productName,
|
|
required this.direction,
|
|
required this.quantity,
|
|
this.qtyBefore,
|
|
this.qtyAfter,
|
|
this.refType,
|
|
this.refId,
|
|
this.createdAt,
|
|
});
|
|
|
|
factory InventoryLog.fromJson(Map<String, dynamic> json) => InventoryLog(
|
|
warehouseId: (json['warehouse_id'] as num).toInt(),
|
|
warehouseName: (json['warehouse'] as Map<String, dynamic>?)?['name'] as String?,
|
|
productId: (json['product_id'] as num).toInt(),
|
|
productName: (json['product'] as Map<String, dynamic>?)?['name'] as String?,
|
|
direction: json['direction'] as String,
|
|
quantity: (json['quantity'] as num).toDouble(),
|
|
qtyBefore: json['qty_before'] != null
|
|
? (json['qty_before'] as num).toDouble()
|
|
: null,
|
|
qtyAfter: json['qty_after'] != null
|
|
? (json['qty_after'] as num).toDouble()
|
|
: null,
|
|
refType: json['ref_type'] as String?,
|
|
refId: json['ref_id'] != null
|
|
? (json['ref_id'] as num).toInt()
|
|
: null,
|
|
createdAt: json['created_at'] as String?,
|
|
);
|
|
}
|