Search in sources :

Example 1 with TaskTemplate

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

the class ProjectServiceImpl method createProjectFromTemplate.

@Override
@Transactional
public Project createProjectFromTemplate(ProjectTemplate projectTemplate, String projectCode, Partner clientPartner) throws AxelorException {
    Project project = new Project();
    project.setName(projectTemplate.getName());
    if (projectRepository.all().filter("self.code = ?", projectCode).count() > 0) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, ITranslation.PROJECT_CODE_ERROR);
    } else {
        project.setCode(projectCode);
        project.setClientPartner(clientPartner);
        if (clientPartner != null && clientPartner.getContactPartnerSet() != null && !clientPartner.getContactPartnerSet().isEmpty()) {
            project.setContactPartner(clientPartner.getContactPartnerSet().iterator().next());
        }
        project.setDescription(projectTemplate.getDescription());
        project.setTeam(projectTemplate.getTeam());
        project.setProjectFolderSet(new HashSet<>(projectTemplate.getProjectFolderSet()));
        project.setAssignedTo(projectTemplate.getAssignedTo());
        project.setProjectTaskCategorySet(new HashSet<>(projectTemplate.getProjectTaskCategorySet()));
        project.setSynchronize(projectTemplate.getSynchronize());
        project.setMembersUserSet(new HashSet<>(projectTemplate.getMembersUserSet()));
        project.setImputable(projectTemplate.getImputable());
        project.setCompany(projectTemplate.getCompany());
        project.setProductSet(new HashSet<>(projectTemplate.getProductSet()));
        project.setExcludePlanning(projectTemplate.getExcludePlanning());
        project.setProjectTypeSelect(ProjectRepository.TYPE_PROJECT);
        List<Wiki> wikiList = projectTemplate.getWikiList();
        if (wikiList != null && !wikiList.isEmpty()) {
            for (Wiki wiki : wikiList) {
                wiki = wikiRepo.copy(wiki, false);
                wiki.setProjectTemplate(null);
                project.addWikiListItem(wiki);
            }
        }
        projectRepository.save(project);
        Set<TaskTemplate> taskTemplateSet = projectTemplate.getTaskTemplateSet();
        if (ObjectUtils.isEmpty(taskTemplateSet)) {
            return project;
        }
        List<TaskTemplate> taskTemplateList = new ArrayList<TaskTemplate>(taskTemplateSet);
        Collections.sort(taskTemplateList, new Comparator<TaskTemplate>() {

            @Override
            public int compare(TaskTemplate taskTemplatet1, TaskTemplate taskTemplate2) {
                return taskTemplatet1.getParentTaskTemplate() == null || taskTemplate2 == null ? 1 : taskTemplatet1.getParentTaskTemplate().equals(taskTemplate2) ? -1 : 1;
            }
        });
        if (taskTemplateList != null) {
            for (TaskTemplate taskTemplate : taskTemplateList) {
                createTask(taskTemplate, project, taskTemplateSet);
            }
        }
        return project;
    }
}
Also used : TaskTemplate(com.axelor.apps.project.db.TaskTemplate) Project(com.axelor.apps.project.db.Project) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) Wiki(com.axelor.apps.project.db.Wiki) Transactional(com.google.inject.persist.Transactional)

Example 2 with TaskTemplate

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

the class ProjectServiceImpl method createTask.

public ProjectTask createTask(TaskTemplate taskTemplate, Project project, Set<TaskTemplate> taskTemplateSet) {
    if (!ObjectUtils.isEmpty(project.getProjectTaskList())) {
        for (ProjectTask projectTask : project.getProjectTaskList()) {
            if (projectTask.getName().equals(taskTemplate.getName())) {
                return projectTask;
            }
        }
    }
    ProjectTask task = projectTaskService.create(taskTemplate.getName(), project, taskTemplate.getAssignedTo());
    task.setDescription(taskTemplate.getDescription());
    ProjectTaskCategory projectTaskCategory = taskTemplate.getProjectTaskCategory();
    if (projectTaskCategory != null) {
        task.setProjectTaskCategory(projectTaskCategory);
        project.addProjectTaskCategorySetItem(projectTaskCategory);
    }
    TaskTemplate parentTaskTemplate = taskTemplate.getParentTaskTemplate();
    if (parentTaskTemplate != null && taskTemplateSet.contains(parentTaskTemplate)) {
        task.setParentTask(this.createTask(parentTaskTemplate, project, taskTemplateSet));
        return task;
    }
    return task;
}
Also used : TaskTemplate(com.axelor.apps.project.db.TaskTemplate) ProjectTaskCategory(com.axelor.apps.project.db.ProjectTaskCategory) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Example 3 with TaskTemplate

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

the class ProductTaskTemplateServiceImpl method convert.

@Override
@Transactional
public List<ProjectTask> convert(List<? extends TaskTemplate> templates, Project project, ProjectTask parent, LocalDateTime startDate, BigDecimal qty, SaleOrderLine saleOrderLine) throws AxelorException {
    List<ProjectTask> tasks = new ArrayList<>();
    Product product = saleOrderLine.getProduct();
    for (TaskTemplate template : templates) {
        BigDecimal qtyTmp = (template.getIsUniqueTaskForMultipleQuantity() ? BigDecimal.ONE : qty);
        while (qtyTmp.signum() > 0) {
            LocalDateTime dateWithDelay = startDate.plusHours(template.getDelayToStart().longValue());
            ProjectTask task = projectTaskBusinessProjectService.create(template, project, dateWithDelay, qty);
            task.setParentTask(parent);
            task.setProduct(product);
            task.setQuantity(!template.getIsUniqueTaskForMultipleQuantity() ? BigDecimal.ONE : qty);
            task.setUnit(product.getUnit());
            task.setUnitPrice((BigDecimal) productCompanyService.get(product, "salePrice", project.getCompany()));
            task.setExTaxTotal(task.getUnitPrice().multiply(task.getQuantity()));
            if (saleOrderLine.getSaleOrder().getToInvoiceViaTask()) {
                task.setToInvoice(true);
                task.setInvoicingType(ProjectTaskRepository.INVOICING_TYPE_PACKAGE);
            }
            tasks.add(projectTaskRepo.save(task));
            // Only parent task can have multiple quantities
            List<ProjectTask> children = convert(template.getTaskTemplateList(), project, task, dateWithDelay, BigDecimal.ONE, saleOrderLine);
            tasks.addAll(children);
            qtyTmp = qtyTmp.subtract(BigDecimal.ONE);
        }
    }
    return tasks;
}
Also used : TaskTemplate(com.axelor.apps.project.db.TaskTemplate) LocalDateTime(java.time.LocalDateTime) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) ProjectTask(com.axelor.apps.project.db.ProjectTask) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

TaskTemplate (com.axelor.apps.project.db.TaskTemplate)3 ProjectTask (com.axelor.apps.project.db.ProjectTask)2 Transactional (com.google.inject.persist.Transactional)2 ArrayList (java.util.ArrayList)2 Product (com.axelor.apps.base.db.Product)1 Project (com.axelor.apps.project.db.Project)1 ProjectTaskCategory (com.axelor.apps.project.db.ProjectTaskCategory)1 Wiki (com.axelor.apps.project.db.Wiki)1 AxelorException (com.axelor.exception.AxelorException)1 BigDecimal (java.math.BigDecimal)1 LocalDateTime (java.time.LocalDateTime)1