Search in sources :

Example 71 with StockMove

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);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) Map(java.util.Map) StockMoveInvoiceService(com.axelor.apps.supplychain.service.StockMoveInvoiceService)

Example 72 with StockMove

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);
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) Filter(com.axelor.rpc.filter.Filter) JPQLFilter(com.axelor.rpc.filter.JPQLFilter)

Example 73 with StockMove

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);
    }
}
Also used : ClientViewService(com.axelor.apps.portal.service.ClientViewService) User(com.axelor.auth.db.User) StockMove(com.axelor.apps.stock.db.StockMove) Filter(com.axelor.rpc.filter.Filter) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository)

Example 74 with StockMove

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);
    }
}
Also used : ClientViewService(com.axelor.apps.portal.service.ClientViewService) User(com.axelor.auth.db.User) StockMove(com.axelor.apps.stock.db.StockMove) Filter(com.axelor.rpc.filter.Filter) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository)

Example 75 with StockMove

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) CancelReason(com.axelor.apps.base.db.CancelReason) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Aggregations

StockMove (com.axelor.apps.stock.db.StockMove)129 AxelorException (com.axelor.exception.AxelorException)57 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)50 ArrayList (java.util.ArrayList)36 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)33 Transactional (com.google.inject.persist.Transactional)32 StockMoveService (com.axelor.apps.stock.service.StockMoveService)31 BigDecimal (java.math.BigDecimal)30 List (java.util.List)25 Company (com.axelor.apps.base.db.Company)23 Map (java.util.Map)21 Product (com.axelor.apps.base.db.Product)19 Invoice (com.axelor.apps.account.db.Invoice)18 StockLocation (com.axelor.apps.stock.db.StockLocation)18 Beans (com.axelor.inject.Beans)17 Optional (java.util.Optional)16 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)15 I18n (com.axelor.i18n.I18n)15 Inject (com.google.inject.Inject)14 HashMap (java.util.HashMap)14