Search in sources :

Example 36 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.

the class ManufOrderWorkflowService method pause.

@Transactional
public void pause(ManufOrder manufOrder) {
    if (manufOrder.getOperationOrderList() != null) {
        for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
            if (operationOrder.getStatusSelect() == OperationOrderRepository.STATUS_IN_PROGRESS) {
                operationOrderWorkflowService.pause(operationOrder);
            }
        }
    }
    manufOrder.setStatusSelect(ManufOrderRepository.STATUS_STANDBY);
    manufOrderRepo.save(manufOrder);
}
Also used : OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Example 37 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.

the class ManufOrderWorkflowService method cancel.

@Transactional(rollbackOn = { Exception.class })
public void cancel(ManufOrder manufOrder, CancelReason cancelReason, String cancelReasonStr) throws AxelorException {
    if (cancelReason == null && manufOrder.getStatusSelect() != ManufOrderRepository.STATUS_DRAFT && manufOrder.getStatusSelect() != ManufOrderRepository.STATUS_PLANNED) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MANUF_ORDER_CANCEL_REASON_ERROR));
    }
    if (manufOrder.getOperationOrderList() != null) {
        for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
            if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_CANCELED) {
                operationOrderWorkflowService.cancel(operationOrder);
            }
        }
    }
    manufOrderStockMoveService.cancel(manufOrder);
    if (manufOrder.getConsumedStockMoveLineList() != null) {
        manufOrder.getConsumedStockMoveLineList().forEach(stockMoveLine -> stockMoveLine.setConsumedManufOrder(null));
    }
    if (manufOrder.getProducedStockMoveLineList() != null) {
        manufOrder.getProducedStockMoveLineList().forEach(stockMoveLine -> stockMoveLine.setProducedManufOrder(null));
    }
    if (manufOrder.getDiffConsumeProdProductList() != null) {
        manufOrder.clearDiffConsumeProdProductList();
    }
    manufOrder.setStatusSelect(ManufOrderRepository.STATUS_CANCELED);
    if (cancelReason != null) {
        manufOrder.setCancelReason(cancelReason);
        if (Strings.isNullOrEmpty(cancelReasonStr)) {
            manufOrder.setCancelReasonStr(cancelReason.getName());
        } else {
            manufOrder.setCancelReasonStr(cancelReasonStr);
        }
    }
    manufOrderRepo.save(manufOrder);
    Beans.get(ProductionOrderService.class).updateStatus(manufOrder.getProductionOrderSet());
}
Also used : AxelorException(com.axelor.exception.AxelorException) ProductionOrderService(com.axelor.apps.production.service.productionorder.ProductionOrderService) OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Example 38 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.

the class ManufOrderWorkflowService method updatePlannedDates.

/**
 * Update planned dates.
 *
 * @param manufOrder
 * @param plannedStartDateT
 */
@Transactional(rollbackOn = { Exception.class })
public void updatePlannedDates(ManufOrder manufOrder, LocalDateTime plannedStartDateT) throws AxelorException {
    manufOrder.setPlannedStartDateT(plannedStartDateT);
    if (manufOrder.getOperationOrderList() != null) {
        List<OperationOrder> operationOrderList = getSortedOperationOrderList(manufOrder);
        operationOrderWorkflowService.resetPlannedDates(operationOrderList);
        for (OperationOrder operationOrder : operationOrderList) {
            operationOrderWorkflowService.replan(operationOrder);
        }
    }
    manufOrder.setPlannedEndDateT(computePlannedEndDateT(manufOrder));
}
Also used : OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Example 39 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder 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 40 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.

the class ManufOrderWorkflowService method finish.

@Transactional(rollbackOn = { Exception.class })
public boolean finish(ManufOrder manufOrder) throws AxelorException {
    if (manufOrder.getOperationOrderList() != null) {
        for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
            if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_FINISHED) {
                if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_IN_PROGRESS && operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_STANDBY) {
                    operationOrderWorkflowService.start(operationOrder);
                }
                operationOrderWorkflowService.finish(operationOrder);
            }
        }
    }
    // create cost sheet
    Beans.get(CostSheetService.class).computeCostPrice(manufOrder, CostSheetRepository.CALCULATION_END_OF_PRODUCTION, Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
    // update price in product
    Product product = manufOrder.getProduct();
    Company company = manufOrder.getCompany();
    if (((Integer) productCompanyService.get(product, "realOrEstimatedPriceSelect", company)) == ProductRepository.PRICE_METHOD_FORECAST) {
        productCompanyService.set(product, "lastProductionPrice", manufOrder.getBillOfMaterial().getCostPrice(), company);
    } else if (((Integer) productCompanyService.get(product, "realOrEstimatedPriceSelect", company)) == ProductRepository.PRICE_METHOD_REAL) {
        BigDecimal costPrice = computeOneUnitProductionPrice(manufOrder);
        if (costPrice.signum() != 0) {
            productCompanyService.set(product, "lastProductionPrice", costPrice, company);
        }
    } else {
        // default value is forecast
        productCompanyService.set(product, "realOrEstimatedPriceSelect", ProductRepository.PRICE_METHOD_FORECAST, company);
        productCompanyService.set(product, "lastProductionPrice", manufOrder.getBillOfMaterial().getCostPrice(), company);
    }
    // update costprice in product
    if (((Integer) productCompanyService.get(product, "costTypeSelect", company)) == ProductRepository.COST_TYPE_LAST_PRODUCTION_PRICE) {
        productCompanyService.set(product, "costPrice", (BigDecimal) productCompanyService.get(product, "lastProductionPrice", company), company);
        if ((Boolean) productCompanyService.get(product, "autoUpdateSalePrice", company)) {
            Beans.get(ProductService.class).updateSalePrice(product, company);
        }
    }
    manufOrderStockMoveService.finish(manufOrder);
    manufOrder.setRealEndDateT(Beans.get(AppProductionService.class).getTodayDateTime().toLocalDateTime());
    manufOrder.setStatusSelect(ManufOrderRepository.STATUS_FINISHED);
    manufOrder.setEndTimeDifference(new BigDecimal(ChronoUnit.MINUTES.between(manufOrder.getPlannedEndDateT(), manufOrder.getRealEndDateT())));
    manufOrderRepo.save(manufOrder);
    Beans.get(ProductionOrderService.class).updateStatus(manufOrder.getProductionOrderSet());
    ProductionConfig productionConfig = manufOrder.getCompany() != null ? productionConfigRepo.findByCompany(manufOrder.getCompany()) : null;
    if (productionConfig != null && productionConfig.getFinishMoAutomaticEmail()) {
        return this.sendMail(manufOrder, productionConfig.getFinishMoMessageTemplate());
    }
    return true;
}
Also used : Company(com.axelor.apps.base.db.Company) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ProductService(com.axelor.apps.base.service.ProductService) Product(com.axelor.apps.base.db.Product) ProductionOrderService(com.axelor.apps.production.service.productionorder.ProductionOrderService) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) OperationOrder(com.axelor.apps.production.db.OperationOrder) BigDecimal(java.math.BigDecimal) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) Transactional(com.google.inject.persist.Transactional)

Aggregations

OperationOrder (com.axelor.apps.production.db.OperationOrder)44 Transactional (com.google.inject.persist.Transactional)24 IOException (java.io.IOException)12 BirtException (org.eclipse.birt.core.exception.BirtException)11 OperationOrderWorkflowService (com.axelor.apps.production.service.operationorder.OperationOrderWorkflowService)10 AxelorException (com.axelor.exception.AxelorException)9 BigDecimal (java.math.BigDecimal)9 OperationOrderRepository (com.axelor.apps.production.db.repo.OperationOrderRepository)8 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)7 LocalDateTime (java.time.LocalDateTime)7 ArrayList (java.util.ArrayList)6 ManufOrder (com.axelor.apps.production.db.ManufOrder)5 Company (com.axelor.apps.base.db.Company)4 ProdProduct (com.axelor.apps.production.db.ProdProduct)4 StockMove (com.axelor.apps.stock.db.StockMove)4 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)4 DayPlanning (com.axelor.apps.base.db.DayPlanning)3 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)3 ManufOrderStockMoveService (com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService)3 ProductionOrderService (com.axelor.apps.production.service.productionorder.ProductionOrderService)3