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