Search in sources :

Example 16 with StockLocation

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

the class SaleOrderLineServiceSupplyChainImpl method getSaleOrderLineListForAProduct.

@Override
public String getSaleOrderLineListForAProduct(Long productId, Long companyId, Long stockLocationId) {
    List<Integer> statusList = new ArrayList<>();
    statusList.add(SaleOrderRepository.STATUS_ORDER_CONFIRMED);
    String status = Beans.get(AppSupplychainService.class).getAppSupplychain().getsOFilterOnStockDetailStatusSelect();
    if (!StringUtils.isBlank(status)) {
        statusList = StringTool.getIntegerList(status);
    }
    String statusListQuery = statusList.stream().map(String::valueOf).collect(Collectors.joining(","));
    String query = "self.product.id = " + productId + " AND self.deliveryState != " + SaleOrderLineRepository.DELIVERY_STATE_DELIVERED + " AND self.saleOrder.statusSelect IN (" + statusListQuery + ")";
    if (companyId != 0L) {
        query += " AND self.saleOrder.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.saleOrder.stockLocation.id IN (" + StringTool.getIdListString(stockLocationList) + ") ";
            }
        }
    }
    return query;
}
Also used : StockLocationService(com.axelor.apps.stock.service.StockLocationService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) ArrayList(java.util.ArrayList)

Example 17 with StockLocation

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

the class PurchaseOrderStockServiceImpl method getStartStockLocation.

protected StockLocation getStartStockLocation(PurchaseOrder purchaseOrder) throws AxelorException {
    Company company = purchaseOrder.getCompany();
    StockLocation startLocation = purchaseOrder.getFromStockLocation();
    if (startLocation == null) {
        startLocation = partnerStockSettingsService.getDefaultExternalStockLocation(purchaseOrder.getSupplierPartner(), company);
    }
    if (startLocation == null) {
        StockConfigService stockConfigService = Beans.get(StockConfigService.class);
        StockConfig stockConfig = stockConfigService.getStockConfig(company);
        startLocation = stockConfigService.getSupplierVirtualStockLocation(stockConfig);
    }
    if (startLocation == null) {
        throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PURCHASE_ORDER_1), company.getName());
    }
    return startLocation;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockConfig(com.axelor.apps.stock.db.StockConfig) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService)

Example 18 with StockLocation

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

the class PurchaseOrderStockServiceImpl method getPurchaseOrderLineListForAProduct.

@Override
public String getPurchaseOrderLineListForAProduct(Long productId, Long companyId, Long stockLocationId) {
    List<Integer> statusList = new ArrayList<>();
    statusList.add(PurchaseOrderRepository.STATUS_VALIDATED);
    String status = Beans.get(AppSupplychainService.class).getAppSupplychain().getpOFilterOnStockDetailStatusSelect();
    if (!StringUtils.isBlank(status)) {
        statusList = StringTool.getIntegerList(status);
    }
    String statusListQuery = statusList.stream().map(String::valueOf).collect(Collectors.joining(","));
    String query = "self.product.id = " + productId + " AND self.receiptState != " + PurchaseOrderLineRepository.RECEIPT_STATE_RECEIVED + " AND self.purchaseOrder.statusSelect IN (" + statusListQuery + ")";
    if (companyId != 0L) {
        query += " AND self.purchaseOrder.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.purchaseOrder.stockLocation.id IN (" + StringTool.getIdListString(stockLocationList) + ") ";
            }
        }
    }
    return query;
}
Also used : StockLocationService(com.axelor.apps.stock.service.StockLocationService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) ArrayList(java.util.ArrayList)

Example 19 with StockLocation

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

the class PurchaseRequestServiceSupplychainImpl method getPurchaseOrderGroupBySupplierKey.

@Override
protected String getPurchaseOrderGroupBySupplierKey(PurchaseRequest purchaseRequest) {
    String key = super.getPurchaseOrderGroupBySupplierKey(purchaseRequest);
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return key;
    }
    StockLocation stockLocation = purchaseRequest.getStockLocation();
    if (stockLocation != null) {
        key = key + "_" + stockLocation.getId().toString();
    }
    return key;
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation)

Example 20 with StockLocation

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

the class ProductStockLocationServiceImpl method computeIndicators.

@Override
public Map<String, Object> computeIndicators(Long productId, Long companyId, Long stockLocationId) throws AxelorException {
    Map<String, Object> map = new HashMap<>();
    Product product = productRepository.find(productId);
    Company company = companyRepository.find(companyId);
    StockLocation stockLocation = stockLocationRepository.find(stockLocationId);
    int scale = appBaseService.getNbDecimalDigitForQty();
    if (stockLocationId != 0L && companyId != 0L) {
        List<StockLocation> stockLocationList = stockLocationService.getAllLocationAndSubLocation(stockLocation, false);
        if (!stockLocationList.isEmpty()) {
            BigDecimal realQty = BigDecimal.ZERO;
            BigDecimal futureQty = BigDecimal.ZERO;
            BigDecimal reservedQty = BigDecimal.ZERO;
            BigDecimal requestedReservedQty = BigDecimal.ZERO;
            BigDecimal saleOrderQty = BigDecimal.ZERO;
            BigDecimal purchaseOrderQty = BigDecimal.ZERO;
            BigDecimal availableQty = BigDecimal.ZERO;
            saleOrderQty = this.getSaleOrderQty(product, company, stockLocation);
            purchaseOrderQty = this.getPurchaseOrderQty(product, company, stockLocation);
            availableQty = this.getAvailableQty(product, company, stockLocation);
            requestedReservedQty = this.getRequestedReservedQty(product, company, stockLocation);
            for (StockLocation sl : stockLocationList) {
                realQty = realQty.add(stockLocationService.getRealQty(productId, sl.getId(), companyId));
                futureQty = futureQty.add(stockLocationService.getFutureQty(productId, sl.getId(), companyId));
                reservedQty = reservedQty.add(stockLocationServiceSupplychain.getReservedQty(productId, sl.getId(), companyId));
            }
            map.put("$realQty", realQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$futureQty", futureQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$reservedQty", reservedQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$requestedReservedQty", requestedReservedQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$saleOrderQty", saleOrderQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$purchaseOrderQty", purchaseOrderQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$availableQty", availableQty.subtract(reservedQty).setScale(scale, RoundingMode.HALF_UP));
            return map;
        }
    }
    BigDecimal reservedQty = stockLocationServiceSupplychain.getReservedQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP);
    map.put("$realQty", stockLocationService.getRealQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP));
    map.put("$futureQty", stockLocationService.getFutureQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP));
    map.put("$reservedQty", reservedQty);
    map.put("$requestedReservedQty", this.getRequestedReservedQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
    map.put("$saleOrderQty", this.getSaleOrderQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
    map.put("$purchaseOrderQty", this.getPurchaseOrderQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
    map.put("$availableQty", this.getAvailableQty(product, company, null).subtract(reservedQty).setScale(scale, RoundingMode.HALF_UP));
    return map;
}
Also used : Company(com.axelor.apps.base.db.Company) HashMap(java.util.HashMap) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) 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