Search in sources :

Example 16 with StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.

the class StockLocationLineServiceImpl method createDetailLocationLine.

@Override
public StockLocationLine createDetailLocationLine(StockLocation stockLocation, Product product, TrackingNumber trackingNumber) {
    LOG.debug("Création d'une ligne de détail de stock : Entrepot? {}, Produit? {}, Num de suivi? {} ", stockLocation.getName(), product.getCode(), trackingNumber.getTrackingNumberSeq());
    StockLocationLine detailLocationLine = new StockLocationLine();
    detailLocationLine.setDetailsStockLocation(stockLocation);
    stockLocation.addDetailsStockLocationLineListItem(detailLocationLine);
    detailLocationLine.setProduct(product);
    detailLocationLine.setUnit(product.getUnit());
    detailLocationLine.setCurrentQty(BigDecimal.ZERO);
    detailLocationLine.setFutureQty(BigDecimal.ZERO);
    detailLocationLine.setTrackingNumber(trackingNumber);
    return detailLocationLine;
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Example 17 with StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.

the class ABCAnalysisServiceStockImpl method createABCAnalysisLine.

@Override
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
    ABCAnalysisLine abcAnalysisLine = null;
    List<StockLocation> stockLocationList = stockLocationService.getAllLocationAndSubLocation(abcAnalysis.getStockLocation(), false);
    BigDecimal productQty = BigDecimal.ZERO;
    BigDecimal productWorth = BigDecimal.ZERO;
    List<StockLocationLine> stockLocationLineList;
    int offset = 0;
    Query<StockLocationLine> stockLocationLineQuery = stockLocationLineRepository.all().filter("self.stockLocation IN :stockLocationList AND self.product.id = :productId AND self.currentQty != 0 ").bind("stockLocationList", stockLocationList).bind("productId", product.getId());
    while (!(stockLocationLineList = stockLocationLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
        offset += stockLocationLineList.size();
        abcAnalysis = abcAnalysisRepository.find(abcAnalysis.getId());
        if (abcAnalysisLine == null) {
            abcAnalysisLine = super.createABCAnalysisLine(abcAnalysis, product).get();
        }
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            BigDecimal convertedQty = unitConversionService.convert(stockLocationLine.getUnit(), product.getUnit(), stockLocationLine.getCurrentQty(), 5, product);
            productQty = productQty.add(convertedQty);
            productWorth = productWorth.add(stockLocationLine.getAvgPrice());
        }
        super.incTotalQty(productQty);
        super.incTotalWorth(productWorth);
        JPA.clear();
    }
    if (abcAnalysisLine != null) {
        setQtyWorth(abcAnalysisLineRepository.find(abcAnalysisLine.getId()), productQty, productWorth);
    }
    return Optional.ofNullable(abcAnalysisLine);
}
Also used : ABCAnalysisLine(com.axelor.apps.base.db.ABCAnalysisLine) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 18 with StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.

the class StockCorrectionController method setDefaultDetails.

public void setDefaultDetails(ActionRequest request, ActionResponse response) {
    try {
        Long stockLocaLocationLineId = Long.valueOf(request.getContext().get("_stockLocationLineId").toString());
        StockLocationLine stockLocationLine = Beans.get(StockLocationLineRepository.class).find(stockLocaLocationLineId);
        Map<String, Object> stockCorrectionDetails;
        if (stockLocationLine != null) {
            stockCorrectionDetails = Beans.get(StockCorrectionService.class).fillDefaultValues(stockLocationLine);
            response.setValues(stockCorrectionDetails);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Example 19 with StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method updateRequestedReservedQty.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateRequestedReservedQty(StockMoveLine stockMoveLine, BigDecimal newReservedQty) throws AxelorException {
    StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
    updateRequestedReservedQty(stockLocationLine, stockMoveLine, newReservedQty);
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Transactional(com.google.inject.persist.Transactional)

Example 20 with StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method changeRequestedQtyLowerThanQty.

/**
 * On planning, we want the requested quantity to be equal or lower to the quantity of the line.
 * So, if the requested quantity is greater than the quantity, we change it to be equal.
 *
 * @param stockMoveLine
 * @throws AxelorException
 */
protected void changeRequestedQtyLowerThanQty(StockMoveLine stockMoveLine) throws AxelorException {
    BigDecimal qty = stockMoveLine.getRealQty().max(BigDecimal.ZERO);
    BigDecimal requestedReservedQty = stockMoveLine.getRequestedReservedQty();
    if (requestedReservedQty.compareTo(qty) > 0) {
        Product product = stockMoveLine.getProduct();
        BigDecimal diffRequestedQty = requestedReservedQty.subtract(qty);
        stockMoveLine.setRequestedReservedQty(qty);
        // update in stock location line
        StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), product);
        BigDecimal diffRequestedQuantityLocation = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), diffRequestedQty, product);
        stockLocationLine.setRequestedReservedQty(stockLocationLine.getRequestedReservedQty().add(diffRequestedQuantityLocation));
    }
}
Also used : Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Aggregations

StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)42 BigDecimal (java.math.BigDecimal)25 Product (com.axelor.apps.base.db.Product)13 Transactional (com.google.inject.persist.Transactional)10 StockLocation (com.axelor.apps.stock.db.StockLocation)8 AxelorException (com.axelor.exception.AxelorException)8 Unit (com.axelor.apps.base.db.Unit)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)6 InventoryLine (com.axelor.apps.stock.db.InventoryLine)4 StockLocationLineRepository (com.axelor.apps.stock.db.repo.StockLocationLineRepository)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Company (com.axelor.apps.base.db.Company)3 StockMove (com.axelor.apps.stock.db.StockMove)3 Beans (com.axelor.inject.Beans)3 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)2 Inventory (com.axelor.apps.stock.db.Inventory)2