fix(backend): 入库审核库存沿用明细真实快照名 + 库存列表过滤软删商品,修复历史导入占位顶替;入库/出库列表支持 keyword 搜索
Deploy Server / release-deploy-server (push) Successful in 53s
Deploy Server / release-deploy-server (push) Successful in 53s
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZ4DskSRKsSiheQonFtQvx
This commit is contained in:
@@ -219,6 +219,52 @@ func TestInventoryHandler_List_HotelIsolation(t *testing.T) {
|
||||
assert.Equal(t, float64(0), respB["total"].(float64))
|
||||
}
|
||||
|
||||
// 库存指向已软删的占位商品时,列表应回退到明细/库存快照真名,
|
||||
// 而非占位商品名「历史导入占位」,且能按真名搜索到。
|
||||
func TestInventoryHandler_List_DeletedProductFallsBackToSnapshot(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "INV009")
|
||||
user := testutil.CreateTestUser(db, shop.ID, "admin", "pass", "admin")
|
||||
warehouse := testutil.CreateTestWarehouse(db, shop.ID, "Warehouse")
|
||||
placeholder := testutil.CreateTestProduct(db, shop.ID, "历史导入占位")
|
||||
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
// 明细携带真实快照名
|
||||
item := model.StockInItem{
|
||||
ShopID: shop.ID,
|
||||
ProductID: placeholder.ID,
|
||||
ProductCode: "ZXZ029751",
|
||||
ProductName: "贵州茅台酒2006",
|
||||
Quantity: 10,
|
||||
}
|
||||
require.NoError(t, db.Create(&item).Error)
|
||||
|
||||
// 库存:product_id 指向占位商品,且 product_name 也是占位名(模拟旧脏数据)
|
||||
require.NoError(t, db.Create(&model.Inventory{
|
||||
ShopID: shop.ID,
|
||||
WarehouseID: &warehouse.ID,
|
||||
ProductID: &placeholder.ID,
|
||||
StockInItemID: &item.ID,
|
||||
ProductName: "历史导入占位",
|
||||
Quantity: 10,
|
||||
}).Error)
|
||||
|
||||
// 软删占位商品
|
||||
require.NoError(t, db.Delete(&placeholder).Error)
|
||||
|
||||
// 列表:名称应回退到明细快照真名
|
||||
w := makeRequest(r, "GET", "/api/v1/inventory", token, nil)
|
||||
resp := parseResponse(w)
|
||||
require.Equal(t, float64(1), resp["total"].(float64))
|
||||
invItem := resp["data"].([]interface{})[0].(map[string]interface{})
|
||||
assert.Equal(t, "贵州茅台酒2006", invItem["product_name"])
|
||||
|
||||
// 按真名可搜到
|
||||
w = makeRequest(r, "GET", "/api/v1/inventory?keyword=茅台", token, nil)
|
||||
assert.Equal(t, float64(1), parseResponse(w)["total"].(float64))
|
||||
}
|
||||
|
||||
func TestInventoryHandler_AfterStockInApprove(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "INV008")
|
||||
|
||||
Reference in New Issue
Block a user