fix(sales): 修复售后退款金额计算逻辑
- 移除了不必要的注释代码 - 优化了实退金额的计算方式,使用含税单价乘以实退数量 - 增加了对实退数量为0的校验 - 调整了优惠金额的处理逻辑 -优化了日志输出信息,提高可读性
This commit is contained in:
parent
2f67e791df
commit
6e5bf89940
|
@ -262,7 +262,6 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
|
||||||
List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList = new ArrayList<>();
|
List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList = new ArrayList<>();
|
||||||
QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo();
|
QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo();
|
||||||
queryOfsSoSaleOutVo.setClientCode("LETS");
|
queryOfsSoSaleOutVo.setClientCode("LETS");
|
||||||
// queryOfsSoSaleOutVo.setInternalInstructionType("SALES");
|
|
||||||
queryOfsSoSaleOutVo.setStatus(900L);
|
queryOfsSoSaleOutVo.setStatus(900L);
|
||||||
queryOfsSoSaleOutVo.setPageNo(1L);
|
queryOfsSoSaleOutVo.setPageNo(1L);
|
||||||
queryOfsSoSaleOutVo.setPageSize(50L);
|
queryOfsSoSaleOutVo.setPageSize(50L);
|
||||||
|
@ -1034,6 +1033,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
|
||||||
* @author liuyang
|
* @author liuyang
|
||||||
*/
|
*/
|
||||||
private String createGenerateBusinessDate(StockinOrderSearchResponse.StockinOrder.StockinH header) {
|
private String createGenerateBusinessDate(StockinOrderSearchResponse.StockinOrder.StockinH header) {
|
||||||
|
// header.setClosedAt("2024-11-07 11:57:12");
|
||||||
String code = null;
|
String code = null;
|
||||||
if (header != null && header.getCode() != null) {
|
if (header != null && header.getCode() != null) {
|
||||||
code = header.getCode();
|
code = header.getCode();
|
||||||
|
@ -1114,6 +1114,14 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
|
||||||
//初始化公司档案对照关系
|
//初始化公司档案对照关系
|
||||||
Map<String, String> comparisonCompanyArchives = queryU8CEntityUtil.queryBdDefDocByPkDefDocAll();
|
Map<String, String> comparisonCompanyArchives = queryU8CEntityUtil.queryBdDefDocByPkDefDocAll();
|
||||||
|
|
||||||
|
//测试
|
||||||
|
// StockinOrderSearchResponse.StockinOrder stockinOrder1 = returnGoodHeaderDetailsDataDtoList1.get(0);
|
||||||
|
// List<StockinOrderSearchResponse.StockinOrder.StockinB> details2 = stockinOrder1.getDetails();
|
||||||
|
// for (int i = 0; i < details2.size(); i++) {
|
||||||
|
// StockinOrderSearchResponse.StockinOrder.StockinB stockinB = details2.get(i);
|
||||||
|
// stockinB.setReceivedQty(stockinB.getRequestQty());
|
||||||
|
// }
|
||||||
|
|
||||||
for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) {
|
for (int i = 0; i < returnGoodHeaderDetailsDataDtoList1.size(); i++) {
|
||||||
StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoList1.get(i);
|
StockinOrderSearchResponse.StockinOrder stockinOrder = returnGoodHeaderDetailsDataDtoList1.get(i);
|
||||||
StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader();
|
StockinOrderSearchResponse.StockinOrder.StockinH header = stockinOrder.getHeader();
|
||||||
|
@ -1508,8 +1516,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
//实付金额/实发数量
|
//实付金额/实发数量
|
||||||
Assert.notNull(totalAmount, "实退金额不能为空 明细行对象:{}", JSON.toJSONString(goodsRertunSonDetailsDto));
|
Assert.notNull(totalAmount, "实退金额不能为空 明细行主键:{}", goodsRertunSonDetailsDto.getId());
|
||||||
Assert.notNull(goodsRertunSonDetailsDto.getReceivedQty(), "实收数量不能为空 明细行对象:{}", JSON.toJSONString(goodsRertunSonDetailsDto));
|
Assert.notNull(goodsRertunSonDetailsDto.getReceivedQty(), "实收数量不能为空 明细行主键:{}", goodsRertunSonDetailsDto.getId());
|
||||||
BigDecimal totalPayAmountBigDecimal = new BigDecimal(totalAmount);
|
BigDecimal totalPayAmountBigDecimal = new BigDecimal(totalAmount);
|
||||||
BigDecimal shipQtyBigDecimal = new BigDecimal(goodsRertunSonDetailsDto.getReceivedQty());
|
BigDecimal shipQtyBigDecimal = new BigDecimal(goodsRertunSonDetailsDto.getReceivedQty());
|
||||||
|
|
||||||
|
@ -1755,7 +1763,7 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
|
||||||
private void findAfterSalesOrder(List<RerturnGoodsOrderSearchData> rerturnGoodsOrderSearchDataList, List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList1) throws Exception {
|
private void findAfterSalesOrder(List<RerturnGoodsOrderSearchData> rerturnGoodsOrderSearchDataList, List<StockinOrderSearchResponse.StockinOrder> returnGoodHeaderDetailsDataDtoList1) throws Exception {
|
||||||
if (rerturnGoodsOrderSearchDataList != null && rerturnGoodsOrderSearchDataList.size() > 0 && returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) {
|
if (rerturnGoodsOrderSearchDataList != null && rerturnGoodsOrderSearchDataList.size() > 0 && returnGoodHeaderDetailsDataDtoList1 != null && returnGoodHeaderDetailsDataDtoList1.size() > 0) {
|
||||||
try {
|
try {
|
||||||
//如果id为空,则这里会报错,所以把id设置为""
|
//key为售后订单主键,如果id为空,则这里会报错,所以把id设置为""
|
||||||
rerturnGoodsOrderSearchDataList.forEach(dto -> {
|
rerturnGoodsOrderSearchDataList.forEach(dto -> {
|
||||||
if (dto.getHeader() != null && dto.getHeader().getId() == null) {
|
if (dto.getHeader() != null && dto.getHeader().getId() == null) {
|
||||||
dto.getHeader().setId("");
|
dto.getHeader().setId("");
|
||||||
|
@ -1777,9 +1785,9 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
|
||||||
// header.setRerturnGoodsOrderSearchData(rerturnGoodsOrderSearchData);
|
// header.setRerturnGoodsOrderSearchData(rerturnGoodsOrderSearchData);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
String id = header.getId();
|
String refOrderId = header.getRefOrderId();
|
||||||
if (id != null && !"".equals(id)) {
|
if (refOrderId != null && !"".equals(refOrderId)) {
|
||||||
RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = collect.get(id);
|
RerturnGoodsOrderSearchData rerturnGoodsOrderSearchData = collect.get(refOrderId);
|
||||||
if (rerturnGoodsOrderSearchData != null) {
|
if (rerturnGoodsOrderSearchData != null) {
|
||||||
header.setRerturnGoodsOrderSearchData(rerturnGoodsOrderSearchData);
|
header.setRerturnGoodsOrderSearchData(rerturnGoodsOrderSearchData);
|
||||||
}
|
}
|
||||||
|
@ -2607,22 +2615,27 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
|
||||||
Assert.notNull(targetDetails, "根据OFS售后入库单细行(refOrderDetailId)无法匹配售后订单明细行", goodsRertunSonDetailsDto.getRefOrderDetailId());
|
Assert.notNull(targetDetails, "根据OFS售后入库单细行(refOrderDetailId)无法匹配售后订单明细行", goodsRertunSonDetailsDto.getRefOrderDetailId());
|
||||||
|
|
||||||
//售后订单明细行-退货金额
|
//售后订单明细行-退货金额
|
||||||
String totalAmount = targetDetails.getTotalAmount();
|
String totalAmount = targetDetails.getTotalAmount();//实退金额
|
||||||
Assert.notNull(totalAmount, "售后订单:{} 存货明细行:{} 退货金额不能为空!", header.getCode(), targetDetails.getSkuCode());
|
Assert.notNull(totalAmount, "售后订单:{} 存货明细行:{} 退货金额不能为空!", header.getCode(), targetDetails.getSkuCode());
|
||||||
Assert.state(!"".equals(totalAmount), "售后订单:{} 存货明细行:{} 退货金额不能为空!", header.getCode(), targetDetails.getSkuCode());
|
Assert.state(!"".equals(totalAmount), "售后订单:{} 存货明细行:{} 退货金额不能为空!", header.getCode(), targetDetails.getSkuCode());
|
||||||
//售后订单明细行-请求数量
|
//售后订单明细行-请求数量
|
||||||
//实退数量存在可能为0的情况,如果用退货金额/实退数量可能会抛出异常
|
//实退数量存在可能为0的情况,如果用退货金额/实退数量可能会抛出异常
|
||||||
String requestQty = targetDetails.getRequestQty();
|
String requestQty = targetDetails.getRequestQty();//请求数量
|
||||||
Assert.notNull(requestQty, "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode());
|
Assert.notNull(requestQty, "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode());
|
||||||
Assert.state(!"".equals(requestQty), "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode());
|
Assert.state(!"".equals(requestQty), "售后订单:{} 存货明细行:{} 请求数量不能为空!", header.getCode(), targetDetails.getSkuCode());
|
||||||
//通过退货金额/请求数量=含税单价
|
|
||||||
BigDecimal unitPriceIncludingTax = new BigDecimal(totalAmount).divide(new BigDecimal(requestQty), 20, BigDecimal.ROUND_HALF_UP);
|
|
||||||
//含税单价*(O售后入库单)实退数量=实退金额
|
|
||||||
BigDecimal actualRefundAmount = unitPriceIncludingTax.multiply(new BigDecimal(requestQty)).setScale(4, BigDecimal.ROUND_HALF_UP);
|
|
||||||
//出库对应的实退=含税单价(actualRefundAmount)*出库单实退数量
|
|
||||||
String receivedQty = goodsRertunSonDetailsDto.getReceivedQty();
|
String receivedQty = goodsRertunSonDetailsDto.getReceivedQty();
|
||||||
Assert.notNull(receivedQty, "售后入库单号:{} 售后入库单明细行主键:{} 实收数量不能为空receivedQty!", header1.getCode(), goodsRertunSonDetailsDto.getId());
|
Assert.notNull(receivedQty, "售后订单:{} 存货明细行:{} 请求数量不能为空!", header1.getCode(), goodsRertunSonDetailsDto.getId());
|
||||||
BigDecimal actualRefundAmountBigDecimal = new BigDecimal(receivedQty).multiply(actualRefundAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
Assert.state(!"".equals(receivedQty), header1.getCode(), goodsRertunSonDetailsDto.getId());
|
||||||
|
if ("0".equals(new BigDecimal(receivedQty).stripTrailingZeros().toPlainString())) {
|
||||||
|
Assert.state(false, "售后订单:{} 存货明细行:{} 实退数量不能为0!", header1.getCode(), goodsRertunSonDetailsDto.getId());
|
||||||
|
}
|
||||||
|
//O含税单价=通过退货金额/请求数量
|
||||||
|
BigDecimal unitPriceIncludingTax = new BigDecimal(totalAmount).divide(new BigDecimal(requestQty), 20, BigDecimal.ROUND_HALF_UP);
|
||||||
|
//实退金额=O含税单价*(O售后入库单)实退数量
|
||||||
|
BigDecimal actualRefundAmount = unitPriceIncludingTax.multiply(new BigDecimal(receivedQty)).setScale(4, BigDecimal.ROUND_HALF_UP);
|
||||||
|
//出库对应的实退=含税单价(actualRefundAmount)*出库单实退数量
|
||||||
|
// BigDecimal actualRefundAmountBigDecimal = new BigDecimal(receivedQty).multiply(actualRefundAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
|
||||||
//商家优惠:不处理!!!仅保存
|
//商家优惠:不处理!!!仅保存
|
||||||
String merchantDiscounts = targetDetails.getMerchantDiscounts();
|
String merchantDiscounts = targetDetails.getMerchantDiscounts();
|
||||||
|
@ -2639,8 +2652,8 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
|
||||||
BigDecimal payDiscountsBigDecimal = new BigDecimal("0");//支付优惠
|
BigDecimal payDiscountsBigDecimal = new BigDecimal("0");//支付优惠
|
||||||
BigDecimal platformDiscountsBigDecimal = new BigDecimal("0");//平台优惠
|
BigDecimal platformDiscountsBigDecimal = new BigDecimal("0");//平台优惠
|
||||||
|
|
||||||
if (actualRefundAmountBigDecimal != null) {
|
if (actualRefundAmount != null) {
|
||||||
totalPayAmountBigDecimal = actualRefundAmountBigDecimal;
|
totalPayAmountBigDecimal = actualRefundAmount;
|
||||||
}
|
}
|
||||||
if (expertDiscounts != null && !"".equals(expertDiscounts)) {
|
if (expertDiscounts != null && !"".equals(expertDiscounts)) {
|
||||||
expertDiscountsBigDecimal = new BigDecimal(expertDiscounts);
|
expertDiscountsBigDecimal = new BigDecimal(expertDiscounts);
|
||||||
|
@ -2715,10 +2728,10 @@ public class SoSaleReturnPluginInitializerToC extends PluginBaseEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sonDetailsDtoList.get(0).setVdef4(platformDiscountsBigDecimal);
|
sonDetailsDtoList.get(0).setVdef4(platformDiscountsBigDecimal);//平台
|
||||||
sonDetailsDtoList.get(0).setVdef5(payDiscountsBigDecimal);
|
sonDetailsDtoList.get(0).setVdef5(payDiscountsBigDecimal);//支付
|
||||||
sonDetailsDtoList.get(0).setVdef6(expertDiscountsBigDecimal);
|
sonDetailsDtoList.get(0).setVdef6(expertDiscountsBigDecimal);//达人
|
||||||
sonDetailsDtoList.get(0).setVdef7(merchantDiscountsBigDecimal);
|
sonDetailsDtoList.get(0).setVdef7(merchantDiscountsBigDecimal);//商家
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -121,7 +121,7 @@ class SoSaleOutPluginInitializerToCTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// soSaleOutPluginInitializerToC.startImplementStockByCode("LETS-SH2024091900002878", "stock");
|
// soSaleOutPluginInitializerToC.startImplementStockByCode("LETS-SH2024091900002878", "stock");
|
||||||
soSaleOutPluginInitializerToC.startImplementStockByCode("LETS-SH2024110400042153", "stock");
|
soSaleOutPluginInitializerToC.startImplementStockByCode("LETS-SH2024110300036490", "tran");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class SoSaleReturnPluginInitializerToCTest {
|
||||||
public void startImplement() {
|
public void startImplement() {
|
||||||
// soSaleReturnPluginInitializerToC.startImplement(null, null);
|
// soSaleReturnPluginInitializerToC.startImplement(null, null);
|
||||||
try {
|
try {
|
||||||
String code = "LETS-SH2024110500018255";
|
String code = "LETS-RE2024110500004678";
|
||||||
soSaleReturnPluginInitializerToC.startImplementByCode(code, "stock");
|
soSaleReturnPluginInitializerToC.startImplementByCode(code, "stock");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue