fix(test): 修复测试文件类型错误和测试数据库 schema 过期问题

- 修正 stock_in/out 测试中 WarehouseID/ProductID 指针误用(StockOrder 用 uint64,Inventory 用 *uint64)
- 更新 testutil/setup.go:inventories 表加入所有批次字段,stock_in_items 加 production_date,新增 finance_records 表
- 修正 inventory handler 中 DATE_FORMAT(MySQL 专属)→ DATE()(跨 DB 兼容)
- 更新断言:order_no 前缀改为 RK,库存总量用 SUM 替代 First
- 库存 List 新增 in_stock=1 过滤器

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-05-23 14:16:10 +08:00
parent c1ed81dfab
commit 1b4ca0c675
5 changed files with 74 additions and 35 deletions
+6 -2
View File
@@ -61,6 +61,7 @@ func (h *InventoryHandler) List(c *gin.Context) {
keyword := c.Query("keyword")
warehouseIDStr := c.Query("warehouse_id")
inStock := c.Query("in_stock")
if keyword != "" {
baseWhere += " AND (COALESCE(NULLIF(p.name,''), inv.product_name) LIKE ? OR COALESCE(NULLIF(p.code,''), inv.product_code) LIKE ?)"
@@ -71,6 +72,9 @@ func (h *InventoryHandler) List(c *gin.Context) {
baseWhere += " AND inv.warehouse_id = ?"
args = append(args, warehouseIDStr)
}
if inStock == "1" {
baseWhere += " AND inv.quantity > 0"
}
// Count query
countSQL := `
@@ -96,13 +100,13 @@ func (h *InventoryHandler) List(c *gin.Context) {
COALESCE(NULLIF(p.unit,''), inv.unit, '') AS unit,
COALESCE(NULLIF(w.name,''), inv.warehouse_name, '') AS warehouse_name,
COALESCE(sii.unit_price, inv.unit_price) AS unit_price,
COALESCE(DATE_FORMAT(sii.production_date,'%Y-%m-%d'), DATE_FORMAT(inv.production_date,'%Y-%m-%d')) AS production_date,
COALESCE(DATE(sii.production_date), DATE(inv.production_date)) AS production_date,
COALESCE(NULLIF(sii.batch_no,''), inv.batch_no, '') AS batch_no,
inv.supplier_name,
inv.remark,
COALESCE(p.brand, '') AS brand,
p.min_stock,
DATE_FORMAT(inv.created_at, '%Y-%m-%dT%H:%i:%sZ') AS created_at
inv.created_at
FROM inventories inv
LEFT JOIN stock_in_items sii ON sii.id = inv.stock_in_item_id
LEFT JOIN products p ON p.id = inv.product_id