wangxinhui
2025-11-18 d21995836f488e6e438321e825182176b1f52cfa
ÏîÄ¿´úÂë/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs
@@ -73,13 +73,13 @@
            {
                decimal needQuantity = item.XqLen;
                //获取可用库存
                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterialNo, item.Width, outBSTOrders.FirstOrDefault().WarehouseId);
                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterialNo, item.Width, outBSTOrders.FirstOrDefault().WarehouseId).Where(x=>!outStocks.Select(x=>x.PalletCode).Contains(x.PalletCode)).ToList();
                if (!stockInfos.Any())
                {
                    throw new Exception($"未找到可分配库存");
                    continue;
                }
                //分配实际库存
                List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, needQuantity).OrderBy(x => x.StockLength - x.StockOutLength).ToList();
                List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutOldStocks(stockInfos, needQuantity).ToList();
                //添加库存分配
                outStocks.AddRange(autoAssignStocks);
                //获取所有该物料单据
@@ -100,17 +100,20 @@
                        decimal orderDetailNeedQuantity = details[i].XqLen - detailAssignQuantity;
                        if (autoAssignStocks.Count==0)
                        {
                            break;
                        }
                        decimal useStockLength = autoAssignStocks[0].StockLength- autoAssignStocks[0].StockOutLength;
                        Dt_OutSGOrder? sGOrder = outBSTOrders.FirstOrDefault(x => x.Id == details[i].OutSGOrderId);
                        if (orderDetailNeedQuantity > useStockLength)
                        {
                            //生成详情
                            Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(sGOrder, details[i], autoAssignStocks[0], useStockLength);
                            outStockLockInfos.Add(outStockLockInfo);
                            details[i].AssignTotalUsage += useStockLength;
                            autoAssignStocks.Remove(autoAssignStocks[0]);
                        }
                        else
                        {
@@ -118,7 +121,11 @@
                            Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(sGOrder, details[i], autoAssignStocks[0], orderDetailNeedQuantity);
                            outStockLockInfos.Add(outStockLockInfo);
                            details[i].AssignTotalUsage = orderQuantity;
                            autoAssignStocks[0].StockOutLength-= orderDetailNeedQuantity;
                            autoAssignStocks[0].StockOutLength+= orderDetailNeedQuantity;
                            if (autoAssignStocks[0].StockOutLength== autoAssignStocks[0].StockLength)
                            {
                                autoAssignStocks.Remove(autoAssignStocks[0]);
                            }
                            assignStop =false;
                        }
                    }