Search in sources :

Example 16 with ActionResponse

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);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) Arrays(java.util.Arrays) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) StockMoveToolService(com.axelor.apps.stock.service.StockMoveToolService) ActionView(com.axelor.meta.schema.actions.ActionView) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) Mapper(com.axelor.db.mapper.Mapper) PrintingSettings(com.axelor.apps.base.db.PrintingSettings) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) ActionRequest(com.axelor.rpc.ActionRequest) PickingStockMovePrintService(com.axelor.apps.stock.service.stockmove.print.PickingStockMovePrintService) StringTool(com.axelor.apps.tool.StringTool) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) ConformityCertificatePrintService(com.axelor.apps.stock.service.stockmove.print.ConformityCertificatePrintService) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) StockMovePrintService(com.axelor.apps.stock.service.stockmove.print.StockMovePrintService) TraceBackService(com.axelor.exception.service.TraceBackService) TradingNameService(com.axelor.apps.base.service.TradingNameService) Collectors(java.util.stream.Collectors) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) Optional(java.util.Optional) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException)

Example 17 with ActionResponse

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);
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) SortedSet(java.util.SortedSet) ActionView(com.axelor.meta.schema.actions.ActionView) HashMap(java.util.HashMap) Mapper(com.axelor.db.mapper.Mapper) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) Wizard(com.axelor.apps.base.db.Wizard) ActionRequest(com.axelor.rpc.ActionRequest) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ResponseMessageType(com.axelor.exception.ResponseMessageType) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) TraceBackService(com.axelor.exception.service.TraceBackService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Comparator(java.util.Comparator) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) StockMove(com.axelor.apps.stock.db.StockMove) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) TreeSet(java.util.TreeSet) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 18 with ActionResponse

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);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) Arrays(java.util.Arrays) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) StockMoveToolService(com.axelor.apps.stock.service.StockMoveToolService) ActionView(com.axelor.meta.schema.actions.ActionView) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) Mapper(com.axelor.db.mapper.Mapper) PrintingSettings(com.axelor.apps.base.db.PrintingSettings) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) ActionRequest(com.axelor.rpc.ActionRequest) PickingStockMovePrintService(com.axelor.apps.stock.service.stockmove.print.PickingStockMovePrintService) StringTool(com.axelor.apps.tool.StringTool) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) ConformityCertificatePrintService(com.axelor.apps.stock.service.stockmove.print.ConformityCertificatePrintService) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) StockMovePrintService(com.axelor.apps.stock.service.stockmove.print.StockMovePrintService) TraceBackService(com.axelor.exception.service.TraceBackService) TradingNameService(com.axelor.apps.base.service.TradingNameService) Collectors(java.util.stream.Collectors) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) Optional(java.util.Optional) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) AxelorException(com.axelor.exception.AxelorException) PickingStockMovePrintService(com.axelor.apps.stock.service.stockmove.print.PickingStockMovePrintService) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) ArrayList(java.util.ArrayList) List(java.util.List) ObjectUtils(com.axelor.common.ObjectUtils) AxelorException(com.axelor.exception.AxelorException)

Example 19 with ActionResponse

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);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) Arrays(java.util.Arrays) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) StockMoveToolService(com.axelor.apps.stock.service.StockMoveToolService) ActionView(com.axelor.meta.schema.actions.ActionView) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) Mapper(com.axelor.db.mapper.Mapper) PrintingSettings(com.axelor.apps.base.db.PrintingSettings) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) ActionRequest(com.axelor.rpc.ActionRequest) PickingStockMovePrintService(com.axelor.apps.stock.service.stockmove.print.PickingStockMovePrintService) StringTool(com.axelor.apps.tool.StringTool) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) ConformityCertificatePrintService(com.axelor.apps.stock.service.stockmove.print.ConformityCertificatePrintService) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) StockMovePrintService(com.axelor.apps.stock.service.stockmove.print.StockMovePrintService) TraceBackService(com.axelor.exception.service.TraceBackService) TradingNameService(com.axelor.apps.base.service.TradingNameService) Collectors(java.util.stream.Collectors) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) Optional(java.util.Optional) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) ConformityCertificatePrintService(com.axelor.apps.stock.service.stockmove.print.ConformityCertificatePrintService) AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) List(java.util.List) ObjectUtils(com.axelor.common.ObjectUtils) AxelorException(com.axelor.exception.AxelorException)

Aggregations

ActionResponse (com.axelor.rpc.ActionResponse)19 Context (com.axelor.rpc.Context)17 List (java.util.List)17 Beans (com.axelor.inject.Beans)16 ActionRequest (com.axelor.rpc.ActionRequest)16 TraceBackService (com.axelor.exception.service.TraceBackService)15 Singleton (com.google.inject.Singleton)15 I18n (com.axelor.i18n.I18n)14 ArrayList (java.util.ArrayList)14 AxelorException (com.axelor.exception.AxelorException)13 ActionView (com.axelor.meta.schema.actions.ActionView)13 BigDecimal (java.math.BigDecimal)13 Map (java.util.Map)13 Product (com.axelor.apps.base.db.Product)12 Collectors (java.util.stream.Collectors)12 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)11 StringTool (com.axelor.apps.tool.StringTool)10 ObjectUtils (com.axelor.common.ObjectUtils)10 MethodHandles (java.lang.invoke.MethodHandles)10 Logger (org.slf4j.Logger)10