Search in sources :

Example 1 with ProjectGeneratorType

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

the class SaleOrderProjectController method generateProject.

public void generateProject(ActionRequest request, ActionResponse response) {
    try {
        SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
        saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrder.getId());
        if (saleOrder.getSaleOrderLineList() == null || saleOrder.getSaleOrderLineList().isEmpty()) {
            response.setAlert(I18n.get(IExceptionMessage.SALE_ORDER_GENERATE_FILL_PROJECT_ERROR_2));
            return;
        }
        String generatorType = (String) request.getContext().get("_projectGeneratorType");
        LocalDateTime startDate = getElementStartDate(request.getContext());
        ProjectGeneratorType projectGeneratorType = ProjectGeneratorType.valueOf(generatorType);
        ProjectGeneratorFactory factory = ProjectGeneratorFactory.getFactory(projectGeneratorType);
        Project project;
        if (projectGeneratorType.equals(ProjectGeneratorType.PROJECT_ALONE)) {
            project = factory.create(saleOrder);
        } else {
            project = factory.generate(saleOrder, startDate);
        }
        response.setReload(true);
        response.setView(ActionView.define("Project").model(Project.class.getName()).add("form", "project-form").param("forceEdit", "true").context(CONTEXT_SHOW_RECORD, String.valueOf(project.getId())).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
        response.setReload(true);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ProjectGeneratorFactory(com.axelor.apps.businessproject.service.projectgenerator.ProjectGeneratorFactory) Project(com.axelor.apps.project.db.Project) ProjectGeneratorType(com.axelor.apps.project.db.ProjectGeneratorType) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Aggregations

ProjectGeneratorFactory (com.axelor.apps.businessproject.service.projectgenerator.ProjectGeneratorFactory)1 Project (com.axelor.apps.project.db.Project)1 ProjectGeneratorType (com.axelor.apps.project.db.ProjectGeneratorType)1 SaleOrder (com.axelor.apps.sale.db.SaleOrder)1 LocalDateTime (java.time.LocalDateTime)1