use of com.axelor.apps.account.db.MoveTemplateType in project axelor-open-suite by axelor.
the class MoveTemplateController method generateMove.
@SuppressWarnings("unchecked")
public void generateMove(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
HashMap<String, Object> moveTemplateTypeMap = (HashMap<String, Object>) context.get("moveTemplateType");
MoveTemplateType moveTemplateType = Beans.get(MoveTemplateTypeRepository.class).find(Long.parseLong(moveTemplateTypeMap.get("id").toString()));
HashMap<String, Object> moveTemplateMap = (HashMap<String, Object>) context.get("moveTemplate");
MoveTemplate moveTemplate = null;
if (moveTemplateType.getTypeSelect() == MoveTemplateTypeRepository.TYPE_PERCENTAGE) {
moveTemplate = Beans.get(MoveTemplateRepository.class).find(Long.parseLong(moveTemplateMap.get("id").toString()));
}
List<HashMap<String, Object>> dataList = (List<HashMap<String, Object>>) context.get("dataInputList");
List<HashMap<String, Object>> moveTemplateList = (List<HashMap<String, Object>>) context.get("moveTemplateSet");
LocalDate moveDate = null;
if (moveTemplateType.getTypeSelect() == MoveTemplateTypeRepository.TYPE_AMOUNT) {
moveDate = LocalDate.parse((String) context.get("moveDate"), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
LOG.debug("MoveTemplate : {}", moveTemplate);
LOG.debug("Data inputlist : {}", dataList);
LOG.debug("Data inputlist : {}", moveTemplateList);
if ((dataList != null && !dataList.isEmpty()) || (moveTemplateList != null && !moveTemplateList.isEmpty())) {
List<Long> moveList = Beans.get(MoveTemplateService.class).generateMove(moveTemplateType, moveTemplate, dataList, moveDate, moveTemplateList);
if (moveList != null && !moveList.isEmpty()) {
response.setView(ActionView.define(I18n.get(IExceptionMessage.MOVE_TEMPLATE_3)).model(Move.class.getName()).add("grid", "move-grid").add("form", "move-form").param("search-filters", "move-filters").domain("self.id in (" + Joiner.on(",").join(moveList) + ")").map());
}
} else {
response.setFlash(I18n.get(IExceptionMessage.MOVE_TEMPLATE_4));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations