1.修复库存调拨缺陷,调入门店的商品可能之前没有,需要新增记录;
2.修复库存变动缺陷,查找库存可用id时主键不一致;
This commit is contained in:
parent
0c6325bd2c
commit
6b747385a5
|
@ -1067,17 +1067,56 @@ func ReceiveAllotInventory(req *InventoryAllotReceiveReq, c *gin.Context) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新库存商品数量
|
// 更新调入门店的库存数量
|
||||||
err = begin.Exec(fmt.Sprintf(
|
exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM erp_stock WHERE store_id=%d AND erp_commodity_id=%d",
|
||||||
"UPDATE erp_stock SET count=count+%d WHERE store_id=%d AND erp_commodity_id=%d",
|
inventoryAllotOrder.ReceiveStoreId, v.CommodityId))
|
||||||
v.Count, inventoryAllotOrder.ReceiveStoreId, v.CommodityId)).Error
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
begin.Rollback()
|
logger.Errorf("exist err:", err)
|
||||||
logger.Errorf("update stock err:", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if exist {
|
||||||
|
// 更新调入门店库存商品数量
|
||||||
|
err = begin.Exec(fmt.Sprintf(
|
||||||
|
"UPDATE erp_stock SET count=count+%d WHERE store_id=%d AND erp_commodity_id=%d",
|
||||||
|
v.Count, inventoryAllotOrder.ReceiveStoreId, v.CommodityId)).Error
|
||||||
|
if err != nil {
|
||||||
|
begin.Rollback()
|
||||||
|
logger.Errorf("update stock err:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stock := &ErpStock{
|
||||||
|
StoreId: inventoryAllotOrder.ReceiveStoreId,
|
||||||
|
StoreName: inventoryAllotOrder.ReceiveStoreName,
|
||||||
|
ErpCommodityId: v.CommodityId,
|
||||||
|
ErpCommodityName: v.CommodityName,
|
||||||
|
ErpCategoryId: stockCommodity[0].ErpCategoryId,
|
||||||
|
ErpCategoryName: stockCommodity[0].ErpCategoryName,
|
||||||
|
CommoditySerialNumber: stockCommodity[0].CommoditySerialNumber,
|
||||||
|
IMEIType: v.IMEIType,
|
||||||
|
RetailPrice: stockCommodity[0].RetailPrice,
|
||||||
|
MinRetailPrice: stockCommodity[0].MinRetailPrice,
|
||||||
|
Count: v.Count,
|
||||||
|
DispatchCount: 0,
|
||||||
|
}
|
||||||
|
err = begin.Create(stock).Error
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("create stock err:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 更新库存商品调拨数量
|
//// 更新库存商品数量
|
||||||
|
//err = begin.Exec(fmt.Sprintf(
|
||||||
|
// "UPDATE erp_stock SET count=count+%d WHERE store_id=%d AND erp_commodity_id=%d",
|
||||||
|
// v.Count, inventoryAllotOrder.ReceiveStoreId, v.CommodityId)).Error
|
||||||
|
//if err != nil {
|
||||||
|
// begin.Rollback()
|
||||||
|
// logger.Errorf("update stock err:", err)
|
||||||
|
// return err
|
||||||
|
//}
|
||||||
|
|
||||||
|
// 更新调出门店库存商品调拨数量
|
||||||
err = begin.Exec(fmt.Sprintf(
|
err = begin.Exec(fmt.Sprintf(
|
||||||
"UPDATE erp_stock SET dispatch_count = dispatch_count-%d WHERE store_id=%d AND erp_commodity_id=%d",
|
"UPDATE erp_stock SET dispatch_count = dispatch_count-%d WHERE store_id=%d AND erp_commodity_id=%d",
|
||||||
v.Count, inventoryAllotOrder.DeliverStoreId, v.CommodityId)).Error
|
v.Count, inventoryAllotOrder.DeliverStoreId, v.CommodityId)).Error
|
||||||
|
|
|
@ -831,7 +831,7 @@ func handleInventoryReduce(gdb *gorm.DB, changeOrder ErpInventoryChangeOrder) er
|
||||||
logger.Field("err", err))
|
logger.Field("err", err))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
usedStockCommodityIdList[trimCommodities[i].ID] = append(usedStockCommodityIdList[trimCommodities[i].ID], rightId)
|
usedStockCommodityIdList[trimCommodities[i].CommodityId] = append(usedStockCommodityIdList[trimCommodities[i].CommodityId], rightId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新库存数量:库存数量-count
|
// 更新库存数量:库存数量-count
|
||||||
|
@ -1022,7 +1022,7 @@ func handleCancelInventoryReduce(gdb *gorm.DB, changeOrder ErpInventoryChangeOrd
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
usedStockCommodityIdList[trimCommodities[i].ID] = append(usedStockCommodityIdList[trimCommodities[i].ID], rightId)
|
usedStockCommodityIdList[trimCommodities[i].CommodityId] = append(usedStockCommodityIdList[trimCommodities[i].CommodityId], rightId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新库存数量:库存数量+count
|
// 更新库存数量:库存数量+count
|
||||||
|
|
|
@ -262,6 +262,7 @@ func (e *Menu) Get() (Menus []Menu, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = table.Order("sort").Find(&Menus).Error; err != nil {
|
if err = table.Order("sort").Find(&Menus).Error; err != nil {
|
||||||
|
//if err = table.Where("visible = 0").Order("sort").Find(&Menus).Error; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user