use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method checkExpirationDates.
@Override
public void checkExpirationDates(StockMove stockMove) throws AxelorException {
List<String> errorList = new ArrayList<>();
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
TrackingNumber trackingNumber = stockMoveLine.getTrackingNumber();
if (trackingNumber == null) {
continue;
}
Product product = trackingNumber.getProduct();
if (product == null || !product.getCheckExpirationDateAtStockMoveRealization()) {
continue;
}
if (product.getHasWarranty() && trackingNumber.getWarrantyExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany())) || product.getIsPerishable() && trackingNumber.getPerishableExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany()))) {
errorList.add(product.getName());
}
}
if (!errorList.isEmpty()) {
String errorStr = errorList.stream().collect(Collectors.joining(", "));
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_LINE_EXPIRED_PRODUCTS), errorStr);
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class InventoryService method generateStockMoveLines.
/**
* Generate lines for the given stock move. Depending if we are creating an incoming or outgoing
* stock move, we only create stock move line with positive quantity.
*
* @param inventoryLine an inventory line
* @param stockMove a stock move being created
* @param isEnteringStock whether we are creating an incoming or outgoing stock move.
* @throws AxelorException
*/
protected void generateStockMoveLines(InventoryLine inventoryLine, StockMove stockMove, boolean isEnteringStock) throws AxelorException {
Product product = inventoryLine.getProduct();
TrackingNumber trackingNumber = inventoryLine.getTrackingNumber();
BigDecimal diff = inventoryLine.getRealQty().subtract(inventoryLine.getCurrentQty());
if (!isEnteringStock) {
diff = diff.negate();
}
if (diff.signum() > 0) {
BigDecimal avgPrice;
StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockMove.getToStockLocation(), product);
if (stockLocationLine != null) {
avgPrice = stockLocationLine.getAvgPrice();
} else {
avgPrice = BigDecimal.ZERO;
}
StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff, avgPrice, avgPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
if (stockMoveLine == null) {
throw new AxelorException(inventoryLine.getInventory(), TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVENTORY_7) + " " + inventoryLine.getInventory().getInventorySeq());
}
if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
stockMoveLine.setTrackingNumber(trackingNumber);
}
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class StockLocationLineServiceImpl method computeFutureQty.
@Override
public BigDecimal computeFutureQty(StockLocationLine stockLocationLine) throws AxelorException {
// future quantity is current quantity minus planned outgoing stock move lines plus planned
// incoming stock move lines.
Product product = stockLocationLine.getProduct();
BigDecimal futureQty = stockLocationLine.getCurrentQty();
List<StockMoveLine> incomingStockMoveLineList = findIncomingPlannedStockMoveLines(stockLocationLine);
List<StockMoveLine> outgoingStockMoveLineList = findOutgoingPlannedStockMoveLines(stockLocationLine);
if (stockLocationLine.getUnit() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOCATION_LINE_MISSING_UNIT), stockLocationLine.getStockLocation().getName(), product.getFullName());
}
for (StockMoveLine incomingStockMoveLine : incomingStockMoveLineList) {
BigDecimal qtyToAdd = unitConversionService.convert(incomingStockMoveLine.getUnit(), stockLocationLine.getUnit(), incomingStockMoveLine.getRealQty(), incomingStockMoveLine.getRealQty().scale(), product);
futureQty = futureQty.add(qtyToAdd);
}
for (StockMoveLine outgoingStockMoveLine : outgoingStockMoveLineList) {
BigDecimal qtyToSubtract = unitConversionService.convert(outgoingStockMoveLine.getUnit(), stockLocationLine.getUnit(), outgoingStockMoveLine.getRealQty(), outgoingStockMoveLine.getRealQty().scale(), product);
futureQty = futureQty.subtract(qtyToSubtract);
}
return futureQty;
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class StockLocationLineServiceImpl method updateLocation.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateLocation(StockLocation stockLocation, Product product, Unit stockMoveLineUnit, BigDecimal qty, boolean current, boolean future, boolean isIncrement, LocalDate lastFutureStockMoveDate) throws AxelorException {
StockLocationLine stockLocationLine = this.getOrCreateStockLocationLine(stockLocation, product);
if (stockLocationLine == null) {
return;
}
Unit stockLocationLineUnit = stockLocationLine.getUnit();
if (stockLocationLineUnit == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOCATION_LINE_MISSING_UNIT), stockLocation.getName(), product.getFullName());
}
if (!stockLocationLineUnit.equals(stockMoveLineUnit)) {
qty = unitConversionService.convert(stockMoveLineUnit, stockLocationLineUnit, qty, qty.scale(), product);
}
LOG.debug("Mise à jour du stock : Entrepot? {}, Produit? {}, Quantité? {}, Actuel? {}, Futur? {}, Incrément? {}, Date? {} ", stockLocation.getName(), product.getCode(), qty, current, future, isIncrement, lastFutureStockMoveDate);
if (!isIncrement) {
minStockRules(product, qty, stockLocationLine, current, future);
} else {
maxStockRules(product, qty, stockLocationLine, current, future);
}
stockLocationLine = this.updateLocation(stockLocationLine, stockMoveLineUnit, product, qty, current, future, isIncrement, lastFutureStockMoveDate);
this.checkStockMin(stockLocationLine, false);
stockLocationLineRepo.save(stockLocationLine);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class StockLocationLineServiceImpl method updateDetailLocation.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateDetailLocation(StockLocation stockLocation, Product product, Unit stockMoveLineUnit, BigDecimal qty, boolean current, boolean future, boolean isIncrement, LocalDate lastFutureStockMoveDate, TrackingNumber trackingNumber) throws AxelorException {
StockLocationLine detailLocationLine = this.getOrCreateDetailLocationLine(stockLocation, product, trackingNumber);
if (detailLocationLine == null) {
return;
}
Unit stockLocationLineUnit = detailLocationLine.getUnit();
if (stockLocationLineUnit == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.DETAIL_LOCATION_LINE_MISSING_UNIT), trackingNumber.getTrackingNumberSeq(), stockLocation.getName(), product.getFullName());
}
if (!stockLocationLineUnit.equals(stockMoveLineUnit)) {
qty = unitConversionService.convert(stockMoveLineUnit, stockLocationLineUnit, qty, qty.scale(), product);
}
LOG.debug("Mise à jour du detail du stock : Entrepot? {}, Produit? {}, Quantité? {}, Actuel? {}, Futur? {}, Incrément? {}, Date? {}, Num de suivi? {} ", stockLocation.getName(), product.getCode(), qty, current, future, isIncrement, lastFutureStockMoveDate, trackingNumber);
detailLocationLine = this.updateLocation(detailLocationLine, stockMoveLineUnit, product, qty, current, future, isIncrement, lastFutureStockMoveDate);
this.checkStockMin(detailLocationLine, true);
stockLocationLineRepo.save(detailLocationLine);
}
Aggregations