fix(integration): return MES inventory on consume voucher reverse
After SAP 262 whole-voucher cancel, write the reverse WMS qty back to the original line-side lot and clear consume occupancy.
This commit is contained in:
parent
4c66da0d0f
commit
4acd51bf3c
@ -29,6 +29,9 @@ import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
|
||||
import com.foreverwin.mom.common.log.annotation.SysLog;
|
||||
import com.foreverwin.mom.common.security.annotation.Inner;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import com.foreverwin.mom.wms.api.feign.RemoteWmsInventoryService;
|
||||
import com.foreverwin.mom.wms.dto.InventoryQtyAdjustRequest;
|
||||
import com.foreverwin.mom.wms.entity.Inventory;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -80,6 +83,7 @@ public class ShopOrderStatisticTransController {
|
||||
|
||||
private final MaterialQtyAdjustmentQueryMapper materialQtyAdjustmentQueryMapper;
|
||||
private final ShopOrderStatusGuard shopOrderStatusGuard;
|
||||
private final RemoteWmsInventoryService remoteWmsInventoryService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("ZMM_MES_GOODMVT_REVERSE") // 通过 Bean 名称注入
|
||||
@ -448,11 +452,7 @@ public class ShopOrderStatisticTransController {
|
||||
targetObj.setUpdater(user);
|
||||
targetObj.setDateUpdate(localDateTime);
|
||||
zLotMaterialConsumptionTransactionMapper.updateById(targetObj);
|
||||
LotMaterial lotMaterial = lotMaterialMapper.selectById(targetObj.getLotMaterialSid());
|
||||
if (lotMaterial != null) {
|
||||
lotMaterial.setErpFlag("N");
|
||||
lotMaterialMapper.updateById(lotMaterial);
|
||||
}
|
||||
returnMesInventory(targetObj, user, localDateTime);
|
||||
// 添加物料消耗冲销事务表(262)
|
||||
ZLotMaterialConsumptionTransactionOff zLotMaterialConsumptionTransactionOff = new ZLotMaterialConsumptionTransactionOff();
|
||||
// 属性copy
|
||||
@ -527,6 +527,40 @@ public class ShopOrderStatisticTransController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
private void returnMesInventory(ZLotMaterialConsumptionTransaction targetObj, String user, LocalDateTime now) {
|
||||
BigDecimal qty = targetObj.getMainQty() == null ? BigDecimal.ZERO : targetObj.getMainQty();
|
||||
LotMaterial lotMaterial = targetObj.getLotMaterialSid() == null
|
||||
? null : lotMaterialMapper.selectById(targetObj.getLotMaterialSid());
|
||||
if (qty.compareTo(BigDecimal.ZERO) > 0) {
|
||||
InventoryQtyAdjustRequest inventoryRequest = new InventoryQtyAdjustRequest();
|
||||
inventoryRequest.setRequestId(targetObj.getSid() + ":cv:" + qty.toPlainString());
|
||||
inventoryRequest.setInventoryBo(Inventory.genHandle(targetObj.getSite(), targetObj.getMaterialLot()));
|
||||
inventoryRequest.setDeltaQty(qty);
|
||||
inventoryRequest.setExpectedMaterialLot(targetObj.getMaterialLot());
|
||||
if (lotMaterial != null) {
|
||||
inventoryRequest.setExpectedItemBo(lotMaterial.getItemBo());
|
||||
}
|
||||
inventoryRequest.setExpectedBatchNo(targetObj.getSapBatchNo());
|
||||
inventoryRequest.setChangeType("MATERIAL_CONSUMPTION_CANCEL");
|
||||
inventoryRequest.setOperator(user);
|
||||
inventoryRequest.setComments(targetObj.getShopOrder() + "整单冲销退回线边库");
|
||||
R<Inventory> inventoryResult = remoteWmsInventoryService.adjustQty(inventoryRequest);
|
||||
if (inventoryResult == null || inventoryResult.getCode() != 0 || inventoryResult.getData() == null) {
|
||||
throw BusinessException.build(inventoryResult == null ? "SAP已冲销,MES库存回退未返回结果"
|
||||
: "SAP已冲销,MES库存回退失败:" + inventoryResult.getMsg());
|
||||
}
|
||||
}
|
||||
if (lotMaterial == null) {
|
||||
return;
|
||||
}
|
||||
lotMaterial.setErpFlag("N");
|
||||
lotMaterial.setConsumeQty(BigDecimal.ZERO);
|
||||
lotMaterial.setQty(BigDecimal.ZERO);
|
||||
lotMaterial.setRemoved("Y");
|
||||
lotMaterial.setRemovedDate(now);
|
||||
lotMaterialMapper.updateById(lotMaterial);
|
||||
}
|
||||
|
||||
private InvokeResponse sendSapToCancel(String syncVoucherNo) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user