Search in sources :

Example 1 with TeamTaskService

use of com.axelor.apps.base.service.TeamTaskService in project axelor-open-suite by axelor.

the class TeamTaskBaseRepository method save.

@Override
public TeamTask save(TeamTask teamTask) {
    TeamTaskService teamTaskService = Beans.get(TeamTaskService.class);
    if (teamTask.getDoApplyToAllNextTasks() && teamTask.getNextTeamTask() != null && teamTask.getHasDateOrFrequencyChanged()) {
        // remove next tasks
        teamTaskService.removeNextTasks(teamTask);
        // regenerate new tasks
        teamTask.setIsFirst(true);
    }
    Frequency frequency = teamTask.getFrequency();
    if (frequency != null && teamTask.getIsFirst() && teamTask.getNextTeamTask() == null) {
        if (teamTask.getTaskDate() != null) {
            if (frequency.getEndDate().isBefore(teamTask.getTaskDate())) {
                throw new PersistenceException(I18n.get("Frequency end date cannot be before task date."));
            }
        } else {
            throw new PersistenceException(I18n.get("Please fill in task date."));
        }
        teamTaskService.generateTasks(teamTask, frequency);
    }
    if (teamTask.getDoApplyToAllNextTasks()) {
        teamTaskService.updateNextTask(teamTask);
    }
    teamTask.setDoApplyToAllNextTasks(false);
    teamTask.setHasDateOrFrequencyChanged(false);
    return super.save(teamTask);
}
Also used : PersistenceException(javax.persistence.PersistenceException) Frequency(com.axelor.apps.base.db.Frequency) TeamTaskService(com.axelor.apps.base.service.TeamTaskService)

Aggregations

Frequency (com.axelor.apps.base.db.Frequency)1 TeamTaskService (com.axelor.apps.base.service.TeamTaskService)1 PersistenceException (javax.persistence.PersistenceException)1