Search in sources :

Example 26 with ProjectTask

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

the class TimerProjectTaskServiceImpl method start.

@Override
@Transactional(rollbackOn = { Exception.class })
public TimerHistory start(Model model, Timer timer, LocalDateTime dateTime) throws AxelorException {
    ProjectTask task = (ProjectTask) model;
    boolean isNewTimer = timer == null;
    timer = tryStartOrCreate(timer);
    if (isNewTimer) {
        task.addTimerListItem(timer);
    }
    TimerHistory history = new TimerHistory();
    history.setStartDateT(dateTime);
    history.setTimer(timer);
    timer.addTimerHistoryListItem(history);
    return timerHistoryRepository.save(history);
}
Also used : TimerHistory(com.axelor.apps.base.db.TimerHistory) ProjectTask(com.axelor.apps.project.db.ProjectTask) Transactional(com.google.inject.persist.Transactional)

Example 27 with ProjectTask

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

the class TimerProjectTaskServiceImpl method find.

@Override
public Timer find(Model model) {
    User user = userService.getUser();
    ProjectTask task = (ProjectTask) model;
    List<Timer> timers = task.getTimerList();
    return timers != null && !timers.isEmpty() ? timers.stream().filter(t -> t.getAssignedToUser() == user).findFirst().orElse(null) : null;
}
Also used : TimerHistoryRepository(com.axelor.apps.base.db.repo.TimerHistoryRepository) AbstractTimerService(com.axelor.apps.base.service.timer.AbstractTimerService) ProjectTask(com.axelor.apps.project.db.ProjectTask) Timer(com.axelor.apps.base.db.Timer) Model(com.axelor.db.Model) UserService(com.axelor.apps.base.service.user.UserService) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) Transactional(com.google.inject.persist.Transactional) List(java.util.List) AxelorException(com.axelor.exception.AxelorException) Duration(java.time.Duration) TimerRepository(com.axelor.apps.base.db.repo.TimerRepository) TimerHistory(com.axelor.apps.base.db.TimerHistory) User(com.axelor.auth.db.User) User(com.axelor.auth.db.User) Timer(com.axelor.apps.base.db.Timer) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Example 28 with ProjectTask

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

the class ProjectTaskController method deleteProjectTask.

public void deleteProjectTask(ActionRequest request, ActionResponse response) {
    try {
        ProjectTask projectTask = request.getContext().asType(ProjectTask.class);
        projectTask = Beans.get(ProjectTaskRepository.class).find(projectTask.getId());
        Beans.get(ProjectTaskService.class).deleteProjectTask(projectTask);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ProjectTaskService(com.axelor.apps.project.service.ProjectTaskService) TimerProjectTaskService(com.axelor.apps.project.service.TimerProjectTaskService) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Example 29 with ProjectTask

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

the class ProjectTaskServiceImpl method generateTasks.

@Override
@Transactional
public void generateTasks(ProjectTask projectTask, Frequency frequency) {
    List<LocalDate> taskDateList = frequencyService.getDates(frequency, projectTask.getTaskDate(), frequency.getEndDate());
    taskDateList.removeIf(date -> date.equals(projectTask.getTaskDate()));
    // limit how many ProjectTask will be generated at once
    Integer limitNumberTasksGenerated = appBaseService.getAppBase().getLimitNumberTasksGenerated();
    if (taskDateList.size() > limitNumberTasksGenerated) {
        taskDateList = taskDateList.subList(0, limitNumberTasksGenerated);
    }
    ProjectTask lastTask = projectTask;
    for (LocalDate date : taskDateList) {
        ProjectTask newProjectTask = projectTaskRepo.copy(projectTask, false);
        setModuleFields(projectTask, date, newProjectTask);
        projectTaskRepo.save(newProjectTask);
        lastTask.setNextProjectTask(newProjectTask);
        projectTaskRepo.save(lastTask);
        lastTask = newProjectTask;
    }
}
Also used : ProjectTask(com.axelor.apps.project.db.ProjectTask) LocalDate(java.time.LocalDate) Transactional(com.google.inject.persist.Transactional)

Example 30 with ProjectTask

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

the class ProjectTaskServiceImpl method getAllNextTasks.

/**
 * Returns next tasks from given {@link ProjectTask}.
 */
public List<ProjectTask> getAllNextTasks(ProjectTask projectTask) {
    List<ProjectTask> projectTaskList = new ArrayList<>();
    ProjectTask current = projectTask;
    while (current.getNextProjectTask() != null) {
        current = current.getNextProjectTask();
        projectTaskList.add(current);
    }
    for (ProjectTask task : projectTaskList) {
        task.setNextProjectTask(null);
        projectTaskRepo.save(task);
    }
    return projectTaskList;
}
Also used : ArrayList(java.util.ArrayList) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Aggregations

ProjectTask (com.axelor.apps.project.db.ProjectTask)43 Transactional (com.google.inject.persist.Transactional)14 ArrayList (java.util.ArrayList)7 Project (com.axelor.apps.project.db.Project)6 TimerProjectTaskService (com.axelor.apps.project.service.TimerProjectTaskService)6 BigDecimal (java.math.BigDecimal)5 Product (com.axelor.apps.base.db.Product)4 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)4 InvoicingProject (com.axelor.apps.businessproject.db.InvoicingProject)3 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)3 ProjectTaskRepository (com.axelor.apps.project.db.repo.ProjectTaskRepository)3 AxelorException (com.axelor.exception.AxelorException)3 LocalDateTime (java.time.LocalDateTime)3 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 Timer (com.axelor.apps.base.db.Timer)2 TimerHistory (com.axelor.apps.base.db.TimerHistory)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 ExpenseLine (com.axelor.apps.hr.db.ExpenseLine)2 ProjectPlanningTime (com.axelor.apps.project.db.ProjectPlanningTime)2 ProjectTaskCategory (com.axelor.apps.project.db.ProjectTaskCategory)2