refactor(sales): 优化售后退货金额计算逻辑

- 移除请求数量和实退数量的验证,避免可能的异常
- 修改实退金额计算方式,直接使用退货金额
-调整测试用例,增加新的测试场景
- 修正报表字段顺序
This commit is contained in:
liuy 2025-08-20 15:59:08 +08:00
parent 4762743d4d
commit b4b03ea8de
5 changed files with 25 additions and 17 deletions

View File

@ -4344,24 +4344,26 @@ public class PassiveWarehouseReceiptToC extends PluginBaseEntity {
Assert.state(!"".equals(totalAmount), "售后订单:{} 存货明细行:{} 退货金额不能为空!", header.getCode(), targetDetails.getSkuCode());
//售后订单明细行-请求数量
//实退数量存在可能为0的情况如果用退货金额/实退数量可能会抛出异常
String requestQty = targetDetails.getRequestQty();//请求数量
Assert.notNull(requestQty, "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode());
Assert.state(!"".equals(requestQty), "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode());
// String requestQty = targetDetails.getRequestQty();//请求数量
// Assert.notNull(requestQty, "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode());
// Assert.state(!"".equals(requestQty), "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode());
String quantity = passiveStorageSonDetailsDto.getQuantity();
Assert.notNull(quantity, "无源入库单:{} sku{} 实退数量不能为空", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName());
Assert.state(!"".equals(quantity), "无源入库单:{} sku{} 实退数量不能为空", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName());
if ("0".equals(new BigDecimal(quantity).stripTrailingZeros().toPlainString())) {
Assert.state(false, "无源入库单:{} sku{} 实退数量不能为0", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName());
}
// String quantity = passiveStorageSonDetailsDto.getQuantity();
// Assert.notNull(quantity, "无源入库单:{} sku{} 实退数量不能为空", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName());
// Assert.state(!"".equals(quantity), "无源入库单:{} sku{} 实退数量不能为空", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName());
// if ("0".equals(new BigDecimal(quantity).stripTrailingZeros().toPlainString())) {
// Assert.state(false, "无源入库单:{} sku{} 实退数量不能为0", passiveStorageSonDetailsDto.getQuantity(), passiveStorageSonDetailsDto.getSkuName());
// }
//O含税单价=通过退货金额/请求数量
BigDecimal unitPriceIncludingTax = new BigDecimal(totalAmount).divide(new BigDecimal(requestQty), 20, BigDecimal.ROUND_HALF_UP);
// BigDecimal unitPriceIncludingTax = new BigDecimal(totalAmount).divide(new BigDecimal(requestQty), 20, BigDecimal.ROUND_HALF_UP);
//实退金额=O含税单价*O售后入库单实退数量
BigDecimal actualRefundAmount = unitPriceIncludingTax.multiply(new BigDecimal(quantity)).setScale(4, BigDecimal.ROUND_HALF_UP);
String format = StrUtil.format("{}/{}*{}", totalAmount, requestQty, quantity);
// BigDecimal actualRefundAmount = unitPriceIncludingTax.multiply(new BigDecimal(quantity)).setScale(4, BigDecimal.ROUND_HALF_UP);
// String format = StrUtil.format("{}/{}*{}", totalAmount, requestQty, quantity);
String format = StrUtil.format("{}", totalAmount);
calculationFormulaStr.append(format);
return actualRefundAmount.stripTrailingZeros().toPlainString();
// return actualRefundAmount.stripTrailingZeros().toPlainString();
return new BigDecimal(totalAmount).stripTrailingZeros().toPlainString();
} else {
//2025年4月18日11:06:04 如果无源入库单明细行无法匹配售后订单明细行则金额为0即可
return "0";

View File

@ -1815,6 +1815,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
// StockinOrderSearchResponse.StockinOrder.StockinB stockinB = details2.get(i);
// stockinB.setReceivedQty(stockinB.getRequestQty());
// }
// headerDetailsDtos.get(0).getHeader().setTradeSuccessAt("2025-08-01 15:12:00");
markTimeInMorningEvening(returnGoodHeaderDetailsDataDtoList1);
if ("stock".equals(sceneType)) {

View File

@ -37,8 +37,10 @@ public class PassiveWarehouseReceiptToCTest {
//情况二
// passiveWarehouseReceiptToC.startImplementByCode("RH20250731000423", "tran");
//情况三
passiveWarehouseReceiptToC.startImplementByCode("RH20250731000613", "tran");
// passiveWarehouseReceiptToC.startImplementByCode("RH20250731000613", "tran");
// passiveWarehouseReceiptToC.startImplementByCode("RH20250723000754", "tran");
passiveWarehouseReceiptToC.startImplementByCode("RH20250731000017", "stock");
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -69,8 +69,10 @@ public class SoSaleReturnPluginInitializerToCTest {
try {
// soSaleReturnPluginInitializerToC.startImplementByTradeTime("2025-04-28 00:00:00", "2025-04-28 23:59:59", "0");
soSaleReturnPluginInitializerToC.startImplementByCode("LETS-RE2025072600001452", "tran");
//满足红字应收单
soSaleReturnPluginInitializerToC.startImplementByCode("LETS-RE2025072200001324", "tran");
// soSaleReturnPluginInitializerToC.startImplementByCode("LETS-RE2025072200001324", "tran");
//情况一
// soSaleReturnPluginInitializerToC.startImplementByCode("LETS-RE2025072900000460", "stock");
//情况二

View File

@ -66,9 +66,9 @@ public class TocofsReturnGoodsDetailedDto {
@ExcelProperty(value = "交易成功红-下游主键")
private String newSystemPrimary4;
@ExcelProperty(value = "交易成功蓝-报错详情")
private String def13;
@ExcelProperty(value = "交易成功蓝-推送时间")
private String def13;
@ExcelProperty(value = "交易成功蓝-报错详情")
private String def14;
@ExcelProperty(value = "交易成功蓝-推送状态")
private String def15;
@ -78,6 +78,7 @@ public class TocofsReturnGoodsDetailedDto {
private String def17;
//交易成功时间
@ExcelProperty(value = "交易成功时间")
private String def23;
//情况类型