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);
}
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;
}
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);
}
Aggregations