Search in sources :

Example 6 with OperationOrder

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

the class ManufOrderWorkflowService method resume.

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

Example 7 with OperationOrder

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

the class ManufOrderWorkflowService method allOpFinished.

@Transactional(rollbackOn = { Exception.class })
public void allOpFinished(ManufOrder manufOrder) throws AxelorException {
    int count = 0;
    List<OperationOrder> operationOrderList = manufOrder.getOperationOrderList();
    for (OperationOrder operationOrderIt : operationOrderList) {
        if (operationOrderIt.getStatusSelect() == OperationOrderRepository.STATUS_FINISHED) {
            count++;
        }
    }
    if (count == operationOrderList.size()) {
        this.finish(manufOrder);
    }
}
Also used : OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Example 8 with OperationOrder

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

the class OperationOrderServiceImpl method updateConsumedStockMoveFromOperationOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateConsumedStockMoveFromOperationOrder(OperationOrder operationOrder) throws AxelorException {
    this.updateDiffProdProductList(operationOrder);
    List<StockMoveLine> consumedStockMoveLineList = operationOrder.getConsumedStockMoveLineList();
    if (consumedStockMoveLineList == null) {
        return;
    }
    Optional<StockMove> stockMoveOpt = operationOrder.getInStockMoveList().stream().filter(stockMove -> stockMove.getStatusSelect() == StockMoveRepository.STATUS_PLANNED).findFirst();
    StockMove stockMove;
    if (stockMoveOpt.isPresent()) {
        stockMove = stockMoveOpt.get();
    } else {
        stockMove = Beans.get(ManufOrderStockMoveService.class)._createToConsumeStockMove(operationOrder.getManufOrder(), operationOrder.getManufOrder().getCompany());
        operationOrder.addInStockMoveListItem(stockMove);
        Beans.get(StockMoveService.class).plan(stockMove);
    }
    Beans.get(ManufOrderService.class).updateStockMoveFromManufOrder(consumedStockMoveLineList, stockMove);
}
Also used : ProdHumanResource(com.axelor.apps.production.db.ProdHumanResource) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Machine(com.axelor.apps.production.db.Machine) Duration(java.time.Duration) Map(java.util.Map) I18n(com.axelor.i18n.I18n) MachineTool(com.axelor.apps.production.db.MachineTool) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ProdProduct(com.axelor.apps.production.db.ProdProduct) RoundingMode(java.math.RoundingMode) BarcodeGeneratorService(com.axelor.apps.base.service.BarcodeGeneratorService) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) MetaFiles(com.axelor.meta.MetaFiles) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) IOException(java.io.IOException) OperationOrder(com.axelor.apps.production.db.OperationOrder) OperationOrderRepository(com.axelor.apps.production.db.repo.OperationOrderRepository) DayPlanning(com.axelor.apps.base.db.DayPlanning) WorkCenter(com.axelor.apps.production.db.WorkCenter) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) MetaFile(com.axelor.meta.db.MetaFile) List(java.util.List) Beans(com.axelor.inject.Beans) ManufOrder(com.axelor.apps.production.db.ManufOrder) ValidationException(javax.validation.ValidationException) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) InputStream(java.io.InputStream) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Example 9 with OperationOrder

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

the class OperationOrderServiceImpl method chargeByMachineHours.

public List<Map<String, Object>> chargeByMachineHours(LocalDateTime fromDateTime, LocalDateTime toDateTime) throws AxelorException {
    List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
    LocalDateTime itDateTime = LocalDateTime.parse(fromDateTime.toString(), DateTimeFormatter.ISO_DATE_TIME);
    OperationOrderRepository operationOrderRepo = Beans.get(OperationOrderRepository.class);
    if (Duration.between(fromDateTime, toDateTime).toDays() > 20) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS));
    }
    List<OperationOrder> operationOrderListTemp = operationOrderRepo.all().filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime).fetch();
    Set<String> machineNameList = new HashSet<String>();
    for (OperationOrder operationOrder : operationOrderListTemp) {
        if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
            if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) {
                machineNameList.add(operationOrder.getWorkCenter().getMachine().getName());
            }
        }
    }
    while (!itDateTime.isAfter(toDateTime)) {
        List<OperationOrder> operationOrderList = operationOrderRepo.all().filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime, itDateTime.plusHours(1)).fetch();
        Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
        for (OperationOrder operationOrder : operationOrderList) {
            if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
                String machine = operationOrder.getWorkCenter().getMachine().getName();
                long numberOfMinutes = 0;
                if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) {
                    numberOfMinutes = Duration.between(itDateTime, operationOrder.getPlannedEndDateT()).toMinutes();
                } else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) {
                    numberOfMinutes = Duration.between(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1)).toMinutes();
                } else {
                    numberOfMinutes = Duration.between(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT()).toMinutes();
                }
                if (numberOfMinutes > 60) {
                    numberOfMinutes = 60;
                }
                BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100)).divide(new BigDecimal(60), 2, RoundingMode.HALF_UP);
                if (map.containsKey(machine)) {
                    map.put(machine, map.get(machine).add(percentage));
                } else {
                    map.put(machine, percentage);
                }
            }
        }
        Set<String> keyList = map.keySet();
        for (String key : machineNameList) {
            if (keyList.contains(key)) {
                Map<String, Object> dataMap = new HashMap<String, Object>();
                dataMap.put("dateTime", (Object) itDateTime.format(DATE_TIME_FORMAT));
                dataMap.put("charge", (Object) map.get(key));
                dataMap.put("machine", (Object) key);
                dataList.add(dataMap);
            } else {
                Map<String, Object> dataMap = new HashMap<String, Object>();
                dataMap.put("dateTime", (Object) itDateTime.format(DATE_TIME_FORMAT));
                dataMap.put("charge", (Object) BigDecimal.ZERO);
                dataMap.put("machine", (Object) key);
                dataList.add(dataMap);
            }
        }
        itDateTime = itDateTime.plusHours(1);
    }
    return dataList;
}
Also used : LocalDateTime(java.time.LocalDateTime) AxelorException(com.axelor.exception.AxelorException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) OperationOrderRepository(com.axelor.apps.production.db.repo.OperationOrderRepository) HashMap(java.util.HashMap) Map(java.util.Map) OperationOrder(com.axelor.apps.production.db.OperationOrder) HashSet(java.util.HashSet)

Example 10 with OperationOrder

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

the class OperationOrderServiceImpl method createOperationOrder.

@Transactional(rollbackOn = { Exception.class })
public OperationOrder createOperationOrder(ManufOrder manufOrder, int priority, WorkCenter workCenter, Machine machine, MachineTool machineTool, ProdProcessLine prodProcessLine) throws AxelorException {
    logger.debug("Création d'une opération {} pour l'OF {}", priority, manufOrder.getManufOrderSeq());
    String operationName = prodProcessLine.getName();
    OperationOrder operationOrder = new OperationOrder(priority, this.computeName(manufOrder, priority, operationName), operationName, manufOrder, workCenter, machine, OperationOrderRepository.STATUS_DRAFT, prodProcessLine, machineTool);
    this._createHumanResourceList(operationOrder, workCenter);
    operationOrder.setUseLineInGeneratedPurchaseOrder(prodProcessLine.getUseLineInGeneratedPurchaseOrder());
    return Beans.get(OperationOrderRepository.class).save(operationOrder);
}
Also used : OperationOrderRepository(com.axelor.apps.production.db.repo.OperationOrderRepository) 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