Search in sources :

Example 6 with StockLocation

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

the class StockLocationLineServiceImpl method getStockLocationLineListForAProduct.

@Override
public String getStockLocationLineListForAProduct(Long productId, Long companyId, Long stockLocationId) {
    String query = "self.product.id = " + productId + " AND self.stockLocation.typeSelect != " + StockLocationRepository.TYPE_VIRTUAL;
    if (companyId != 0L) {
        query += " AND self.stockLocation.company.id = " + companyId;
        if (stockLocationId != 0L) {
            StockLocation stockLocation = Beans.get(StockLocationRepository.class).find(stockLocationId);
            List<StockLocation> stockLocationList = Beans.get(StockLocationService.class).getAllLocationAndSubLocation(stockLocation, false);
            if (!stockLocationList.isEmpty() && stockLocation.getCompany().getId().equals(companyId)) {
                query += " AND self.stockLocation.id IN (" + StringTool.getIdListString(stockLocationList) + ") ";
            }
        }
    }
    return query;
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository)

Example 7 with StockLocation

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

the class StockLocationLineServiceImpl method checkStockMax.

protected void checkStockMax(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type, BigDecimal baseQty) throws AxelorException {
    StockLocation stockLocation = stockLocationLine.getStockLocation();
    StockRules stockRules = stockRulesService.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
    if (stockRules == null || !stockRules.getUseMaxQty()) {
        return;
    }
    if (baseQty.add(qty).compareTo(stockRules.getMaxQty()) > 0) {
        throw new AxelorException(stockLocationLine, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOCATION_LINE_3), stockLocationLine.getProduct().getName(), stockLocationLine.getProduct().getCode());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) StockRules(com.axelor.apps.stock.db.StockRules)

Example 8 with StockLocation

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

the class ProductStockRepository method setAvailableQty.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void setAvailableQty(Map<String, Object> json, Map<String, Object> context) {
    try {
        Long productId = (Long) json.get("id");
        Product product = find(productId);
        if (context.get("_parent") != null) {
            Map<String, Object> _parent = (Map<String, Object>) context.get("_parent");
            StockLocation stockLocation = null;
            if (context.get("_model").toString().equals("com.axelor.apps.stock.db.StockMoveLine")) {
                if (_parent.get("fromStockLocation") != null) {
                    stockLocation = stockLocationRepo.find(Long.parseLong(((Map) _parent.get("fromStockLocation")).get("id").toString()));
                }
            } else {
                if (_parent.get("stockLocation") != null) {
                    stockLocation = stockLocationRepo.find(Long.parseLong(((Map) _parent.get("stockLocation")).get("id").toString()));
                }
            }
            if (stockLocation != null) {
                BigDecimal availableQty = stockLocationLineService.getAvailableQty(stockLocation, product);
                json.put("$availableQty", availableQty);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 9 with StockLocation

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

the class StockLocationStockRepository method copy.

@Override
public StockLocation copy(StockLocation entity, boolean deep) {
    StockLocation copy = super.copy(entity, deep);
    copy.clearDetailsStockLocationLineList();
    copy.clearStockLocationLineList();
    return copy;
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation)

Example 10 with StockLocation

use of com.axelor.apps.stock.db.StockLocation 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)

Aggregations

StockLocation (com.axelor.apps.stock.db.StockLocation)56 Company (com.axelor.apps.base.db.Company)19 BigDecimal (java.math.BigDecimal)18 Product (com.axelor.apps.base.db.Product)15 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockLocationRepository (com.axelor.apps.stock.db.repo.StockLocationRepository)12 ArrayList (java.util.ArrayList)12 StockConfig (com.axelor.apps.stock.db.StockConfig)10 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)9 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 StockLocationService (com.axelor.apps.stock.service.StockLocationService)8 List (java.util.List)8 Partner (com.axelor.apps.base.db.Partner)6 Unit (com.axelor.apps.base.db.Unit)6 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)6 LocalDate (java.time.LocalDate)6 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)5 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)5