use of com.axelor.apps.stock.db.TrackingNumber 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.TrackingNumber in project axelor-open-suite by axelor.
the class InventoryService method getTrackingNumber.
public TrackingNumber getTrackingNumber(String sequence, Product product, BigDecimal realQty) {
TrackingNumber trackingNumber = null;
if (!StringUtils.isEmpty(sequence)) {
trackingNumber = trackingNumberRepository.all().filter("self.trackingNumberSeq = ?1 and self.product = ?2", sequence, product).fetchOne();
if (trackingNumber == null) {
trackingNumber = new TrackingNumber();
trackingNumber.setTrackingNumberSeq(sequence);
trackingNumber.setProduct(product);
trackingNumber.setCounter(realQty);
}
}
return trackingNumber;
}
use of com.axelor.apps.stock.db.TrackingNumber in project axelor-open-suite by axelor.
the class TrackingNumberManagementRepository method populate.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
try {
Long trackingNumberId = (Long) json.get("id");
TrackingNumber trackingNumber = find(trackingNumberId);
if (trackingNumber.getProduct() != null && context.get("_parent") != null) {
Map<String, Object> _parent = (Map<String, Object>) context.get("_parent");
if (_parent.get("fromStockLocation") != null) {
StockLocation stockLocation = stockLocationRepo.find(Long.parseLong(((Map) _parent.get("fromStockLocation")).get("id").toString()));
if (stockLocation != null) {
BigDecimal availableQty = stockLocationLineService.getTrackingNumberAvailableQty(stockLocation, trackingNumber);
json.put("$availableQty", availableQty);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return super.populate(json, context);
}
use of com.axelor.apps.stock.db.TrackingNumber in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method realize.
@Override
@Transactional(rollbackOn = { Exception.class })
public String realize(StockMove stockMove, boolean check) throws AxelorException {
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return super.realize(stockMove, check);
}
LOG.debug("RĂ©alisation du mouvement de stock : {} ", stockMove.getStockMoveSeq());
String newStockSeq = super.realize(stockMove, check);
AppSupplychain appSupplychain = appSupplyChainService.getAppSupplychain();
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
updateSaleOrderLinesDeliveryState(stockMove, !stockMove.getIsReversion());
// Update linked saleOrder delivery state depending on BackOrder's existence
SaleOrder saleOrder = saleOrderRepo.find(stockMove.getOriginId());
if (newStockSeq != null) {
saleOrder.setDeliveryState(SaleOrderRepository.DELIVERY_STATE_PARTIALLY_DELIVERED);
} else {
Beans.get(SaleOrderStockService.class).updateDeliveryState(saleOrder);
if (appSupplychain.getTerminateSaleOrderOnDelivery()) {
terminateOrConfirmSaleOrderStatus(saleOrder);
}
}
Beans.get(SaleOrderRepository.class).save(saleOrder);
} else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
updatePurchaseOrderLines(stockMove, !stockMove.getIsReversion());
// Update linked purchaseOrder receipt state depending on BackOrder's existence
PurchaseOrder purchaseOrder = purchaseOrderRepo.find(stockMove.getOriginId());
if (newStockSeq != null) {
purchaseOrder.setReceiptState(PurchaseOrderRepository.STATE_PARTIALLY_RECEIVED);
} else {
Beans.get(PurchaseOrderStockService.class).updateReceiptState(purchaseOrder);
if (appSupplychain.getTerminatePurchaseOrderOnReceipt()) {
finishOrValidatePurchaseOrderStatus(purchaseOrder);
}
}
Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
}
if (appSupplyChainService.getAppSupplychain().getManageStockReservation()) {
Beans.get(ReservedQtyService.class).updateReservedQuantity(stockMove, StockMoveRepository.STATUS_REALIZED);
}
detachNonDeliveredStockMoveLines(stockMove);
List<Long> trackingNumberIds = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getTrackingNumber).filter(Objects::nonNull).map(TrackingNumber::getId).filter(Objects::nonNull).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(trackingNumberIds)) {
Query update = JPA.em().createQuery("UPDATE FixedAsset self SET self.stockLocation = :stockLocation WHERE self.trackingNumber.id IN (:trackingNumber)");
update.setParameter("stockLocation", stockMove.getToStockLocation());
update.setParameter("trackingNumber", trackingNumberIds);
update.executeUpdate();
}
return newStockSeq;
}
use of com.axelor.apps.stock.db.TrackingNumber 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);
}
Aggregations