66e54af8c6
后端: - feat(backend): 重命名 Batches→Products 接口,新增库存状态(在售/已卖出)和买家信息 - feat(backend): 出库单创建/提交时校验仓库库存,不足则返回明确错误信息 - fix(backend): 出库创建 status 判断逻辑修复(空值默认 draft) 前端: - feat(client): 批次追踪改为商品追踪,新增状态列(在售/已卖出)和买家/时间列 - fix(client): 无批次号时显示"无批次"而非空 - refactor(client): BatchRecord → ProductTrackingRecord,repository 接口更新 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
165 lines
5.1 KiB
Dart
165 lines
5.1 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 ProductTrackingRecord {
|
|
final int id;
|
|
final int productId;
|
|
final String? productName;
|
|
final String? productCode;
|
|
final String? productSpec;
|
|
final String? productUnit;
|
|
final String? batchNo;
|
|
final double quantity;
|
|
final double unitPrice;
|
|
final String? orderNo;
|
|
final String? orderDate;
|
|
final String? warehouseName;
|
|
final String? supplierName;
|
|
// 库存状态
|
|
final double currentQty;
|
|
final String status; // in_stock | sold_out
|
|
final String? buyerName;
|
|
final String? soldAt;
|
|
|
|
const ProductTrackingRecord({
|
|
required this.id,
|
|
required this.productId,
|
|
this.productName,
|
|
this.productCode,
|
|
this.productSpec,
|
|
this.productUnit,
|
|
this.batchNo,
|
|
required this.quantity,
|
|
required this.unitPrice,
|
|
this.orderNo,
|
|
this.orderDate,
|
|
this.warehouseName,
|
|
this.supplierName,
|
|
required this.currentQty,
|
|
required this.status,
|
|
this.buyerName,
|
|
this.soldAt,
|
|
});
|
|
|
|
bool get isSoldOut => status == 'sold_out';
|
|
|
|
factory ProductTrackingRecord.fromJson(Map<String, dynamic> json) {
|
|
final product = json['product'] as Map<String, dynamic>?;
|
|
final order = json['order'] as Map<String, dynamic>?;
|
|
final warehouse = order?['warehouse'] as Map<String, dynamic>?;
|
|
final partner = order?['partner'] as Map<String, dynamic>?;
|
|
return ProductTrackingRecord(
|
|
id: (json['id'] as num).toInt(),
|
|
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?,
|
|
batchNo: json['batch_no'] as String?,
|
|
quantity: (json['quantity'] as num).toDouble(),
|
|
unitPrice: (json['unit_price'] as num).toDouble(),
|
|
orderNo: order?['order_no'] as String?,
|
|
orderDate: order?['order_date'] as String?,
|
|
warehouseName: warehouse?['name'] as String?,
|
|
supplierName: partner?['name'] as String?,
|
|
currentQty: json['current_qty'] != null
|
|
? (json['current_qty'] as num).toDouble()
|
|
: 0,
|
|
status: json['status'] as String? ?? 'in_stock',
|
|
buyerName: json['buyer_name'] as String?,
|
|
soldAt: json['sold_at'] as String?,
|
|
);
|
|
}
|
|
}
|
|
|
|
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?,
|
|
);
|
|
}
|