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:
@@ -64,16 +64,26 @@ func (s *StockService) ApproveStockIn(shopID, orderID, reviewerID uint64) error
|
||||
unitPricePtr = &itemCopy.UnitPrice
|
||||
}
|
||||
|
||||
productCode := ""
|
||||
productName := ""
|
||||
series := ""
|
||||
spec := ""
|
||||
// 优先使用明细自带快照列(历史导入单的真实商品信息在此),
|
||||
// Product 关联仅作兜底(普通 UI 录入单的明细快照为空)。
|
||||
productCode := itemCopy.ProductCode
|
||||
productName := itemCopy.ProductName
|
||||
series := itemCopy.Series
|
||||
spec := itemCopy.Spec
|
||||
unit := ""
|
||||
if itemCopy.Product != nil {
|
||||
productCode = itemCopy.Product.Code
|
||||
productName = itemCopy.Product.Name
|
||||
series = itemCopy.Product.Series
|
||||
spec = itemCopy.Product.Spec
|
||||
if productCode == "" {
|
||||
productCode = itemCopy.Product.Code
|
||||
}
|
||||
if productName == "" {
|
||||
productName = itemCopy.Product.Name
|
||||
}
|
||||
if series == "" {
|
||||
series = itemCopy.Product.Series
|
||||
}
|
||||
if spec == "" {
|
||||
spec = itemCopy.Product.Spec
|
||||
}
|
||||
unit = itemCopy.Product.Unit
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,47 @@ func TestStockService_ApproveStockIn_Success(t *testing.T) {
|
||||
assert.Equal(t, float64(10), logs[0].QtyAfter)
|
||||
}
|
||||
|
||||
// 历史导入单:明细自带真实快照名,product_id 指向占位商品(名「历史导入占位」)。
|
||||
// 审核生成的库存应使用明细快照真名,而非占位商品名。
|
||||
func TestStockService_ApproveStockIn_PrefersItemSnapshot(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "STOCK009")
|
||||
warehouse := testutil.CreateTestWarehouse(db, shop.ID, "Warehouse")
|
||||
placeholder := testutil.CreateTestProduct(db, shop.ID, "历史导入占位")
|
||||
user := testutil.CreateTestUser(db, shop.ID, "admin", "pass", "admin")
|
||||
|
||||
order := model.StockInOrder{
|
||||
TenantBase: model.TenantBase{ShopID: shop.ID},
|
||||
OrderNo: "IN20240101000009",
|
||||
WarehouseID: warehouse.ID,
|
||||
OperatorID: user.ID,
|
||||
Status: "pending",
|
||||
OrderDate: model.Date{Time: time.Now()},
|
||||
Items: []model.StockInItem{
|
||||
{
|
||||
ShopID: shop.ID,
|
||||
ProductID: placeholder.ID,
|
||||
ProductCode: "ZXZ029751",
|
||||
ProductName: "贵州茅台酒2006",
|
||||
Series: "茅台",
|
||||
Spec: "500ml",
|
||||
Quantity: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
require.NoError(t, db.Create(&order).Error)
|
||||
|
||||
svc := NewStockService(db)
|
||||
require.NoError(t, svc.ApproveStockIn(shop.ID, order.ID, user.ID))
|
||||
|
||||
var inv model.Inventory
|
||||
require.NoError(t, db.Where("shop_id = ? AND product_id = ?", shop.ID, placeholder.ID).First(&inv).Error)
|
||||
assert.Equal(t, "贵州茅台酒2006", inv.ProductName)
|
||||
assert.Equal(t, "ZXZ029751", inv.ProductCode)
|
||||
assert.Equal(t, "茅台", inv.Series)
|
||||
assert.Equal(t, "500ml", inv.Spec)
|
||||
}
|
||||
|
||||
func TestStockService_ApproveStockIn_NotPending(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "STOCK002")
|
||||
|
||||
Reference in New Issue
Block a user