feat(backend): 入库每行新建独立产品发独立序列号(product 加生产日期/批次列)
Deploy Server / release-deploy-server (push) Successful in 59s
Deploy Server / release-deploy-server (push) Successful in 59s
入库 Create/Update 改为对每条明细新建独立 product(createIndependentProduct, nextProductCode 自增 + uk_shop_code 唯一约束兜底),回填 product_id;不再按名称复用。 product 表加 production_date/batch_no。向后兼容:保留明细/库存快照列。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZ4DskSRKsSiheQonFtQvx
This commit is contained in:
@@ -28,9 +28,11 @@ func TestStockInHandler_FullFlow(t *testing.T) {
|
||||
"order_date": time.Now().Format(time.RFC3339),
|
||||
"items": []map[string]interface{}{
|
||||
{
|
||||
"product_id": product.ID,
|
||||
"quantity": 10.0,
|
||||
"unit_price": 5.0,
|
||||
"product_name": "Test Beer",
|
||||
"series": "普通",
|
||||
"spec": "500ml",
|
||||
"quantity": 10.0,
|
||||
"unit_price": 5.0,
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -57,15 +59,17 @@ func TestStockInHandler_FullFlow(t *testing.T) {
|
||||
w = makeRequest(r, "PUT", fmt.Sprintf("/api/v1/stock-in/orders/%d/approve", orderID), token, nil)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
// 5. 验证库存变化
|
||||
// 5. 验证库存变化:入库为明细新建了独立产品,库存指向它(不是预设的 product)
|
||||
var inv model.Inventory
|
||||
db.Where("shop_id = ? AND warehouse_id = ? AND product_id = ?",
|
||||
shop.ID, warehouse.ID, product.ID).First(&inv)
|
||||
db.Where("shop_id = ? AND warehouse_id = ?",
|
||||
shop.ID, warehouse.ID).First(&inv)
|
||||
assert.Equal(t, float64(10), inv.Quantity)
|
||||
assert.NotZero(t, inv.ProductID)
|
||||
assert.NotEqual(t, product.ID, inv.ProductID)
|
||||
|
||||
// 6. 验证库存流水
|
||||
var logs []model.InventoryLog
|
||||
db.Where("shop_id = ? AND product_id = ?", shop.ID, product.ID).Find(&logs)
|
||||
db.Where("shop_id = ? AND product_id = ?", shop.ID, inv.ProductID).Find(&logs)
|
||||
require.Len(t, logs, 1)
|
||||
assert.Equal(t, "in", logs[0].Direction)
|
||||
assert.Equal(t, float64(10), logs[0].Quantity)
|
||||
|
||||
Reference in New Issue
Block a user