Search in sources :

Example 31 with ProjectTask

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;
}
Also used : TaskTemplate(com.axelor.apps.project.db.TaskTemplate) ProjectTaskCategory(com.axelor.apps.project.db.ProjectTaskCategory) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Example 32 with ProjectTask

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);
}
Also used : HashMap(java.util.HashMap) AppBusinessProject(com.axelor.apps.base.db.AppBusinessProject) ArrayList(java.util.ArrayList) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Example 33 with ProjectTask

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)));
}
Also used : AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) ProjectTask(com.axelor.apps.project.db.ProjectTask) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Transactional(com.google.inject.persist.Transactional)

Example 34 with ProjectTask

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());
}
Also used : AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) ProjectTask(com.axelor.apps.project.db.ProjectTask) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Transactional(com.google.inject.persist.Transactional)

Example 35 with ProjectTask

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;
}
Also used : Project(com.axelor.apps.project.db.Project) 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