use of com.axelor.apps.base.db.WeeklyPlanning 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);
}
Aggregations