use of com.axelor.rpc.ActionResponse 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);
}
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class StockMoveLineController method displayAvailableTrackingNumber.
public void displayAvailableTrackingNumber(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> stockMoveLineMap = (LinkedHashMap<String, Object>) context.get("_stockMoveLine");
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> stockMoveMap = (LinkedHashMap<String, Object>) context.get("_stockMove");
Integer stockMoveLineId = (Integer) stockMoveLineMap.get("id");
Integer stockMoveId = (Integer) stockMoveMap.get("id");
StockMoveLine stockMoveLine = Beans.get(StockMoveLineRepository.class).find(new Long(stockMoveLineId));
StockMove stockMove = Beans.get(StockMoveRepository.class).find(new Long(stockMoveId));
if (stockMoveLine == null || stockMoveLine.getProduct() == null || stockMove == null || stockMove.getFromStockLocation() == null) {
return;
}
List<TrackingNumber> trackingNumberList = Beans.get(StockMoveLineService.class).getAvailableTrackingNumbers(stockMoveLine, stockMove);
if (trackingNumberList == null || trackingNumberList.isEmpty()) {
return;
}
SortedSet<Map<String, Object>> trackingNumbers = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("trackingNumberSeq")));
StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
for (TrackingNumber trackingNumber : trackingNumberList) {
StockLocationLine detailStockLocationLine = stockLocationLineService.getDetailLocationLine(stockMove.getFromStockLocation(), stockMoveLine.getProduct(), trackingNumber);
BigDecimal availableQty = detailStockLocationLine != null ? detailStockLocationLine.getCurrentQty() : BigDecimal.ZERO;
Map<String, Object> map = new HashMap<String, Object>();
map.put("trackingNumber", trackingNumber);
map.put("trackingNumberSeq", trackingNumber.getTrackingNumberSeq());
map.put("counter", BigDecimal.ZERO);
map.put("warrantyExpirationDate", trackingNumber.getWarrantyExpirationDate());
map.put("perishableExpirationDate", trackingNumber.getPerishableExpirationDate());
map.put("$availableQty", availableQty);
map.put("$moveTypeSelect", stockMove.getTypeSelect());
map.put("origin", trackingNumber.getOrigin());
map.put("note", trackingNumber.getNote());
trackingNumbers.add(map);
}
response.setValue("$trackingNumbers", trackingNumbers);
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class StockMoveController method printPickingStockMove.
/**
* 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 printPickingStockMove(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
String fileLink;
String title;
String userType = (String) context.get("_userType");
PickingStockMovePrintService pickingstockMovePrintService = Beans.get(PickingStockMovePrintService.class);
if (!ObjectUtils.isEmpty(context.get("_ids"))) {
List<Long> ids = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
fileLink = pickingstockMovePrintService.printStockMoves(ids, userType);
title = I18n.get("Stock Moves");
} else if (context.get("id") != null) {
StockMove stockMove = context.asType(StockMove.class);
stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
title = pickingstockMovePrintService.getFileName(stockMove);
fileLink = pickingstockMovePrintService.printStockMove(stockMove, ReportSettings.FORMAT_PDF, userType);
logger.debug("Printing " + title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.STOCK_MOVE_PRINT));
}
response.setReload(true);
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class StockMoveController method printConformityCertificate.
/**
* Called from stock move form view. Print conformity certificate for the given stock move.
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void printConformityCertificate(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
String fileLink;
String title;
ConformityCertificatePrintService conformityCertificatePrintService = Beans.get(ConformityCertificatePrintService.class);
if (!ObjectUtils.isEmpty(context.get("_ids"))) {
List<Long> ids = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
fileLink = conformityCertificatePrintService.printConformityCertificates(ids);
title = I18n.get("Conformity Certificates");
} else if (context.get("id") != null) {
StockMove stockMove = context.asType(StockMove.class);
title = conformityCertificatePrintService.getFileName(stockMove);
fileLink = conformityCertificatePrintService.printConformityCertificate(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);
}
}
Aggregations