feat(backend): 入库/出库列表 keyword 支持酒名模糊反查
- keyword 在单号/往来单位基础上,新增按酒名反查含该酒明细的单据 - 酒名匹配复用拼音基建:name(优先 product 回退快照) + name_pinyin + name_initials - 子查询带 shop_id,多租户隔离不破 - 补 stock_in/stock_out List 按酒名+拼音命中的测试用例 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -451,6 +451,42 @@ func TestStockInHandler_List_FilterByKeyword(t *testing.T) {
|
||||
assert.Equal(t, float64(2), parseResponse(w)["total"].(float64))
|
||||
}
|
||||
|
||||
func TestStockInHandler_List_FilterByProductName(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "SI012")
|
||||
user := testutil.CreateTestUser(db, shop.ID, "admin", "pass", "admin")
|
||||
warehouse := testutil.CreateTestWarehouse(db, shop.ID, "Warehouse")
|
||||
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
// 单据1:明细酒名「飞天茅台」(入库按 product_name 新建独立 product)
|
||||
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_name": "飞天茅台", "quantity": 5.0}},
|
||||
})
|
||||
require.Equal(t, http.StatusCreated, w.Code)
|
||||
|
||||
// 单据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_name": "拉菲红酒", "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))
|
||||
|
||||
w = makeRequest(r, "GET", "/api/v1/stock-in/orders?keyword=红酒", 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