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
+36 -3
View File
@@ -183,6 +183,7 @@ func SetupTestDB() *gorm.DB {
unit_price REAL DEFAULT 0,
total_price REAL DEFAULT 0,
batch_no TEXT,
production_date DATETIME,
custom_fields TEXT,
remark TEXT
)`,
@@ -223,11 +224,25 @@ func SetupTestDB() *gorm.DB {
`CREATE TABLE IF NOT EXISTS inventories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
shop_id INTEGER NOT NULL,
warehouse_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
warehouse_id INTEGER,
product_id INTEGER,
stock_in_item_id INTEGER,
inventory_check_id INTEGER,
quantity REAL DEFAULT 0,
product_code TEXT DEFAULT '',
product_name TEXT DEFAULT '',
series TEXT DEFAULT '',
spec TEXT DEFAULT '',
unit TEXT DEFAULT '',
warehouse_name TEXT DEFAULT '',
unit_price REAL,
production_date DATETIME,
batch_no TEXT DEFAULT '',
supplier_name TEXT DEFAULT '',
remark TEXT DEFAULT '',
created_at DATETIME,
updated_at DATETIME,
UNIQUE(shop_id, warehouse_id, product_id)
deleted_at DATETIME
)`,
`CREATE TABLE IF NOT EXISTS inventory_logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -269,6 +284,24 @@ func SetupTestDB() *gorm.DB {
actual_qty REAL,
remark TEXT
)`,
`CREATE TABLE IF NOT EXISTS finance_records (
id INTEGER PRIMARY KEY AUTOINCREMENT,
created_at DATETIME,
updated_at DATETIME,
deleted_at DATETIME,
shop_id INTEGER NOT NULL,
partner_id INTEGER,
type TEXT,
amount REAL DEFAULT 0,
balance REAL DEFAULT 0,
status TEXT DEFAULT 'open',
ref_type TEXT,
ref_id INTEGER,
operator_id INTEGER,
record_date DATETIME,
remark TEXT,
custom_fields TEXT
)`,
`CREATE TABLE IF NOT EXISTS number_rules (
id INTEGER PRIMARY KEY AUTOINCREMENT,
shop_id INTEGER NOT NULL,