use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockCorrectionServiceImpl method generateStockMove.
public StockMove generateStockMove(StockCorrection stockCorrection) throws AxelorException {
StockLocation toStockLocation = stockCorrection.getStockLocation();
Company company = toStockLocation.getCompany();
StockLocation fromStockLocation = stockConfigService.getInventoryVirtualStockLocation(stockConfigService.getStockConfig(company));
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
StockLocationLine stockLocationLine = null;
StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
if (stockCorrection.getTrackingNumber() == null) {
stockLocationLine = stockLocationLineService.getStockLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct());
} else {
stockLocationLine = stockLocationLineService.getDetailLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct(), stockCorrection.getTrackingNumber());
}
BigDecimal realQty = stockCorrection.getRealQty();
Product product = stockCorrection.getProduct();
TrackingNumber trackingNumber = stockCorrection.getTrackingNumber();
BigDecimal diff = realQty.subtract(stockLocationLine.getCurrentQty());
StockMove stockMove = null;
if (diff.compareTo(BigDecimal.ZERO) == 0) {
return null;
} else if (diff.compareTo(BigDecimal.ZERO) > 0) {
stockMove = this.createStockMoveHeader(company, fromStockLocation, toStockLocation);
} else {
stockMove = this.createStockMoveHeader(company, toStockLocation, fromStockLocation);
}
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_STOCK_CORRECTION);
stockMove.setOriginId(stockCorrection.getId());
stockMove.setStockCorrectionReason(stockCorrection.getStockCorrectionReason());
BigDecimal productCostPrice = (BigDecimal) productCompanyService.get(product, "costPrice", company);
StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff.abs(), productCostPrice, productCostPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
if (stockMoveLine == null) {
throw new AxelorException(stockCorrection, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_CORRECTION_1));
}
if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
stockMoveLine.setTrackingNumber(trackingNumber);
}
stockMoveService.plan(stockMove);
stockMoveService.copyQtyToRealQty(stockMove);
stockMoveService.realize(stockMove, false);
return stockMove;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockCorrectionServiceImpl method fillDeafultQtys.
@Override
public Map<String, Object> fillDeafultQtys(StockCorrection stockCorrection) {
Map<String, Object> stockCorrectionQtys = new HashMap<>();
StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
StockLocationLine stockLocationLine;
if (stockCorrection.getTrackingNumber() == null) {
stockLocationLine = stockLocationLineService.getStockLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct());
} else {
stockLocationLine = stockLocationLineService.getDetailLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct(), stockCorrection.getTrackingNumber());
}
if (stockLocationLine != null) {
getDefaultQtys(stockLocationLine, stockCorrectionQtys);
}
return stockCorrectionQtys;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockLocationServiceImpl method getBadStockLocationLineId.
public List<Long> getBadStockLocationLineId() {
List<StockLocationLine> stockLocationLineList = Beans.get(StockLocationLineRepository.class).all().filter("self.stockLocation.typeSelect = 1 OR self.stockLocation.typeSelect = 2").fetch();
List<Long> idList = new ArrayList<>();
StockRulesRepository stockRulesRepository = Beans.get(StockRulesRepository.class);
for (StockLocationLine stockLocationLine : stockLocationLineList) {
StockRules stockRules = stockRulesRepository.all().filter("self.stockLocation = ?1 AND self.product = ?2", stockLocationLine.getStockLocation(), stockLocationLine.getProduct()).fetchOne();
if (stockRules != null && stockLocationLine.getFutureQty().compareTo(stockRules.getMinQty()) < 0) {
idList.add(stockLocationLine.getId());
}
}
if (idList.isEmpty()) {
idList.add(0L);
}
return idList;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method computeFromStockLocation.
/**
* Compute the price corresponding to the stock move line in the stock location. The price is the
* average price in the stock location line with the same product as the stock move line, after
* converting the unit.
*
* @param stockMoveLine a stock move line with a product.
* @param stockLocation a stock location.
* @return the computed price.
* @throws AxelorException if the conversion fails.
*/
protected BigDecimal computeFromStockLocation(StockMoveLine stockMoveLine, StockLocation stockLocation) throws AxelorException {
Optional<StockLocationLine> stockLocationLine = Optional.ofNullable(stockLocationLineService.getStockLocationLine(stockLocation, stockMoveLine.getProduct()));
BigDecimal priceFromLocation = BigDecimal.ZERO;
if (stockLocationLine.isPresent()) {
priceFromLocation = stockLocationLine.get().getAvgPrice();
priceFromLocation = unitConversionService.convert(stockMoveLine.getUnit(), getStockUnit(stockMoveLine), priceFromLocation, priceFromLocation.scale(), null);
}
return priceFromLocation;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method fillRealizeWapPrice.
public void fillRealizeWapPrice(StockMoveLine stockMoveLine) {
StockLocation stockLocation = stockMoveLine.getStockMove().getFromStockLocation();
Optional<StockLocationLine> stockLocationLineOpt = Optional.ofNullable(stockLocationLineService.getStockLocationLine(stockLocation, stockMoveLine.getProduct()));
stockLocationLineOpt.ifPresent(stockLocationLine -> stockMoveLine.setWapPrice(stockLocationLine.getAvgPrice()));
}
Aggregations