use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class InventoryService method fillInventoryLineList.
@Transactional(rollbackOn = { Exception.class })
public Boolean fillInventoryLineList(Inventory inventory) throws AxelorException {
if (inventory.getStockLocation() == null) {
throw new AxelorException(inventory, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVENTORY_1));
}
this.initInventoryLines(inventory);
List<? extends StockLocationLine> stockLocationLineList = this.getStockLocationLines(inventory);
if (stockLocationLineList != null) {
Boolean succeed = false;
for (StockLocationLine stockLocationLine : stockLocationLineList) {
if (stockLocationLine.getTrackingNumber() == null) {
// if no tracking number on stockLocationLine, check if there is a tracking
// number on the product
long numberOfTrackingNumberOnAProduct = stockLocationLineList.stream().filter(sll -> stockLocationLine.getProduct() != null && stockLocationLine.getProduct().equals(sll.getProduct()) && sll.getTrackingNumber() != null && inventory.getStockLocation().equals(sll.getDetailsStockLocation())).count();
if (numberOfTrackingNumberOnAProduct != 0) {
// there is a tracking number on the product
continue;
}
}
inventory.addInventoryLineListItem(this.createInventoryLine(inventory, stockLocationLine));
succeed = true;
}
inventoryRepo.save(inventory);
return succeed;
}
return null;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class InventoryService method storeLastInventoryData.
private void storeLastInventoryData(Inventory inventory) {
Map<Pair<Product, TrackingNumber>, BigDecimal> realQties = new HashMap<>();
Map<Product, BigDecimal> consolidatedRealQties = new HashMap<>();
Map<Product, String> realRacks = new HashMap<>();
List<InventoryLine> inventoryLineList = inventory.getInventoryLineList();
if (inventoryLineList != null) {
for (InventoryLine inventoryLine : inventoryLineList) {
Product product = inventoryLine.getProduct();
TrackingNumber trackingNumber = inventoryLine.getTrackingNumber();
realQties.put(Pair.of(product, trackingNumber), inventoryLine.getRealQty());
BigDecimal realQty = consolidatedRealQties.getOrDefault(product, BigDecimal.ZERO);
realQty = realQty.add(inventoryLine.getRealQty());
consolidatedRealQties.put(product, realQty);
realRacks.put(product, inventoryLine.getRack());
}
}
List<StockLocationLine> stockLocationLineList = inventory.getStockLocation().getStockLocationLineList();
if (stockLocationLineList != null) {
for (StockLocationLine stockLocationLine : stockLocationLineList) {
Product product = stockLocationLine.getProduct();
BigDecimal realQty = consolidatedRealQties.get(product);
if (realQty != null) {
stockLocationLine.setLastInventoryRealQty(realQty);
stockLocationLine.setLastInventoryDateT(inventory.getValidatedOn().atStartOfDay().atZone(ZoneOffset.UTC));
}
String rack = realRacks.get(product);
if (rack != null) {
stockLocationLine.setRack(rack);
}
}
}
List<StockLocationLine> detailsStockLocationLineList = inventory.getStockLocation().getDetailsStockLocationLineList();
if (detailsStockLocationLineList != null) {
for (StockLocationLine detailsStockLocationLine : detailsStockLocationLineList) {
Product product = detailsStockLocationLine.getProduct();
TrackingNumber trackingNumber = detailsStockLocationLine.getTrackingNumber();
BigDecimal realQty = realQties.get(Pair.of(product, trackingNumber));
if (realQty != null) {
detailsStockLocationLine.setLastInventoryRealQty(realQty);
detailsStockLocationLine.setLastInventoryDateT(inventory.getValidatedOn().atStartOfDay().atZone(ZoneOffset.UTC));
}
String rack = realRacks.get(product);
if (rack != null) {
detailsStockLocationLine.setRack(rack);
}
}
}
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockLocationLineController method allocateAll.
/**
* Called from stock location line form view, on allocateAll button click. Call {@link
* StockLocationLineReservationService#allocateAll(StockLocationLine)}
*
* @param request
* @param response
*/
public void allocateAll(ActionRequest request, ActionResponse response) {
try {
StockLocationLine stockLocationLine = request.getContext().asType(StockLocationLine.class);
stockLocationLine = Beans.get(StockLocationLineRepository.class).find(stockLocationLine.getId());
Beans.get(StockLocationLineReservationService.class).allocateAll(stockLocationLine);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.StockLocationLine 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.db.StockLocationLine 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