Search in sources :

Example 1 with OperationOrderDuration

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

the class OperationOrderWorkflowService method startOperationOrderDuration.

/**
 * Starts an {@link OperationOrderDuration} and links it to the given {@link OperationOrder}
 *
 * @param operationOrder An operation order
 */
public void startOperationOrderDuration(OperationOrder operationOrder) {
    OperationOrderDuration duration = new OperationOrderDuration();
    duration.setStartedBy(AuthUtils.getUser());
    duration.setStartingDateTime(appProductionService.getTodayDateTime().toLocalDateTime());
    operationOrder.addOperationOrderDurationListItem(duration);
}
Also used : OperationOrderDuration(com.axelor.apps.production.db.OperationOrderDuration)

Example 2 with OperationOrderDuration

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

the class OperationOrderWorkflowService method computeRealDuration.

/**
 * Computes the duration of all the {@link OperationOrderDuration} of {@code operationOrder}
 *
 * @param operationOrder An operation order
 * @return Real duration of {@code operationOrder}
 */
public Duration computeRealDuration(OperationOrder operationOrder) {
    Duration totalDuration = Duration.ZERO;
    List<OperationOrderDuration> operationOrderDurations = operationOrder.getOperationOrderDurationList();
    if (operationOrderDurations != null) {
        for (OperationOrderDuration operationOrderDuration : operationOrderDurations) {
            if (operationOrderDuration.getStartingDateTime() != null && operationOrderDuration.getStoppingDateTime() != null) {
                totalDuration = totalDuration.plus(Duration.between(operationOrderDuration.getStartingDateTime(), operationOrderDuration.getStoppingDateTime()));
            }
        }
    }
    return totalDuration;
}
Also used : OperationOrderDuration(com.axelor.apps.production.db.OperationOrderDuration) Duration(java.time.Duration) OperationOrderDuration(com.axelor.apps.production.db.OperationOrderDuration)

Example 3 with OperationOrderDuration

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

Aggregations

OperationOrderDuration (com.axelor.apps.production.db.OperationOrderDuration)3 Machine (com.axelor.apps.production.db.Machine)1 Duration (java.time.Duration)1