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