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);
}
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);
}
}
Aggregations