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:
@@ -75,6 +75,44 @@ func TestStockInHandler_FullFlow(t *testing.T) {
|
||||
assert.Equal(t, float64(10), logs[0].Quantity)
|
||||
}
|
||||
|
||||
// 入库明细带 sale_price 时,为该行新建的独立产品应写入 product.SalePrice(建议售价)。
|
||||
func TestStockInHandler_Create_SalePriceToProduct(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "SISALE")
|
||||
user := testutil.CreateTestUser(db, shop.ID, "admin", "pass", "admin")
|
||||
warehouse := testutil.CreateTestWarehouse(db, shop.ID, "Main")
|
||||
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
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": "茅台飞天",
|
||||
"series": "53度",
|
||||
"spec": "500ml",
|
||||
"quantity": 3.0,
|
||||
"unit_price": 2680.0,
|
||||
"sale_price": 2980.0,
|
||||
},
|
||||
},
|
||||
})
|
||||
require.Equal(t, http.StatusCreated, w.Code)
|
||||
orderID := extractID(w)
|
||||
|
||||
// 找到该单据明细新建的独立产品,核对进价/售价
|
||||
var item model.StockInItem
|
||||
require.NoError(t, db.Where("order_id = ?", orderID).First(&item).Error)
|
||||
require.NotZero(t, item.ProductID)
|
||||
var prod model.Product
|
||||
require.NoError(t, db.Where("id = ? AND shop_id = ?", item.ProductID, shop.ID).First(&prod).Error)
|
||||
assert.Equal(t, 2680.0, prod.PurchasePrice)
|
||||
assert.Equal(t, 2980.0, prod.SalePrice)
|
||||
// sale_price 不落 stock_in_items(gorm:"-"),仅作产品建库入参
|
||||
assert.Equal(t, "茅台飞天", prod.Name)
|
||||
}
|
||||
|
||||
func TestStockInHandler_List(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "SI002")
|
||||
|
||||
Reference in New Issue
Block a user