use of com.axelor.apps.stock.db.repo.StockMoveRepository in project axelor-open-suite by axelor.
the class SaleOrderController method notifyStockMoveCreated.
public void notifyStockMoveCreated(ActionRequest request, ActionResponse response) {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
StockMoveRepository stockMoveRepo = Beans.get(StockMoveRepository.class);
StockMove stockMove = stockMoveRepo.all().filter("self.originTypeSelect = ?1 AND self.originId = ?2 AND self.statusSelect = ?3", "com.axelor.apps.sale.db.SaleOrder", saleOrder.getId(), StockMoveRepository.STATUS_PLANNED).fetchOne();
if (stockMove != null) {
response.setNotify(String.format(I18n.get(IExceptionMessage.SALE_ORDER_STOCK_MOVE_CREATED), stockMove.getStockMoveSeq()));
}
}
use of com.axelor.apps.stock.db.repo.StockMoveRepository in project axelor-open-suite by axelor.
the class SaleOrderController method createStockMove.
public void createStockMove(ActionRequest request, ActionResponse response) {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
try {
if (saleOrder.getId() != null) {
SaleOrderStockService saleOrderStockService = Beans.get(SaleOrderStockService.class);
List<Long> stockMoveList = saleOrderStockService.createStocksMovesFromSaleOrder(Beans.get(SaleOrderRepository.class).find(saleOrder.getId()));
if (stockMoveList != null && stockMoveList.size() == 1) {
response.setView(ActionView.define(I18n.get("Stock move")).model(StockMove.class.getName()).add("form", "stock-move-form").add("grid", "stock-move-grid").param("search-filters", "internal-stock-move-filters").param("forceEdit", "true").domain("self.id = " + stockMoveList.get(0)).context("_showRecord", String.valueOf(stockMoveList.get(0))).context("_userType", StockMoveRepository.USER_TYPE_SALESPERSON).map());
// we have to inject TraceBackService to use non static methods
Beans.get(TraceBackService.class).findLastMessageTraceBack(Beans.get(StockMoveRepository.class).find(stockMoveList.get(0))).ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
} else if (stockMoveList != null && stockMoveList.size() > 1) {
response.setView(ActionView.define(I18n.get("Stock move")).model(StockMove.class.getName()).add("grid", "stock-move-grid").add("form", "stock-move-form").param("search-filters", "internal-stock-move-filters").domain("self.id in (" + Joiner.on(",").join(stockMoveList) + ")").context("_userType", StockMoveRepository.USER_TYPE_SALESPERSON).map());
// we have to inject TraceBackService to use non static methods
TraceBackService traceBackService = Beans.get(TraceBackService.class);
StockMoveRepository stockMoveRepository = Beans.get(StockMoveRepository.class);
stockMoveList.stream().map(stockMoveRepository::find).map(traceBackService::findLastMessageTraceBack).filter(Optional::isPresent).map(Optional::get).findAny().ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
} else {
response.setFlash(I18n.get(IExceptionMessage.SO_NO_DELIVERY_STOCK_MOVE_TO_GENERATE));
}
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.repo.StockMoveRepository in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method generateMultipleInvoices.
@Override
public Entry<List<Long>, String> generateMultipleInvoices(List<Long> stockMoveIdList) {
StockMoveRepository stockMoveRepository = Beans.get(StockMoveRepository.class);
List<Long> invoiceIdList = new ArrayList<>();
StringBuilder stockMovesInError = new StringBuilder();
List<StockMove> stockMoveList;
Query<StockMove> stockMoveQuery = stockMoveRepository.all().filter("self.id IN :stockMoveIdList").bind("stockMoveIdList", stockMoveIdList).order("id");
int offset = 0;
while (!(stockMoveList = stockMoveQuery.fetch(AbstractBatch.FETCH_LIMIT, offset)).isEmpty()) {
for (StockMove stockMove : stockMoveList) {
offset++;
try {
Invoice invoice = stockMoveInvoiceService.createInvoice(stockMove, 0, null);
if (invoice != null) {
invoiceIdList.add(invoice.getId());
}
} catch (Exception e) {
if (stockMovesInError.length() > 0) {
stockMovesInError.append("<br/>");
}
stockMovesInError.append(String.format(I18n.get(IExceptionMessage.STOCK_MOVE_GENERATE_INVOICE), stockMove.getName(), e.getLocalizedMessage()));
break;
}
}
JPA.clear();
}
return new SimpleImmutableEntry<>(invoiceIdList, stockMovesInError.toString());
}
Aggregations