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