use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class SopLineController method fillMrpForecast.
public void fillMrpForecast(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> productCategoryMap = (LinkedHashMap<String, Object>) context.get("_productCategory");
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> sopLineMap = (LinkedHashMap<String, Object>) context.get("_sopLine");
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> currencyMap = (LinkedHashMap<String, Object>) sopLineMap.get("currency");
BigDecimal sopSalesForecast = new BigDecimal(sopLineMap.get("sopSalesForecast").toString());
Long productCategoryId = Long.parseLong(productCategoryMap.get("id").toString());
Currency currency = currencyRepo.find(Long.parseLong(currencyMap.get("id").toString()));
BigDecimal totalForecast = BigDecimal.ZERO;
SortedSet<Map<String, Object>> mrpForecastSet = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("code")));
List<Product> productList = Beans.get(ProductRepository.class).all().filter("self.productCategory.id = ?1 ", productCategoryId).fetch();
if (productList != null) {
for (Product product : productList) {
Map<String, Object> map = new HashMap<String, Object>();
MrpForecast mrpForecast = mrpForecastRepo.all().filter("self.product.id = ?1 AND self.technicalOrigin = ?2", product.getId(), MrpForecastRepository.TECHNICAL_ORIGIN_CREATED_FROM_SOP).fetchOne();
if (mrpForecast != null) {
map = Mapper.toMap(mrpForecast);
BigDecimal totalPrice = mrpForecast.getQty().multiply(product.getSalePrice());
map.put("$totalPrice", totalPrice);
map.put("$unitPrice", product.getSalePrice());
map.put("code", product.getCode());
totalForecast = totalForecast.add(totalPrice);
mrpForecastSet.add(map);
continue;
}
map.put("product", product);
map.put("qty", BigDecimal.ZERO);
map.put("$totalPrice", BigDecimal.ZERO);
map.put("$unitPrice", product.getSalePrice());
map.put("code", product.getCode());
mrpForecastSet.add(map);
}
}
response.setValue("$mrpForecasts", mrpForecastSet);
response.setValue("$sopSalesForecast", sopSalesForecast);
response.setValue("$totalForecast", totalForecast);
response.setValue("$difference", sopSalesForecast.subtract(totalForecast).setScale(Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice()));
response.setValue("$currency", currency);
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class ManufOrderController method multiLevelManufOrderOnLoad.
/**
* Called from manuf order form, on clicking "Multi-level planning" button.
*
* @param request
* @param response
*/
public void multiLevelManufOrderOnLoad(ActionRequest request, ActionResponse response) {
try {
Long moId = Long.valueOf(request.getContext().get("id").toString());
ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
boolean showOnlyMissingQty = request.getContext().get("_showOnlyMissingQty") != null && Boolean.parseBoolean(request.getContext().get("_showOnlyMissingQty").toString());
ProdProductProductionRepository prodProductProductionRepository = Beans.get(ProdProductProductionRepository.class);
List<ProdProduct> prodProducts = mo.getToConsumeProdProductList().stream().filter(prodProduct -> prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_FINISHED_PRODUCT || prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_SEMI_FINISHED_PRODUCT).filter(prodProduct -> !showOnlyMissingQty || prodProductProductionRepository.computeMissingQty(prodProduct.getProduct().getId(), prodProduct.getQty(), moId).compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
response.setValue("$components", prodProducts);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class ActionServiceImpl method createHandler.
protected ActionHandler createHandler(String action) {
ActionRequest request = new ActionRequest();
Map<String, Object> data = new HashMap<>();
request.setData(data);
request.setModel(modelName);
request.setAction(action);
data.put("context", context);
return executor.newActionHandler(request);
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class StockMoveController method printStockMove.
/**
* Method called from stock move form and grid view. Print one or more stock move as PDF
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void printStockMove(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
String fileLink;
String title;
StockMovePrintService stockMovePrintService = Beans.get(StockMovePrintService.class);
if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
List<Long> ids = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
fileLink = stockMovePrintService.printStockMoves(ids);
title = I18n.get("Stock Moves");
} else if (context.get("id") != null) {
StockMove stockMove = Beans.get(StockMoveRepository.class).find(Long.parseLong(context.get("id").toString()));
title = stockMovePrintService.getFileName(stockMove);
fileLink = stockMovePrintService.printStockMove(stockMove, ReportSettings.FORMAT_PDF);
logger.debug("Printing " + title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.STOCK_MOVE_PRINT));
}
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class StockMoveController method openStockPerDay.
public void openStockPerDay(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
Long locationId = Long.parseLong(((Map<String, Object>) context.get("stockLocation")).get("id").toString());
LocalDate fromDate = LocalDate.parse(context.get("stockFromDate").toString());
LocalDate toDate = LocalDate.parse(context.get("stockToDate").toString());
Collection<Map<String, Object>> products = (Collection<Map<String, Object>>) context.get("productSet");
String domain = null;
List<Object> productIds = null;
if (products != null && !products.isEmpty()) {
productIds = Arrays.asList(products.stream().map(p -> p.get("id")).toArray());
domain = "self.id in (:productIds)";
}
response.setView(ActionView.define(I18n.get("Stocks")).model(Product.class.getName()).add("cards", "stock-product-cards").add("grid", "stock-product-grid").add("form", "stock-product-form").domain(domain).context("fromStockWizard", true).context("productIds", productIds).context("stockFromDate", fromDate).context("stockToDate", toDate).context("locationId", locationId).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations