Search in sources :

Example 1 with Machine

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

the class OperationOrderWorkflowService method getMachineSetupDuration.

public long getMachineSetupDuration(OperationOrder operationOrder) throws AxelorException {
    ProdProcessLine prodProcessLine = operationOrder.getProdProcessLine();
    long duration = 0;
    WorkCenter workCenter = prodProcessLine.getWorkCenter();
    if (workCenter == null) {
        return 0;
    }
    int workCenterTypeSelect = workCenter.getWorkCenterTypeSelect();
    if (workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_MACHINE || workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_BOTH) {
        Machine machine = workCenter.getMachine();
        if (machine == null) {
            throw new AxelorException(workCenter, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.WORKCENTER_NO_MACHINE), workCenter.getName());
        }
        duration += machine.getStartingDuration();
        duration += machine.getEndingDuration();
        duration += machine.getSetupDuration();
    }
    return duration;
}
Also used : AxelorException(com.axelor.exception.AxelorException) WorkCenter(com.axelor.apps.production.db.WorkCenter) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) Machine(com.axelor.apps.production.db.Machine)

Example 2 with Machine

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

the class OperationOrderWorkflowService method computeEntireCycleDuration.

public long computeEntireCycleDuration(OperationOrder operationOrder, BigDecimal qty) throws AxelorException {
    ProdProcessLine prodProcessLine = operationOrder.getProdProcessLine();
    WorkCenter workCenter = prodProcessLine.getWorkCenter();
    long duration = 0;
    if (prodProcessLine.getWorkCenter() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PROD_PROCESS_LINE_MISSING_WORK_CENTER), prodProcessLine.getProdProcess() != null ? prodProcessLine.getProdProcess().getCode() : "null", prodProcessLine.getName());
    }
    BigDecimal maxCapacityPerCycle = prodProcessLine.getMaxCapacityPerCycle();
    BigDecimal nbCycles;
    if (maxCapacityPerCycle.compareTo(BigDecimal.ZERO) == 0) {
        nbCycles = qty;
    } else {
        nbCycles = qty.divide(maxCapacityPerCycle, 0, RoundingMode.UP);
    }
    int workCenterTypeSelect = workCenter.getWorkCenterTypeSelect();
    if (workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_MACHINE || workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_BOTH) {
        Machine machine = workCenter.getMachine();
        if (machine == null) {
            throw new AxelorException(workCenter, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.WORKCENTER_NO_MACHINE), workCenter.getName());
        }
        duration += machine.getStartingDuration();
        duration += machine.getEndingDuration();
        duration += nbCycles.subtract(new BigDecimal(1)).multiply(new BigDecimal(machine.getSetupDuration())).longValue();
    }
    BigDecimal durationPerCycle = new BigDecimal(prodProcessLine.getDurationPerCycle());
    duration += nbCycles.multiply(durationPerCycle).longValue();
    return duration;
}
Also used : AxelorException(com.axelor.exception.AxelorException) WorkCenter(com.axelor.apps.production.db.WorkCenter) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) BigDecimal(java.math.BigDecimal) Machine(com.axelor.apps.production.db.Machine)

Example 3 with Machine

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

the class OperationOrderWorkflowService method stopOperationOrderDuration.

/**
 * Ends the last {@link OperationOrderDuration} and sets the real duration of {@code
 * operationOrder}<br>
 * Adds the real duration to the {@link Machine} linked to {@code operationOrder}
 *
 * @param operationOrder An operation order
 */
public void stopOperationOrderDuration(OperationOrder operationOrder) {
    OperationOrderDuration duration = operationOrderDurationRepo.all().filter("self.operationOrder.id = ? AND self.stoppedBy IS NULL AND self.stoppingDateTime IS NULL", operationOrder.getId()).fetchOne();
    duration.setStoppedBy(AuthUtils.getUser());
    duration.setStoppingDateTime(appProductionService.getTodayDateTime().toLocalDateTime());
    if (operationOrder.getStatusSelect() == OperationOrderRepository.STATUS_FINISHED) {
        long durationLong = DurationTool.getSecondsDuration(computeRealDuration(operationOrder));
        operationOrder.setRealDuration(durationLong);
        Machine machine = operationOrder.getMachine();
        if (machine != null) {
            machine.setOperatingDuration(machine.getOperatingDuration() + durationLong);
        }
    }
    operationOrderDurationRepo.save(duration);
}
Also used : OperationOrderDuration(com.axelor.apps.production.db.OperationOrderDuration) Machine(com.axelor.apps.production.db.Machine)

Example 4 with Machine

use of com.axelor.apps.production.db.Machine 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)

Aggregations

Machine (com.axelor.apps.production.db.Machine)4 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)2 WorkCenter (com.axelor.apps.production.db.WorkCenter)2 AxelorException (com.axelor.exception.AxelorException)2 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)1 ManufOrder (com.axelor.apps.production.db.ManufOrder)1 OperationOrderDuration (com.axelor.apps.production.db.OperationOrderDuration)1 Transactional (com.google.inject.persist.Transactional)1 BigDecimal (java.math.BigDecimal)1 LocalDateTime (java.time.LocalDateTime)1