Search in sources :

Example 36 with ManufOrder

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) Machine(com.axelor.apps.production.db.Machine) ManufOrder(com.axelor.apps.production.db.ManufOrder) Transactional(com.google.inject.persist.Transactional)

Example 37 with ManufOrder

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) SequenceService(com.axelor.apps.base.service.administration.SequenceService) ProductionOrderService(com.axelor.apps.production.service.productionorder.ProductionOrderService) OperationOrder(com.axelor.apps.production.db.OperationOrder) ManufOrder(com.axelor.apps.production.db.ManufOrder) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) Transactional(com.google.inject.persist.Transactional)

Example 38 with ManufOrder

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();
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) Inject(com.google.inject.Inject) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) CollectionUtils(org.apache.commons.collections.CollectionUtils) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) OperationOrder(com.axelor.apps.production.db.OperationOrder) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) Beans(com.axelor.inject.Beans) ManufOrder(com.axelor.apps.production.db.ManufOrder) Optional(java.util.Optional) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockConfig(com.axelor.apps.stock.db.StockConfig) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) ManufOrder(com.axelor.apps.production.db.ManufOrder) Transactional(com.google.inject.persist.Transactional)

Example 39 with ManufOrder

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);
    }
}
Also used : ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 40 with ManufOrder

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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) BirtException(org.eclipse.birt.core.exception.BirtException) CostSheetRepository(com.axelor.apps.production.db.repo.CostSheetRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) I18n(com.axelor.i18n.I18n) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ActionRequest(com.axelor.rpc.ActionRequest) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) ManufOrderPrintService(com.axelor.apps.production.service.manuforder.ManufOrderPrintService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MethodHandles(java.lang.invoke.MethodHandles) CostSheet(com.axelor.apps.production.db.CostSheet) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) List(java.util.List) IReport(com.axelor.apps.production.report.IReport) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ReportFactory(com.axelor.apps.ReportFactory) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Context(com.axelor.rpc.Context) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Singleton(com.google.inject.Singleton) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Aggregations

ManufOrder (com.axelor.apps.production.db.ManufOrder)44 AxelorException (com.axelor.exception.AxelorException)30 IOException (java.io.IOException)22 BirtException (org.eclipse.birt.core.exception.BirtException)22 ManufOrderRepository (com.axelor.apps.production.db.repo.ManufOrderRepository)17 ManufOrderService (com.axelor.apps.production.service.manuforder.ManufOrderService)12 BigDecimal (java.math.BigDecimal)12 ArrayList (java.util.ArrayList)12 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)11 List (java.util.List)11 ProdProduct (com.axelor.apps.production.db.ProdProduct)10 ManufOrderWorkflowService (com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService)10 Transactional (com.google.inject.persist.Transactional)10 Beans (com.axelor.inject.Beans)9 Company (com.axelor.apps.base.db.Company)8 Product (com.axelor.apps.base.db.Product)8 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)8 IExceptionMessage (com.axelor.apps.production.exceptions.IExceptionMessage)8 I18n (com.axelor.i18n.I18n)8