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