解决移动平均价遇到负库存情况下的bug

This commit is contained in:
jishenghua
2024-11-07 18:09:47 +08:00
parent 800cf85f39
commit d80d3b0fc4

View File

@@ -1077,33 +1077,38 @@ public class DepotItemService {
BigDecimal currentAllPrice = BigDecimal.ZERO;
for(DepotItemVo4DetailByTypeAndMId item: itemList) {
BigDecimal basicNumber = item.getBnum()!=null?item.getBnum():BigDecimal.ZERO;
//数量*单价 另外计算新的成本价
BigDecimal allPrice = unitService.parseAllPriceByUnit(item.getAllPrice()!=null?item.getAllPrice():BigDecimal.ZERO, unitInfo, item.getMaterialUnit());
if(basicNumber.compareTo(BigDecimal.ZERO)!=0 && allPrice.compareTo(BigDecimal.ZERO)!=0) {
//入库
if(BusinessConstants.DEPOTHEAD_TYPE_IN.equals(item.getType())) {
if (BusinessConstants.DEPOTHEAD_TYPE_IN.equals(item.getType())) {
//零售退货、销售退货
if(BusinessConstants.SUB_TYPE_RETAIL_RETURN.equals(item.getSubType())||BusinessConstants.SUB_TYPE_SALES_RETURN.equals(item.getSubType())) {
if (BusinessConstants.SUB_TYPE_RETAIL_RETURN.equals(item.getSubType()) || BusinessConstants.SUB_TYPE_SALES_RETURN.equals(item.getSubType())) {
//数量*当前的成本单价
currentNumber = currentNumber.add(basicNumber);
currentAllPrice = currentAllPrice.add(basicNumber.multiply(currentUnitPrice));
} else {
//数量*单价 另外计算新的成本价
BigDecimal allPrice = unitService.parseAllPriceByUnit(item.getAllPrice(), unitInfo, item.getMaterialUnit());
currentAllPrice = currentAllPrice.add(allPrice);
currentNumber = currentNumber.add(basicNumber);
if(currentNumber.compareTo(BigDecimal.ZERO)!=0) {
//只有当前库存总金额和当前库存数量都大于0才计算移动平均价
if (currentAllPrice.compareTo(BigDecimal.ZERO) > 0 && currentNumber.compareTo(BigDecimal.ZERO) > 0) {
currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP);
} else {
currentUnitPrice = item.getUnitPrice();
}
}
}
//出库
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(item.getType())) {
if (BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(item.getType())) {
//采购退货
if(BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(item.getSubType())) {
//数量*单价 另外计算新的成本价
BigDecimal allPrice = unitService.parseAllPriceByUnit(item.getAllPrice(), unitInfo, item.getMaterialUnit());
if (BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(item.getSubType())) {
currentAllPrice = currentAllPrice.add(allPrice);
currentNumber = currentNumber.add(basicNumber);
if(currentNumber.compareTo(BigDecimal.ZERO)!=0) {
//只有当前库存总金额和当前库存数量都大于0才计算移动平均价
if (currentAllPrice.compareTo(BigDecimal.ZERO) > 0 && currentNumber.compareTo(BigDecimal.ZERO) > 0) {
currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP);
} else {
currentUnitPrice = item.getUnitPrice();
}
} else {
currentNumber = currentNumber.add(basicNumber);
@@ -1116,6 +1121,7 @@ public class DepotItemService {
currentUnitPrice = BigDecimal.ZERO;
}
}
}
//更新实时库存中的当前单价
materialCurrentStockMapperEx.updateUnitPriceByMId(currentUnitPrice, depotItem.getMaterialId());
}