Search in sources :

Example 6 with TrackingNumber

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);
            }
        }
    }
}
Also used : TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) HashMap(java.util.HashMap) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Pair(org.apache.commons.lang3.tuple.Pair) InventoryLine(com.axelor.apps.stock.db.InventoryLine)

Example 7 with TrackingNumber

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;
}
Also used : TrackingNumber(com.axelor.apps.stock.db.TrackingNumber)

Example 8 with 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);
}
Also used : TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) StockLocation(com.axelor.apps.stock.db.StockLocation) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 9 with TrackingNumber

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;
}
Also used : AppSupplychain(com.axelor.apps.base.db.AppSupplychain) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Query(javax.persistence.Query) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Transactional(com.google.inject.persist.Transactional)

Example 10 with TrackingNumber

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

Aggregations

TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)13 BigDecimal (java.math.BigDecimal)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)6 Product (com.axelor.apps.base.db.Product)5 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)5 AxelorException (com.axelor.exception.AxelorException)5 StockLocation (com.axelor.apps.stock.db.StockLocation)4 Transactional (com.google.inject.persist.Transactional)4 InventoryLine (com.axelor.apps.stock.db.InventoryLine)3 StockMove (com.axelor.apps.stock.db.StockMove)2 TrackingNumberConfiguration (com.axelor.apps.stock.db.TrackingNumberConfiguration)2 Beans (com.axelor.inject.Beans)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AppSupplychain (com.axelor.apps.base.db.AppSupplychain)1 Company (com.axelor.apps.base.db.Company)1 Sequence (com.axelor.apps.base.db.Sequence)1 Wizard (com.axelor.apps.base.db.Wizard)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1