e892ab45b2
入库/出库明细 fromJson 改为优先取明细行自身的 product_code/name/series/spec 快照列,回退到 product 关联。历史导入单 product_id 为占位、无 product join, 靠快照列正常展示商品信息;App 新建单据仍走 product 关联,行为不变。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
153 lines
5.2 KiB
Dart
153 lines
5.2 KiB
Dart
class StockInItem {
|
|
final int? orderId;
|
|
final int productId;
|
|
final double quantity;
|
|
final double unitPrice;
|
|
final double totalPrice;
|
|
final String? batchNo;
|
|
final String? productionDate;
|
|
// Denormalized for display
|
|
final String? productName;
|
|
final String? productCode;
|
|
final String? productSeries;
|
|
final String? productSpec;
|
|
final String? productUnit;
|
|
final String? productOrigin;
|
|
final String? productShelfLife;
|
|
final String? productStorage;
|
|
|
|
const StockInItem({
|
|
this.orderId,
|
|
required this.productId,
|
|
required this.quantity,
|
|
required this.unitPrice,
|
|
required this.totalPrice,
|
|
this.batchNo,
|
|
this.productionDate,
|
|
this.productName,
|
|
this.productCode,
|
|
this.productSeries,
|
|
this.productSpec,
|
|
this.productUnit,
|
|
this.productOrigin,
|
|
this.productShelfLife,
|
|
this.productStorage,
|
|
});
|
|
|
|
factory StockInItem.fromJson(Map<String, dynamic> json) {
|
|
final product = json['product'] as Map<String, dynamic>?;
|
|
// 历史导入行 product_id=0、无 product 关联,商品信息存在明细行自身列上。
|
|
// 优先取明细行快照列,回退到 product 关联(App 新建单据走 product)。
|
|
String? lineOrProduct(String lineKey, String productKey) {
|
|
final line = json[lineKey] as String?;
|
|
if (line != null && line.isNotEmpty) return line;
|
|
return product?[productKey] as String?;
|
|
}
|
|
|
|
return StockInItem(
|
|
orderId: json['order_id'] != null
|
|
? (json['order_id'] as num).toInt()
|
|
: null,
|
|
productId: (json['product_id'] as num).toInt(),
|
|
quantity: (json['quantity'] as num).toDouble(),
|
|
unitPrice: (json['unit_price'] as num).toDouble(),
|
|
totalPrice: (json['total_price'] as num).toDouble(),
|
|
batchNo: json['batch_no'] as String?,
|
|
productionDate: json['production_date'] as String?,
|
|
productName: lineOrProduct('product_name', 'name'),
|
|
productCode: lineOrProduct('product_code', 'code'),
|
|
productSeries: lineOrProduct('series', 'series'),
|
|
productSpec: lineOrProduct('spec', 'spec'),
|
|
productUnit: (json['product'] as Map<String, dynamic>?)?['unit'] as String?,
|
|
productOrigin: ((json['product'] as Map<String, dynamic>?)?['origin']
|
|
as Map<String, dynamic>?)?['name'] as String?,
|
|
productShelfLife: ((json['product'] as Map<String, dynamic>?)?['shelf_life']
|
|
as Map<String, dynamic>?)?['name'] as String?,
|
|
productStorage: ((json['product'] as Map<String, dynamic>?)?['storage']
|
|
as Map<String, dynamic>?)?['name'] as String?,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'product_id': productId,
|
|
'quantity': quantity,
|
|
'unit_price': unitPrice,
|
|
'total_price': totalPrice,
|
|
if (batchNo != null) 'batch_no': batchNo,
|
|
if (productionDate != null) 'production_date': productionDate,
|
|
};
|
|
}
|
|
|
|
class StockInOrder {
|
|
final int id;
|
|
final String orderNo;
|
|
final String? type;
|
|
final int warehouseId;
|
|
final String? warehouseName;
|
|
final int? partnerId;
|
|
final String? partnerName;
|
|
final int? operatorId;
|
|
final String? operatorName;
|
|
final int? reviewerId;
|
|
final String? reviewerName;
|
|
final String status; // draft | pending | approved | rejected
|
|
final String? orderDate;
|
|
final String? reviewedAt;
|
|
final double? totalAmount;
|
|
final String? remark;
|
|
final List<StockInItem> items;
|
|
|
|
const StockInOrder({
|
|
required this.id,
|
|
required this.orderNo,
|
|
this.type,
|
|
required this.warehouseId,
|
|
this.warehouseName,
|
|
this.partnerId,
|
|
this.partnerName,
|
|
this.operatorId,
|
|
this.operatorName,
|
|
this.reviewerId,
|
|
this.reviewerName,
|
|
required this.status,
|
|
this.orderDate,
|
|
this.reviewedAt,
|
|
this.totalAmount,
|
|
this.remark,
|
|
this.items = const [],
|
|
});
|
|
|
|
factory StockInOrder.fromJson(Map<String, dynamic> json) => StockInOrder(
|
|
id: (json['id'] as num).toInt(),
|
|
orderNo: json['order_no'] as String,
|
|
type: json['type'] as String?,
|
|
warehouseId: (json['warehouse_id'] as num).toInt(),
|
|
warehouseName: (json['warehouse'] as Map<String, dynamic>?)?['name'] as String?,
|
|
partnerId: json['partner_id'] != null
|
|
? (json['partner_id'] as num).toInt()
|
|
: null,
|
|
partnerName: (json['partner'] as Map<String, dynamic>?)?['name'] as String?,
|
|
operatorId: json['operator_id'] != null
|
|
? (json['operator_id'] as num).toInt()
|
|
: null,
|
|
operatorName: (json['operator'] as Map<String, dynamic>?)?['real_name'] as String?,
|
|
reviewerId: json['reviewer_id'] != null
|
|
? (json['reviewer_id'] as num).toInt()
|
|
: null,
|
|
reviewerName: (json['reviewer'] as Map<String, dynamic>?)?['real_name'] as String?,
|
|
status: json['status'] as String,
|
|
orderDate: json['order_date'] as String?,
|
|
reviewedAt: json['reviewed_at'] as String?,
|
|
totalAmount: json['total_amount'] != null
|
|
? (json['total_amount'] as num).toDouble()
|
|
: null,
|
|
remark: json['remark'] as String?,
|
|
items: json['items'] != null
|
|
? (json['items'] as List)
|
|
.map((e) =>
|
|
StockInItem.fromJson(e as Map<String, dynamic>))
|
|
.toList()
|
|
: [],
|
|
);
|
|
}
|