Search in sources :

Example 11 with WeeklyPlanning

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

WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)11 LocalDate (java.time.LocalDate)8 BigDecimal (java.math.BigDecimal)6 Employee (com.axelor.apps.hr.db.Employee)5 AxelorException (com.axelor.exception.AxelorException)5 EventsPlanning (com.axelor.apps.base.db.EventsPlanning)4 User (com.axelor.auth.db.User)4 DayPlanning (com.axelor.apps.base.db.DayPlanning)3 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)3 PublicHolidayHrService (com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService)3 HRConfig (com.axelor.apps.hr.db.HRConfig)2 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)2 Transactional (com.google.inject.persist.Transactional)2 LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 AppTimesheet (com.axelor.apps.base.db.AppTimesheet)1 Company (com.axelor.apps.base.db.Company)1 ICalendarEvent (com.axelor.apps.base.db.ICalendarEvent)1 PriceList (com.axelor.apps.base.db.PriceList)1 PublicHolidayService (com.axelor.apps.base.service.publicHoliday.PublicHolidayService)1