修复零售出库金额为负
This commit is contained in:
1 parent
84dcc8e9c7
commit
591b4cb7db
1 file changed
+11
-2
+11
-2
@@ -566,7 +566,8 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
|||||||
?smErpUnitEntity.getRetailPrice():smErpUnitEntity.getPromotionPrice());
|
?smErpUnitEntity.getRetailPrice():smErpUnitEntity.getPromotionPrice());
|
||||||
//使用 BigDecimal 避免浮点数精度问题
|
//使用 BigDecimal 避免浮点数精度问题
|
||||||
//setScale(0, RoundingMode.HALF_UP) 确保四舍五入到整数
|
//setScale(0, RoundingMode.HALF_UP) 确保四舍五入到整数
|
||||||
BigDecimal quantity = BigDecimal.valueOf(smErpInventoryRecordsItemEntity.getQuantity());
|
//注意:金额应该使用数量的绝对值计算,因为金额不应该是负数,出入库方向由OrderType区分
|
||||||
|
BigDecimal quantity = BigDecimal.valueOf(Math.abs(smErpInventoryRecordsItemEntity.getQuantity()));
|
||||||
BigDecimal unitPrice = BigDecimal.valueOf(smErpInventoryRecordsItemEntity.getUnitPrice());
|
BigDecimal unitPrice = BigDecimal.valueOf(smErpInventoryRecordsItemEntity.getUnitPrice());
|
||||||
BigDecimal totalAmount = quantity.multiply(unitPrice);
|
BigDecimal totalAmount = quantity.multiply(unitPrice);
|
||||||
smErpInventoryRecordsItemEntity.setTotalAmount(totalAmount.setScale(0, RoundingMode.HALF_UP).intValue());
|
smErpInventoryRecordsItemEntity.setTotalAmount(totalAmount.setScale(0, RoundingMode.HALF_UP).intValue());
|
||||||
@@ -651,10 +652,18 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
|||||||
smErpInventoryRecordsItemEntity.setUnitPrice
|
smErpInventoryRecordsItemEntity.setUnitPrice
|
||||||
(smErpUnitEntity.getPromotionPrice()==null || smErpUnitEntity.getPromotionPrice()==0
|
(smErpUnitEntity.getPromotionPrice()==null || smErpUnitEntity.getPromotionPrice()==0
|
||||||
?smErpUnitEntity.getRetailPrice():smErpUnitEntity.getPromotionPrice());
|
?smErpUnitEntity.getRetailPrice():smErpUnitEntity.getPromotionPrice());
|
||||||
|
//使用 BigDecimal 避免浮点数精度问题
|
||||||
|
//注意:金额应该使用数量的绝对值计算,因为金额不应该是负数,出入库方向由OrderType区分
|
||||||
|
BigDecimal quantity = BigDecimal.valueOf(Math.abs(smErpInventoryRecordsItemEntity.getQuantity()));
|
||||||
|
BigDecimal unitPrice = BigDecimal.valueOf(smErpInventoryRecordsItemEntity.getUnitPrice());
|
||||||
|
BigDecimal totalAmount = quantity.multiply(unitPrice);
|
||||||
|
smErpInventoryRecordsItemEntity.setTotalAmount(totalAmount.setScale(0, RoundingMode.HALF_UP).intValue());
|
||||||
smErpInventoryRecordsItemEntityList.add(smErpInventoryRecordsItemEntity);
|
smErpInventoryRecordsItemEntityList.add(smErpInventoryRecordsItemEntity);
|
||||||
}
|
}
|
||||||
smErpStockService.updateStock(updateStockDTOS);
|
smErpStockService.updateStock(updateStockDTOS);
|
||||||
int sum = smErpInventoryRecordsItemEntityList.stream().map(smErpInventoryRecordsItemEntity -> smErpInventoryRecordsItemEntity.getUnitPrice()).mapToInt(Integer::intValue).sum();
|
int sum = smErpInventoryRecordsItemEntityList.stream()
|
||||||
|
.mapToInt(SmErpInventoryRecordsItemEntity::getTotalAmount)
|
||||||
|
.sum();
|
||||||
smErpInventoryRecordsEntity.setTotalAmount(sum);
|
smErpInventoryRecordsEntity.setTotalAmount(sum);
|
||||||
smErpInventoryRecordsEntity.setReceiveAmount(sum);
|
smErpInventoryRecordsEntity.setReceiveAmount(sum);
|
||||||
//生成出入库记录
|
//生成出入库记录
|
||||||
|
|||||||
Reference in new issue
Block a user