Search in sources :

Example 1 with StockLocationLineService

use of com.axelor.apps.stock.service.StockLocationLineService 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 2 with StockLocationLineService

use of com.axelor.apps.stock.service.StockLocationLineService in project axelor-open-suite by axelor.

the class ProductStockController method updateStockLocation.

public void updateStockLocation(ActionRequest request, ActionResponse response) {
    try {
        Product product = request.getContext().asType(Product.class);
        StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
        if (product.getId() == null) {
            return;
        }
        product = Beans.get(ProductRepository.class).find(product.getId());
        List<StockLocationLine> stockLocationLineList = stockLocationLineService.getStockLocationLines(product);
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            stockLocationLineService.updateStockLocationFromProduct(stockLocationLine, product);
        }
        Beans.get(WeightedAveragePriceService.class).computeAvgPriceForProduct(product);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) WeightedAveragePriceService(com.axelor.apps.stock.service.WeightedAveragePriceService) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Aggregations

StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)2 StockLocationLineService (com.axelor.apps.stock.service.StockLocationLineService)2 Product (com.axelor.apps.base.db.Product)1 Wizard (com.axelor.apps.base.db.Wizard)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 StockMove (com.axelor.apps.stock.db.StockMove)1 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)1 TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)1 StockLocationRepository (com.axelor.apps.stock.db.repo.StockLocationRepository)1 StockMoveLineRepository (com.axelor.apps.stock.db.repo.StockMoveLineRepository)1 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)1 IExceptionMessage (com.axelor.apps.stock.exception.IExceptionMessage)1 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)1 WeightedAveragePriceService (com.axelor.apps.stock.service.WeightedAveragePriceService)1 Mapper (com.axelor.db.mapper.Mapper)1 AxelorException (com.axelor.exception.AxelorException)1 ResponseMessageType (com.axelor.exception.ResponseMessageType)1 TraceBackService (com.axelor.exception.service.TraceBackService)1 I18n (com.axelor.i18n.I18n)1 Beans (com.axelor.inject.Beans)1