fix(backend): 往来单位下拉返回全部 + 入库售价写入产品

- partner List 分页上限 200→1000:避免下拉请求大页被 ValidatePageSize
  回退到默认 20(超上限返回默认值而非截断),供应商/客户下拉一次取全部
- 入库明细 sale_price 建独立产品时写入 product.SalePrice(建议售价);
  SalePrice 为 gorm:"-" 仅作建库入参,不落 stock_in_items 表
- 补 partner 大页返回全部、入库售价入产品两条回归测试

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-02 11:44:50 +08:00
parent 1bd8b8f877
commit d0c71a9252
6 changed files with 70 additions and 4 deletions
+23
View File
@@ -205,6 +205,29 @@ func TestPartnerHandler_List_KeywordSearch(t *testing.T) {
assert.Equal(t, float64(0), resp["total"].(float64))
}
// 下拉需一次取全部:请求大页(>默认 20)应返回全部,而非被 ValidatePageSize
// 回退到默认 20(超上限即返回默认值的历史坑)。
func TestPartnerHandler_List_LargePageSizeReturnsAll(t *testing.T) {
db := testutil.SetupTestDB()
shop := testutil.CreateTestShop(db, "PT007")
user := testutil.CreateTestUser(db, shop.ID, "admin", "pass", "admin")
token := getAuthToken(user.ID, shop.ID, "admin")
r := setupProtectedRouter(db)
for i := 0; i < 25; i++ {
makeRequest(r, "POST", "/api/v1/partners", token, map[string]interface{}{
"name": fmt.Sprintf("Partner %02d", i),
"type": "supplier",
})
}
w := makeRequest(r, "GET", "/api/v1/partners?page_size=1000", token, nil)
resp := parseResponse(w)
assert.Equal(t, float64(25), resp["total"].(float64))
assert.Equal(t, float64(1000), resp["page_size"].(float64))
assert.Len(t, resp["data"].([]interface{}), 25)
}
func TestPartnerHandler_ShopIDFromToken(t *testing.T) {
db := testutil.SetupTestDB()
shop := testutil.CreateTestShop(db, "PT007")