Search in sources :

Example 1 with SaleOrderStockService

use of com.axelor.apps.supplychain.service.SaleOrderStockService 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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) SaleOrderServiceSupplychainImpl(com.axelor.apps.supplychain.service.SaleOrderServiceSupplychainImpl) Mapper(com.axelor.db.mapper.Mapper) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) ActionResponse(com.axelor.rpc.ActionResponse) BlockingService(com.axelor.apps.base.service.BlockingService) Map(java.util.Map) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockLocationService(com.axelor.apps.stock.service.StockLocationService) PartnerSupplychainLinkTypeRepository(com.axelor.apps.supplychain.db.repo.PartnerSupplychainLinkTypeRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) SaleOrderStockService(com.axelor.apps.supplychain.service.SaleOrderStockService) Currency(com.axelor.apps.base.db.Currency) BlockingRepository(com.axelor.apps.base.db.repo.BlockingRepository) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrderPurchaseService(com.axelor.apps.supplychain.service.SaleOrderPurchaseService) LocalDate(java.time.LocalDate) PriceList(com.axelor.apps.base.db.PriceList) Optional(java.util.Optional) SaleOrderInvoiceService(com.axelor.apps.supplychain.service.SaleOrderInvoiceService) Partner(com.axelor.apps.base.db.Partner) Joiner(com.google.common.base.Joiner) Singleton(com.google.inject.Singleton) Company(com.axelor.apps.base.db.Company) ActionView(com.axelor.meta.schema.actions.ActionView) TemporalUnit(java.time.temporal.TemporalUnit) HashMap(java.util.HashMap) SaleOrderCreateServiceSupplychainImpl(com.axelor.apps.supplychain.service.SaleOrderCreateServiceSupplychainImpl) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) SaleOrderReservedQtyService(com.axelor.apps.supplychain.service.SaleOrderReservedQtyService) I18n(com.axelor.i18n.I18n) Wizard(com.axelor.apps.base.db.Wizard) PartnerSupplychainLinkService(com.axelor.apps.supplychain.service.PartnerSupplychainLinkService) ActionRequest(com.axelor.rpc.ActionRequest) ResponseMessageType(com.axelor.exception.ResponseMessageType) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) SaleOrderLineServiceSupplyChain(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChain) JPA(com.axelor.db.JPA) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) TraceBackService(com.axelor.exception.service.TraceBackService) Invoice(com.axelor.apps.account.db.Invoice) Team(com.axelor.team.db.Team) ChronoUnit(java.time.temporal.ChronoUnit) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) SaleOrderSupplychainService(com.axelor.apps.supplychain.service.SaleOrderSupplychainService) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Context(com.axelor.rpc.Context) TraceBackService(com.axelor.exception.service.TraceBackService) StockMove(com.axelor.apps.stock.db.StockMove) Optional(java.util.Optional) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderStockService(com.axelor.apps.supplychain.service.SaleOrderStockService) AxelorException(com.axelor.exception.AxelorException)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)1 Company (com.axelor.apps.base.db.Company)1 Currency (com.axelor.apps.base.db.Currency)1 Partner (com.axelor.apps.base.db.Partner)1 PriceList (com.axelor.apps.base.db.PriceList)1 Wizard (com.axelor.apps.base.db.Wizard)1 BlockingRepository (com.axelor.apps.base.db.repo.BlockingRepository)1 BlockingService (com.axelor.apps.base.service.BlockingService)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1 SaleOrder (com.axelor.apps.sale.db.SaleOrder)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 SaleOrderLineRepository (com.axelor.apps.sale.db.repo.SaleOrderLineRepository)1 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 StockMove (com.axelor.apps.stock.db.StockMove)1 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)1 StockLocationService (com.axelor.apps.stock.service.StockLocationService)1 PartnerSupplychainLinkTypeRepository (com.axelor.apps.supplychain.db.repo.PartnerSupplychainLinkTypeRepository)1 IExceptionMessage (com.axelor.apps.supplychain.exception.IExceptionMessage)1