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