Search in sources :

Example 1 with StockMoveRepository

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()));
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 2 with StockMoveRepository

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);
    }
}
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)

Example 3 with StockMoveRepository

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());
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) RefundInvoice(com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice) Invoice(com.axelor.apps.account.db.Invoice) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ArrayList(java.util.ArrayList) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) AxelorException(com.axelor.exception.AxelorException)

Aggregations

StockMove (com.axelor.apps.stock.db.StockMove)3 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)3 Invoice (com.axelor.apps.account.db.Invoice)2 SaleOrder (com.axelor.apps.sale.db.SaleOrder)2 AxelorException (com.axelor.exception.AxelorException)2 ArrayList (java.util.ArrayList)2 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)1 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)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 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