Search in sources :

Example 1 with OperationOrder

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

the class ManufOrderWorkFlowMaintenanceService method plan.

@Transactional(rollbackOn = { Exception.class })
@Override
public ManufOrder plan(ManufOrder manufOrder) throws AxelorException {
    if (manufOrder.getTypeSelect() != ManufOrderRepository.TYPE_MAINTENANCE) {
        return super.plan(manufOrder);
    }
    ManufOrderService manufOrderService = Beans.get(ManufOrderService.class);
    if (Beans.get(SequenceService.class).isEmptyOrDraftSequenceNumber(manufOrder.getManufOrderSeq())) {
        manufOrder.setManufOrderSeq(manufOrderService.getManufOrderSeq(manufOrder));
    }
    if (CollectionUtils.isEmpty(manufOrder.getOperationOrderList())) {
        manufOrderService.preFillOperations(manufOrder);
    }
    if (!manufOrder.getIsConsProOnOperation() && CollectionUtils.isEmpty(manufOrder.getToConsumeProdProductList())) {
        manufOrderService.createToConsumeProdProductList(manufOrder);
    }
    if (CollectionUtils.isEmpty(manufOrder.getToProduceProdProductList())) {
        manufOrderService.createToProduceProdProductList(manufOrder);
    }
    if (manufOrder.getPlannedStartDateT() == null) {
        manufOrder.setPlannedStartDateT(Beans.get(AppProductionService.class).getTodayDateTime().toLocalDateTime());
    }
    for (OperationOrder operationOrder : getSortedOperationOrderList(manufOrder)) {
        operationOrderWorkflowService.plan(operationOrder, null);
    }
    manufOrder.setPlannedEndDateT(this.computePlannedEndDateT(manufOrder));
    if (manufOrder.getBillOfMaterial() != null) {
        manufOrder.setUnit(manufOrder.getBillOfMaterial().getUnit());
    }
    manufOrder.setStatusSelect(ManufOrderRepository.STATUS_PLANNED);
    manufOrder.setCancelReason(null);
    manufOrder.setCancelReasonStr(null);
    return manufOrderRepo.save(manufOrder);
}
Also used : ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) SequenceService(com.axelor.apps.base.service.administration.SequenceService) OperationOrder(com.axelor.apps.production.db.OperationOrder) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) Transactional(com.google.inject.persist.Transactional)

Example 2 with OperationOrder

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

the class ManufOrderWorkFlowMaintenanceService method finish.

@Transactional(rollbackOn = { Exception.class })
@Override
public boolean finish(ManufOrder manufOrder) throws AxelorException {
    if (manufOrder.getTypeSelect() != ManufOrderRepository.TYPE_MAINTENANCE) {
        return super.finish(manufOrder);
    } else {
        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);
                }
            }
        }
        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);
        return true;
    }
}
Also used : 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)

Example 3 with OperationOrder

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

the class ManufOrderStockMoveService method partialFinish.

/**
 * Call the method to realize in stock move, then the method to realize out stock move for the
 * given manufacturing order.
 *
 * @param manufOrder
 */
@Transactional(rollbackOn = { Exception.class })
public void partialFinish(ManufOrder manufOrder) throws AxelorException {
    if (manufOrder.getIsConsProOnOperation()) {
        for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
            if (operationOrder.getStatusSelect() == OperationOrderRepository.STATUS_IN_PROGRESS) {
                Beans.get(OperationOrderStockMoveService.class).partialFinish(operationOrder);
            }
        }
    } else {
        partialFinish(manufOrder, PART_FINISH_IN);
    }
    partialFinish(manufOrder, PART_FINISH_OUT);
    Beans.get(ManufOrderRepository.class).save(manufOrder);
}
Also used : ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) OperationOrder(com.axelor.apps.production.db.OperationOrder) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) Transactional(com.google.inject.persist.Transactional)

Example 4 with OperationOrder

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

the class ManufOrderWorkflowService method createPurchaseOrder.

@Transactional
public void createPurchaseOrder(ManufOrder manufOrder) throws AxelorException {
    PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderService.class).createPurchaseOrder(null, manufOrder.getCompany(), null, null, null, null, null, null, null, manufOrder.getProdProcess().getSubcontractors(), null);
    purchaseOrder.setOutsourcingOrder(true);
    if (manufOrder.getCompany() != null && manufOrder.getCompany().getStockConfig() != null) {
        purchaseOrder.setStockLocation(manufOrder.getCompany().getStockConfig().getOutsourcingReceiptStockLocation());
    }
    this.setPurchaseOrderSupplierDetails(purchaseOrder);
    for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
        if (operationOrder.getUseLineInGeneratedPurchaseOrder()) {
            this.createPurchaseOrderLineProduction(operationOrder, purchaseOrder);
        }
    }
    Beans.get(PurchaseOrderService.class).computePurchaseOrder(purchaseOrder);
    manufOrder.setPurchaseOrder(purchaseOrder);
    manufOrderRepo.save(manufOrder);
}
Also used : PurchaseOrderService(com.axelor.apps.purchase.service.PurchaseOrderService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Example 5 with OperationOrder

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

the class ManufOrderWorkflowService method partialFinish.

/**
 * Allows to finish partially a manufacturing order, by realizing current stock move and planning
 * the difference with the planned prodproducts.
 *
 * @param manufOrder
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public boolean partialFinish(ManufOrder manufOrder) throws AxelorException {
    if (manufOrder.getIsConsProOnOperation()) {
        for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
            if (operationOrder.getStatusSelect() == OperationOrderRepository.STATUS_PLANNED) {
                operationOrderWorkflowService.start(operationOrder);
            }
        }
    }
    Beans.get(CostSheetService.class).computeCostPrice(manufOrder, CostSheetRepository.CALCULATION_PARTIAL_END_OF_PRODUCTION, Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
    Beans.get(ManufOrderStockMoveService.class).partialFinish(manufOrder);
    ProductionConfig productionConfig = manufOrder.getCompany() != null ? productionConfigRepo.findByCompany(manufOrder.getCompany()) : null;
    if (productionConfig != null && productionConfig.getPartFinishMoAutomaticEmail()) {
        return this.sendMail(manufOrder, productionConfig.getPartFinishMoMessageTemplate());
    }
    return true;
}
Also used : CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) OperationOrder(com.axelor.apps.production.db.OperationOrder) 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