use of com.axelor.apps.project.db.ProjectTask 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.ProjectTask in project axelor-open-suite by axelor.
the class BatchUpdateTaskService method updateTasks.
private void updateTasks(Map<String, Object> contextValues) {
AppBusinessProject appBusinessProject = appBusinessProjectService.getAppBusinessProject();
List<Object> updatedTaskList = new ArrayList<Object>();
String filter = !Strings.isNullOrEmpty(appBusinessProject.getExculdeTaskInvoicing()) ? "self.id NOT IN (SELECT id FROM ProjectTask WHERE " + appBusinessProject.getExculdeTaskInvoicing() + ")" : "self.id NOT IN (0)";
Query<ProjectTask> taskQuery = projectTaskRepo.all().filter(filter + " AND self.project.isBusinessProject = :isBusinessProject " + " AND self.project.toInvoice = :invoiceable " + "AND self.toInvoice = :toInvoice").bind("isBusinessProject", true).bind("invoiceable", true).bind("toInvoice", false).order("id");
int offset = 0;
List<ProjectTask> taskList;
while (!(taskList = taskQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
findBatch();
offset += taskList.size();
for (ProjectTask projectTask : taskList) {
try {
projectTask = projectTaskBusinessProjectService.updateTask(projectTask, appBusinessProject);
if (projectTask.getToInvoice()) {
offset--;
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", projectTask.getId());
updatedTaskList.add(map);
}
} catch (Exception e) {
incrementAnomaly();
TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_TASK_UPDATION_1), projectTask.getId()), e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
}
}
JPA.clear();
}
findBatch();
ProjectInvoicingAssistantBatchService.updateJsonObject(batch, updatedTaskList, "updatedTaskSet", contextValues);
}
use of com.axelor.apps.project.db.ProjectTask in project axelor-open-suite by axelor.
the class ProjectGeneratorFactoryTask method fill.
@Override
@Transactional(rollbackOn = { Exception.class, AxelorException.class })
public ActionViewBuilder fill(Project project, SaleOrder saleOrder, LocalDateTime startDate) throws AxelorException {
List<ProjectTask> tasks = new ArrayList<>();
projectRepository.save(project);
for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
Product product = saleOrderLine.getProduct();
boolean isTaskGenerated = projectTaskRepo.all().filter("self.saleOrderLine = ? AND self.project = ?", saleOrderLine, project).fetch().size() > 0;
if (product != null && ProductRepository.PRODUCT_TYPE_SERVICE.equals((String) productCompanyService.get(product, "productTypeSelect", saleOrder.getCompany())) && saleOrderLine.getSaleSupplySelect() == SaleOrderLineRepository.SALE_SUPPLY_PRODUCE && !(isTaskGenerated)) {
ProjectTask task = projectTaskBusinessProjectService.create(saleOrderLine, project, project.getAssignedTo());
if (saleOrder.getToInvoiceViaTask()) {
task.setInvoicingType(ProjectTaskRepository.INVOICING_TYPE_PACKAGE);
}
task.setTaskDate(startDate.toLocalDate());
task.setUnitPrice((BigDecimal) productCompanyService.get(product, "salePrice", saleOrder.getCompany()));
task.setExTaxTotal(saleOrderLine.getExTaxTotal());
if (project.getIsInvoicingTimesheet()) {
task.setToInvoice(true);
} else {
task.setToInvoice(false);
}
projectTaskRepo.save(task);
tasks.add(task);
}
}
if (tasks == null || tasks.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.SALE_ORDER_GENERATE_FILL_PROJECT_ERROR_1));
}
return ActionView.define(String.format("Task%s generated", (tasks.size() > 1 ? "s" : ""))).model(ProjectTask.class.getName()).add("grid", "project-task-grid").add("form", "project-task-form").param("search-filters", "project-task-filters").domain(String.format("self.id in (%s)", StringTool.getIdListString(tasks)));
}
use of com.axelor.apps.project.db.ProjectTask in project axelor-open-suite by axelor.
the class ProjectGeneratorFactoryTaskTemplate method fill.
@Override
@Transactional(rollbackOn = { Exception.class, AxelorException.class })
public ActionViewBuilder fill(Project project, SaleOrder saleOrder, LocalDateTime startDate) throws AxelorException {
List<ProjectTask> tasks = new ArrayList<>();
ProjectTask root;
root = projectTaskRepo.all().filter("self.project = ? AND self.assignedTo = ? AND self.name = ?", project, project.getAssignedTo(), saleOrder.getFullName()).fetchOne();
projectRepository.save(project);
for (SaleOrderLine orderLine : saleOrder.getSaleOrderLineList()) {
Product product = orderLine.getProduct();
if (product != null && !((ProductRepository.PROCUREMENT_METHOD_PRODUCE.equals((String) productCompanyService.get(product, "procurementMethodSelect", saleOrder.getCompany())) || orderLine.getSaleSupplySelect() == SaleOrderLineRepository.SALE_SUPPLY_PRODUCE) && ProductRepository.PRODUCT_TYPE_SERVICE.equals(product.getProductTypeSelect()))) {
continue;
}
boolean isTaskGenerated = projectTaskRepo.all().filter("self.saleOrderLine = ? AND self.project = ?", orderLine, project).fetch().size() > 0;
if (root == null) {
root = projectTaskBusinessProjectService.create(saleOrder.getFullName(), project, project.getAssignedTo());
root.setTaskDate(startDate.toLocalDate());
tasks.add(projectTaskRepo.save(root));
}
if (product != null && !isTaskGenerated) {
if (!CollectionUtils.isEmpty(product.getTaskTemplateSet())) {
List<ProjectTask> convertedTasks = productTaskTemplateService.convert(product.getTaskTemplateSet().stream().filter(template -> Objects.isNull(template.getParentTaskTemplate())).collect(Collectors.toList()), project, root, startDate, orderLine.getQty(), orderLine);
convertedTasks.stream().forEach(task -> task.setSaleOrderLine(orderLine));
tasks.addAll(convertedTasks);
} else {
ProjectTask childTask = projectTaskBusinessProjectService.create(orderLine.getFullName(), project, project.getAssignedTo());
this.updateTask(root, childTask, orderLine);
tasks.add(projectTaskRepo.save(childTask));
}
}
}
if (root == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.SALE_ORDER_GENERATE_FILL_PROJECT_ERROR_2));
}
return ActionView.define("Tasks").model(ProjectTask.class.getName()).add("grid", "project-task-grid").add("form", "project-task-form").param("search-filters", "project-task-filters").domain("self.parentTask = " + root.getId());
}
use of com.axelor.apps.project.db.ProjectTask in project axelor-open-suite by axelor.
the class TimesheetLineProjectServiceImpl method getDefaultToInvoice.
@Override
public TimesheetLine getDefaultToInvoice(TimesheetLine timesheetLine) {
Project project = timesheetLine.getProject() != null ? projectRepo.find(timesheetLine.getProject().getId()) : null;
ProjectTask projectTask = timesheetLine.getProjectTask() != null ? projectTaskRepo.find(timesheetLine.getProjectTask().getId()) : null;
boolean toInvoice;
if (projectTask == null && project != null) {
toInvoice = project.getIsInvoicingTimesheet();
} else if (projectTask != null) {
toInvoice = projectTask.getToInvoice();
if (projectTask.getParentTask() != null) {
toInvoice = projectTask.getParentTask().getInvoicingType() == ProjectTaskRepository.INVOICING_TYPE_TIME_SPENT;
}
} else {
toInvoice = false;
}
timesheetLine.setToInvoice(toInvoice);
return timesheetLine;
}
Aggregations