| | |
| | | ErrorCode PURCHASE_REQUEST_ORDER_EXISTS = new ErrorCode(1_030_104_007, "采购申请单已生成采购订单,请勿重复操作"); |
| | | ErrorCode PURCHASE_REQUEST_BPM_CATEGORY_NOT_EXISTS = new ErrorCode(1_030_104_008, "采购申请审批分类不存在,请先在BPM模块创建采购申请审批流程分类"); |
| | | ErrorCode PURCHASE_REQUEST_BPM_PROCESS_DEFINITION_NOT_EXISTS = new ErrorCode(1_030_104_009, "采购申请审批分类下没有可用的流程模型,请先创建并发布流程"); |
| | | ErrorCode PURCHASE_REQUEST_ITEM_PRICE_EMPTY = new ErrorCode(1_030_104_021, "采购申请明细({})金额信息不完整,无法生成采购订单"); |
| | | |
| | | // ========== ERP 采购计划(1-030-104-010) ========== |
| | | ErrorCode PURCHASE_PLAN_NOT_EXISTS = new ErrorCode(1_030_104_010, "采购计划不存在"); |
| | |
| | | if (ErpPurchaseRequestStatusEnum.APPROVE.getStatus().equals(newStatus) |
| | | && purchaseRequest.getSupplierId() != null |
| | | && purchaseRequest.getOrderId() == null) { |
| | | try { |
| | | Long orderId = doGeneratePurchaseOrder(purchaseRequest); |
| | | log.info("[updatePurchaseRequestAuditStatus] 采购申请({}) 自动生成采购订单({})", id, orderId); |
| | | } catch (Exception e) { |
| | | log.error("[updatePurchaseRequestAuditStatus] 采购申请({}) 自动生成采购订单失败", id, e); |
| | | // 不抛出异常,避免影响状态更新 |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if (CollUtil.isEmpty(requestItems)) { |
| | | throw exception(PURCHASE_REQUEST_NOT_EXISTS); |
| | | } |
| | | requestItems.forEach(item -> { |
| | | if (item.getProductPrice() == null || item.getTotalPrice() == null || item.getTaxPrice() == null) { |
| | | throw exception(PURCHASE_REQUEST_ITEM_PRICE_EMPTY, item.getId()); |
| | | } |
| | | }); |
| | | |
| | | // 2. 生成采购订单号 |
| | | String orderNo = noRedisDAO.generate(ErpNoRedisDAO.PURCHASE_ORDER_NO_PREFIX); |
| | |
| | | if (item == null) { |
| | | continue; |
| | | } |
| | | // 如果物料开启批次管理,检查行上的批次号是否为空 |
| | | if (Boolean.TRUE.equals(item.getIsBatchManaged()) && line.getBatchId() == null) { |
| | | // 如果物料开启批次管理,行或其上架明细必须携带批次号,否则无法生成库存事务 |
| | | if (Boolean.TRUE.equals(item.getIsBatchManaged())) { |
| | | boolean hasBatch = line.getBatchId() != null |
| | | || hasDetailBatch(itemReceiptDetailService.getItemReceiptDetailListByLineId(line.getId())); |
| | | if (!hasBatch) { |
| | | throw exception(WM_ITEM_RECEIPT_BATCH_REQUIRED, item.getCode(), item.getName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private boolean hasDetailBatch(List<MesWmItemReceiptDetailDO> details) { |
| | | return details.stream().anyMatch(detail -> detail.getBatchId() != null); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |