use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method generateInvoice.
@SuppressWarnings("unchecked")
public void generateInvoice(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
if (context.containsKey("operationSelect")) {
Integer operationSelect = Integer.parseInt(context.get("operationSelect").toString());
List<Map<String, Object>> stockMoveLineListContext = null;
if (operationSelect == StockMoveRepository.INVOICE_PARTIALLY && context.containsKey("stockMoveLines")) {
stockMoveLineListContext = (List<Map<String, Object>>) context.get("stockMoveLines");
}
StockMove stockMove = Beans.get(StockMoveRepository.class).find(Long.parseLong(request.getContext().get("_id").toString()));
stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
Invoice invoice = Beans.get(StockMoveInvoiceService.class).createInvoice(stockMove, operationSelect, stockMoveLineListContext);
if (invoice != null) {
// Open the generated invoice in a new tab
response.setView(ActionView.define(I18n.get(ITranslation.INVOICE)).model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoice.getId())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(stockMove.getCompany())).map());
response.setCanClose(true);
} else {
response.setError(I18n.get(IExceptionMessage.STOCK_MOVE_NO_LINES_TO_INVOICE));
}
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ClientViewServiceImpl method getLastDeliveryIndicator.
/* StockMove Indicators */
protected String getLastDeliveryIndicator(User user) {
List<Filter> filters = getLastDeliveryOfUser(user);
StockMove stockMove = Filter.and(filters).build(StockMove.class).order("-realDate").fetchOne();
if (stockMove == null) {
return I18n.get(CLIENT_PORTAL_NO_DATE);
}
return stockMove.getRealDate() != null ? stockMove.getRealDate().format(DATE_FORMATTER) : I18n.get(CLIENT_PORTAL_NO_DATE);
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ClientViewController method showClientMyLastDelivery.
/* STOCKMOVE OnClick */
public void showClientMyLastDelivery(ActionRequest request, ActionResponse response) {
try {
ClientViewService clientViewService = Beans.get(ClientViewService.class);
User clientUser = clientViewService.getClientUser();
if (clientUser.getPartner() == null) {
response.setError(I18n.get(ITranslation.CLIENT_PORTAL_NO_PARTNER));
} else {
Filter filter = clientViewService.getLastDeliveryOfUser(clientUser).get(0);
if (filter != null) {
StockMove stockMove = Beans.get(StockMoveRepository.class).all().filter(filter.getQuery()).fetchOne();
if (stockMove != null) {
response.setView(ActionView.define(I18n.get("Last delivery")).model(StockMove.class.getName()).add("form", "stock-move-form").context("_showRecord", stockMove.getId()).map());
}
}
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ClientViewController method showClientMyNextDelivery.
public void showClientMyNextDelivery(ActionRequest request, ActionResponse response) {
try {
ClientViewService clientViewService = Beans.get(ClientViewService.class);
User clientUser = clientViewService.getClientUser();
if (clientUser.getPartner() == null) {
response.setError(I18n.get(ITranslation.CLIENT_PORTAL_NO_PARTNER));
} else {
Filter filter = clientViewService.getNextDeliveryOfUser(clientUser).get(0);
if (filter != null) {
StockMove stockMove = Beans.get(StockMoveRepository.class).all().filter(filter.getQuery()).fetchOne();
if (stockMove != null) {
response.setView(ActionView.define(I18n.get("Next delivery")).model(StockMove.class.getName()).add("form", "stock-move-form").context("_showRecord", stockMove.getId()).map());
}
}
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class SaleOrderServiceSupplychainImpl method enableEditOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public boolean enableEditOrder(SaleOrder saleOrder) throws AxelorException {
boolean checkAvailabiltyRequest = super.enableEditOrder(saleOrder);
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return checkAvailabiltyRequest;
}
List<StockMove> allStockMoves = Beans.get(StockMoveRepository.class).findAllBySaleOrderAndStatus(StockMoveRepository.ORIGIN_SALE_ORDER, saleOrder.getId(), StockMoveRepository.STATUS_PLANNED).fetch();
List<StockMove> stockMoves = !allStockMoves.isEmpty() ? allStockMoves.stream().filter(stockMove -> !stockMove.getAvailabilityRequest()).collect(Collectors.toList()) : allStockMoves;
checkAvailabiltyRequest = stockMoves.size() != allStockMoves.size() ? true : checkAvailabiltyRequest;
if (!stockMoves.isEmpty()) {
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
CancelReason cancelReason = appSupplychain.getCancelReasonOnChangingSaleOrder();
if (cancelReason == null) {
throw new AxelorException(appSupplychain, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, IExceptionMessage.SUPPLYCHAIN_MISSING_CANCEL_REASON_ON_CHANGING_SALE_ORDER);
}
for (StockMove stockMove : stockMoves) {
stockMoveService.cancel(stockMove, cancelReason);
stockMove.setArchived(true);
for (StockMoveLine stockMoveline : stockMove.getStockMoveLineList()) {
stockMoveline.setSaleOrderLine(null);
stockMoveline.setArchived(true);
}
}
}
return checkAvailabiltyRequest;
}
Aggregations