use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class PartnerSaleController method displayValues.
public void displayValues(ActionRequest request, ActionResponse response) {
Partner customer = request.getContext().asType(Partner.class);
try {
customer = Beans.get(PartnerRepository.class).find(customer.getId());
SortedSet<Map<String, Object>> saleDetailsByProduct = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("name")));
PartnerSaleService partnerSaleService = Beans.get(PartnerSaleService.class);
List<Product> productList = partnerSaleService.getProductBoughtByCustomer(customer);
if (productList.isEmpty()) {
response.setAttr("$saleDetailsByProduct", "hidden", true);
return;
}
response.setAttr("$saleDetailsByProduct", "hidden", false);
HashMap<String, BigDecimal> qtyAndPrice;
for (Product product : productList) {
qtyAndPrice = partnerSaleService.getTotalSaleQuantityAndPrice(customer, product);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", product.getName());
map.put("$quantitySold", qtyAndPrice.get("qty"));
map.put("$totalPrice", qtyAndPrice.get("price"));
map.put("$averagePrice", qtyAndPrice.get("price").divide(qtyAndPrice.get("qty"), AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_EVEN));
saleDetailsByProduct.add(map);
}
response.setValue("$saleDetailsByProduct", saleDetailsByProduct);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class ManufOrderController method generateMultiLevelManufOrder.
/**
* Called from multi-level-planing-wizard-form, on clicking "Generate MO" button.
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void generateMultiLevelManufOrder(ActionRequest request, ActionResponse response) {
try {
Long moId = Long.valueOf(request.getContext().get("id").toString());
ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
ProdProductRepository prodProductRepository = Beans.get(ProdProductRepository.class);
List<ProdProduct> prodProductList = ((List<LinkedHashMap<String, Object>>) request.getContext().get("components")).stream().filter(map -> (boolean) map.get("selected")).map(map -> prodProductRepository.find(Long.valueOf(map.get("id").toString()))).collect(Collectors.toList());
if (prodProductList.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PRODUCT_SELECTED));
}
List<Product> selectedProductList = new ArrayList<>();
for (ProdProduct prod : prodProductList) {
if (selectedProductList.contains(prod.getProduct())) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.DUPLICATE_PRODUCT_SELECTED));
}
selectedProductList.add(prod.getProduct());
}
List<ManufOrder> moList = Beans.get(ManufOrderService.class).generateAllSubManufOrder(selectedProductList, mo);
response.setCanClose(true);
response.setView(ActionView.define(I18n.get("Manufacturing orders")).model(ManufOrder.class.getName()).add("grid", "generated-manuf-order-grid").add("form", "manuf-order-form").param("popup", "true").param("popup-save", "false").param("show-toolbar", "false").param("show-confirm", "false").domain("self.id in (" + StringTool.getIdListString(moList) + ")").map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class ManufOrderController method partialFinish.
public void partialFinish(ActionRequest request, ActionResponse response) {
try {
ManufOrder manufOrder = request.getContext().asType(ManufOrder.class);
manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrder.getId());
// we have to inject TraceBackService to use non static methods
TraceBackService traceBackService = Beans.get(TraceBackService.class);
long tracebackCount = traceBackService.countMessageTraceBack(manufOrder);
if (!Beans.get(ManufOrderWorkflowService.class).partialFinish(manufOrder)) {
response.setNotify(I18n.get(IExceptionMessage.MANUF_ORDER_EMAIL_NOT_SENT));
} else if (traceBackService.countMessageTraceBack(manufOrder) > tracebackCount) {
traceBackService.findLastMessageTraceBack(manufOrder).ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
}
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class InvoiceController method massPaymentOnSupplierInvoices.
public void massPaymentOnSupplierInvoices(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
if (!ObjectUtils.isEmpty(context.get("_ids"))) {
List<Long> invoiceIdList = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
List<Long> invoiceToPay = Beans.get(InvoicePaymentCreateService.class).getInvoiceIdsToPay(invoiceIdList);
if (invoiceToPay.isEmpty()) {
response.setError(I18n.get(IExceptionMessage.INVOICE_NO_INVOICE_TO_PAY));
}
response.setView(ActionView.define(I18n.get("Register a mass payment")).model(InvoicePayment.class.getName()).add("form", "invoice-payment-mass-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true").context("_invoices", invoiceToPay).map());
}
} catch (Exception e) {
TraceBackService.trace(response, e, ResponseMessageType.ERROR);
}
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class AdvancedExportController method createCriteria.
@SuppressWarnings("unchecked")
private List<Long> createCriteria(ActionRequest request, AdvancedExport advancedExport) {
if (request.getContext().get("_criteria") != null) {
if (request.getContext().get("_criteria").toString().startsWith("[")) {
String ids = request.getContext().get("_criteria").toString();
return Splitter.on(", ").splitToList(ids.substring(1, ids.length() - 1)).stream().map(id -> Long.valueOf(id.toString())).collect(Collectors.toList());
} else {
ObjectMapper mapper = new ObjectMapper();
ActionRequest parentRequest = mapper.convertValue(request.getContext().get("_criteria"), ActionRequest.class);
Class<? extends Model> klass = (Class<? extends Model>) parentRequest.getBeanClass();
Filter filter = Beans.get(AdvancedExportService.class).getJpaSecurityFilter(advancedExport.getMetaModel());
Stream<? extends Model> listObj = parentRequest.getCriteria().createQuery(klass, filter).fetchSteam(advancedExport.getMaxExportLimit());
return listObj.map(it -> it.getId()).collect(Collectors.toList());
}
}
return null;
}
Aggregations