use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class OperationOrderWorkflowService method plan.
/**
* Plan an operation order. For successive calls, must be called by order of operation order
* priority.
*
* @param operationOrder
* @return
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public OperationOrder plan(OperationOrder operationOrder, Long cumulatedDuration) throws AxelorException {
if (CollectionUtils.isEmpty(operationOrder.getToConsumeProdProductList())) {
Beans.get(OperationOrderService.class).createToConsumeProdProductList(operationOrder);
}
LocalDateTime plannedStartDate = operationOrder.getPlannedStartDateT();
LocalDateTime lastOPerationDate = this.getLastOperationOrder(operationOrder);
LocalDateTime maxDate = DateTool.max(plannedStartDate, lastOPerationDate);
operationOrder.setPlannedStartDateT(maxDate);
Machine machine = operationOrder.getMachine();
WeeklyPlanning weeklyPlanning = null;
if (machine != null) {
weeklyPlanning = machine.getWeeklyPlanning();
}
if (weeklyPlanning != null) {
this.planWithPlanning(operationOrder, weeklyPlanning);
}
operationOrder.setPlannedEndDateT(this.computePlannedEndDateT(operationOrder));
if (cumulatedDuration != null) {
operationOrder.setPlannedEndDateT(operationOrder.getPlannedEndDateT().minusSeconds(cumulatedDuration).plusSeconds(this.getMachineSetupDuration(operationOrder)));
}
Long plannedDuration = DurationTool.getSecondsDuration(Duration.between(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT()));
operationOrder.setPlannedDuration(plannedDuration);
if (weeklyPlanning != null) {
this.manageDurationWithMachinePlanning(operationOrder, weeklyPlanning, plannedDuration);
}
ManufOrder manufOrder = operationOrder.getManufOrder();
if (manufOrder == null || manufOrder.getIsConsProOnOperation()) {
operationOrderStockMoveService.createToConsumeStockMove(operationOrder);
}
operationOrder.setStatusSelect(OperationOrderRepository.STATUS_PLANNED);
return operationOrderRepo.save(operationOrder);
}
use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderWorkflowService method plan.
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public List<ManufOrder> plan(List<ManufOrder> manufOrderList, boolean quickSolve) throws AxelorException {
ManufOrderService manufOrderService = Beans.get(ManufOrderService.class);
SequenceService sequenceService = Beans.get(SequenceService.class);
for (ManufOrder manufOrder : manufOrderList) {
if (manufOrder.getBillOfMaterial().getStatusSelect() != BillOfMaterialRepository.STATUS_APPLICABLE || manufOrder.getProdProcess().getStatusSelect() != ProdProcessRepository.STATUS_APPLICABLE) {
throw new AxelorException(manufOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.CHECK_BOM_AND_PROD_PROCESS));
}
if (sequenceService.isEmptyOrDraftSequenceNumber(manufOrder.getManufOrderSeq())) {
manufOrder.setManufOrderSeq(manufOrderService.getManufOrderSeq(manufOrder));
}
if (CollectionUtils.isEmpty(manufOrder.getOperationOrderList())) {
manufOrderService.preFillOperations(manufOrder);
} else {
manufOrderService.updateOperationsName(manufOrder);
}
if (!manufOrder.getIsConsProOnOperation() && CollectionUtils.isEmpty(manufOrder.getToConsumeProdProductList())) {
manufOrderService.createToConsumeProdProductList(manufOrder);
}
if (CollectionUtils.isEmpty(manufOrder.getToProduceProdProductList())) {
manufOrderService.createToProduceProdProductList(manufOrder);
}
if (manufOrder.getPlannedStartDateT() == null && manufOrder.getPlannedEndDateT() == null) {
manufOrder.setPlannedStartDateT(Beans.get(AppProductionService.class).getTodayDateTime().toLocalDateTime());
} else if (manufOrder.getPlannedStartDateT() == null && manufOrder.getPlannedEndDateT() != null) {
long duration = 0;
for (OperationOrder order : manufOrder.getOperationOrderList()) {
duration += operationOrderWorkflowService.computeEntireCycleDuration(order, // in seconds
order.getManufOrder().getQty());
}
manufOrder.setPlannedStartDateT(manufOrder.getPlannedEndDateT().minusSeconds(duration));
}
}
for (ManufOrder manufOrder : manufOrderList) {
if (manufOrder.getOperationOrderList() != null) {
for (OperationOrder operationOrder : getSortedOperationOrderList(manufOrder)) {
operationOrderWorkflowService.plan(operationOrder, null);
}
}
}
for (ManufOrder manufOrder : manufOrderList) {
if (manufOrder.getPlannedEndDateT() == null) {
manufOrder.setPlannedEndDateT(this.computePlannedEndDateT(manufOrder));
}
if (manufOrder.getBillOfMaterial() != null) {
manufOrder.setUnit(manufOrder.getBillOfMaterial().getUnit());
}
if (!manufOrder.getIsConsProOnOperation()) {
manufOrderStockMoveService.createToConsumeStockMove(manufOrder);
}
manufOrderStockMoveService.createToProduceStockMove(manufOrder);
manufOrder.setStatusSelect(ManufOrderRepository.STATUS_PLANNED);
manufOrder.setCancelReason(null);
manufOrder.setCancelReasonStr(null);
manufOrderRepo.save(manufOrder);
Beans.get(ProductionOrderService.class).updateStatus(manufOrder.getProductionOrderSet());
}
return manufOrderList;
}
use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class OperationOrderStockMoveService method partialFinish.
/**
* Allows to create and realize in stock moves for the given operation order. This method is used
* during a partial finish.
*
* @param operationOrder
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void partialFinish(OperationOrder operationOrder) throws AxelorException {
ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
ManufOrder manufOrder = operationOrder.getManufOrder();
Company company = manufOrder.getCompany();
StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
StockLocation fromStockLocation;
StockLocation toStockLocation;
List<StockMove> stockMoveList;
stockMoveList = operationOrder.getInStockMoveList();
fromStockLocation = manufOrderStockMoveService.getDefaultStockLocation(manufOrder, company, ManufOrderStockMoveService.STOCK_LOCATION_IN);
toStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, operationOrder.getManufOrder().getProdProcess().getOutsourcing());
// realize current stock move
Optional<StockMove> stockMoveToRealize = stockMoveList.stream().filter(stockMove -> stockMove.getStatusSelect() == StockMoveRepository.STATUS_PLANNED && !CollectionUtils.isEmpty(stockMove.getStockMoveLineList())).findFirst();
if (stockMoveToRealize.isPresent()) {
manufOrderStockMoveService.finishStockMove(stockMoveToRealize.get());
}
// generate new stock move
StockMove newStockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, toStockLocation, null, operationOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
newStockMove.setOrigin(operationOrder.getOperationName());
newStockMove.setOriginId(operationOrder.getId());
newStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_OPERATION_ORDER);
newStockMove.setStockMoveLineList(new ArrayList<>());
createNewStockMoveLines(operationOrder, newStockMove);
if (!newStockMove.getStockMoveLineList().isEmpty()) {
// plan the stockmove
stockMoveService.plan(newStockMove);
operationOrder.addInStockMoveListItem(newStockMove);
newStockMove.getStockMoveLineList().forEach(operationOrder::addConsumedStockMoveLineListItem);
operationOrder.clearDiffConsumeProdProductList();
}
}
use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderController method preFillOperations.
public void preFillOperations(ActionRequest request, ActionResponse response) throws AxelorException {
try {
ManufOrder manufOrder = request.getContext().asType(ManufOrder.class);
ManufOrderService moService = Beans.get(ManufOrderService.class);
manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrder.getId());
moService.preFillOperations(manufOrder);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderController method multiLevelManufOrderOnLoad.
/**
* Called from manuf order form, on clicking "Multi-level planning" button.
*
* @param request
* @param response
*/
public void multiLevelManufOrderOnLoad(ActionRequest request, ActionResponse response) {
try {
Long moId = Long.valueOf(request.getContext().get("id").toString());
ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
boolean showOnlyMissingQty = request.getContext().get("_showOnlyMissingQty") != null && Boolean.parseBoolean(request.getContext().get("_showOnlyMissingQty").toString());
ProdProductProductionRepository prodProductProductionRepository = Beans.get(ProdProductProductionRepository.class);
List<ProdProduct> prodProducts = mo.getToConsumeProdProductList().stream().filter(prodProduct -> prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_FINISHED_PRODUCT || prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_SEMI_FINISHED_PRODUCT).filter(prodProduct -> !showOnlyMissingQty || prodProductProductionRepository.computeMissingQty(prodProduct.getProduct().getId(), prodProduct.getQty(), moId).compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
response.setValue("$components", prodProducts);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations