use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method getSpreadableQtyMap.
@Override
public Map<StockMoveLine, BigDecimal> getSpreadableQtyMap(LogisticalForm logisticalForm) {
Set<StockMove> stockMoveSet = new LinkedHashSet<>();
Map<StockMoveLine, BigDecimal> spreadableQtyMap = new LinkedHashMap<>();
if (logisticalForm.getLogisticalFormLineList() != null) {
StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
logisticalForm.getLogisticalFormLineList().stream().filter(logisticalFormLine -> logisticalFormLine.getTypeSelect() == LogisticalFormLineRepository.TYPE_DETAIL && logisticalFormLine.getStockMoveLine() != null && logisticalFormLine.getStockMoveLine().getStockMove() != null).forEach(logisticalFormLine -> stockMoveSet.add(logisticalFormLine.getStockMoveLine().getStockMove()));
for (StockMove stockMove : stockMoveSet) {
if (stockMove.getStockMoveLineList() == null) {
continue;
}
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
BigDecimal spreadableQty = stockMoveLineService.computeSpreadableQtyOverLogisticalFormLines(stockMoveLine, logisticalForm);
spreadableQtyMap.put(stockMoveLine, spreadableQty);
}
}
}
return spreadableQtyMap;
}
use of com.axelor.apps.stock.db.StockMove 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.StockMove in project axelor-open-suite by axelor.
the class StockCorrectionServiceImpl method validate.
@Override
@Transactional(rollbackOn = { Exception.class })
public boolean validate(StockCorrection stockCorrection) throws AxelorException {
AppBaseService baseService = Beans.get(AppBaseService.class);
StockMove stockMove = generateStockMove(stockCorrection);
if (stockMove != null) {
stockCorrection.setStatusSelect(StockCorrectionRepository.STATUS_VALIDATED);
stockCorrection.setValidationDateT(baseService.getTodayDateTime().toLocalDateTime());
return true;
}
return false;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class InventoryService method cancel.
@Transactional(rollbackOn = { Exception.class })
public void cancel(Inventory inventory) throws AxelorException {
List<StockMove> stockMoveList = stockMoveRepo.all().filter("self.originTypeSelect = :originTypeSelect AND self.originId = :originId").bind("originTypeSelect", StockMoveRepository.ORIGIN_INVENTORY).bind("originId", inventory.getId()).fetch();
for (StockMove stockMove : stockMoveList) {
stockMoveService.cancel(stockMove);
}
inventory.setStatusSelect(InventoryRepository.STATUS_CANCELED);
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method getFullySpreadStockMoveList.
protected List<StockMove> getFullySpreadStockMoveList(LogisticalForm logisticalForm) {
List<StockMove> fullySpreadStockMoveList = new ArrayList<>();
List<StockMoveLine> fullySpreadStockMoveLineList = getFullySpreadStockMoveLineList(logisticalForm);
Set<StockMove> stockMoveSet = new HashSet<>();
for (StockMoveLine stockMoveLine : fullySpreadStockMoveLineList) {
stockMoveSet.add(stockMoveLine.getStockMove());
}
for (StockMove stockMove : stockMoveSet) {
if (fullySpreadStockMoveLineList.containsAll(stockMove.getStockMoveLineList())) {
fullySpreadStockMoveList.add(stockMove);
}
}
return fullySpreadStockMoveList;
}
Aggregations