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:
@@ -308,6 +308,51 @@ func TestStockInHandler_Reject_NotPending(t *testing.T) {
|
||||
assert.Equal(t, http.StatusBadRequest, w.Code)
|
||||
}
|
||||
|
||||
func TestStockInHandler_List_FilterByKeyword(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "SI011")
|
||||
user := testutil.CreateTestUser(db, shop.ID, "admin", "pass", "admin")
|
||||
warehouse := testutil.CreateTestWarehouse(db, shop.ID, "Warehouse")
|
||||
product := testutil.CreateTestProduct(db, shop.ID, "Brandy")
|
||||
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
// 往来单位:茅台供应商
|
||||
partner := &model.Partner{Code: "P001", Name: "茅台供应商", Type: "supplier"}
|
||||
partner.ShopID = shop.ID
|
||||
require.NoError(t, db.Create(partner).Error)
|
||||
|
||||
// 单据1:挂往来单位
|
||||
w := makeRequest(r, "POST", "/api/v1/stock-in/orders", token, map[string]interface{}{
|
||||
"warehouse_id": warehouse.ID,
|
||||
"partner_id": partner.ID,
|
||||
"order_date": time.Now().Format(time.RFC3339),
|
||||
"items": []map[string]interface{}{{"product_id": product.ID, "quantity": 5.0}},
|
||||
})
|
||||
require.Equal(t, http.StatusCreated, w.Code)
|
||||
order1No := parseResponse(w)["data"].(map[string]interface{})["order_no"].(string)
|
||||
|
||||
// 单据2:无往来单位
|
||||
w = makeRequest(r, "POST", "/api/v1/stock-in/orders", token, map[string]interface{}{
|
||||
"warehouse_id": warehouse.ID,
|
||||
"order_date": time.Now().Format(time.RFC3339),
|
||||
"items": []map[string]interface{}{{"product_id": product.ID, "quantity": 3.0}},
|
||||
})
|
||||
require.Equal(t, http.StatusCreated, w.Code)
|
||||
|
||||
// 按往来单位名搜索 → 只命中单据1
|
||||
w = makeRequest(r, "GET", "/api/v1/stock-in/orders?keyword=茅台", token, nil)
|
||||
assert.Equal(t, float64(1), parseResponse(w)["total"].(float64))
|
||||
|
||||
// 按单号搜索 → 只命中单据1
|
||||
w = makeRequest(r, "GET", "/api/v1/stock-in/orders?keyword="+order1No, token, nil)
|
||||
assert.Equal(t, float64(1), parseResponse(w)["total"].(float64))
|
||||
|
||||
// 无关键词 → 两条都在
|
||||
w = makeRequest(r, "GET", "/api/v1/stock-in/orders", token, nil)
|
||||
assert.Equal(t, float64(2), parseResponse(w)["total"].(float64))
|
||||
}
|
||||
|
||||
func TestStockInHandler_List_FilterByStatus(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "SI010")
|
||||
|
||||
Reference in New Issue
Block a user