Search in sources :

Example 1 with SaleOrderRepository

use of com.axelor.apps.sale.db.repo.SaleOrderRepository in project axelor-open-suite by axelor.

the class BatchOutgoingStockMoveInvoicing method process.

@Override
protected void process() {
    SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
    List<Long> anomalyList = Lists.newArrayList(0L);
    SaleOrderRepository saleRepo = Beans.get(SaleOrderRepository.class);
    TypedQuery<StockMove> query = JPA.em().createQuery("SELECT self FROM StockMove self " + "WHERE self.statusSelect = :statusSelect " + "AND self.originTypeSelect LIKE :typeSaleOrder " + "AND self.invoicingStatusSelect !=  :invoicingStatusSelect " + "AND (SELECT count(invoice.id) FROM Invoice invoice WHERE invoice.statusSelect != :invoiceStatusCanceled AND invoice MEMBER OF self.invoiceSet) = 0" + "AND self.id NOT IN (:anomalyList) " + "AND self.partner.id NOT IN (" + Beans.get(BlockingService.class).listOfBlockedPartner(supplychainBatch.getCompany(), BlockingRepository.INVOICING_BLOCKING) + ") " + "AND :batch NOT MEMBER OF self.batchSet " + "ORDER BY self.id", StockMove.class).setParameter("statusSelect", StockMoveRepository.STATUS_REALIZED).setParameter("typeSaleOrder", StockMoveRepository.ORIGIN_SALE_ORDER).setParameter("invoiceStatusCanceled", InvoiceRepository.STATUS_CANCELED).setParameter("invoicingStatusSelect", StockMoveRepository.STATUS_DELAYED_INVOICE).setParameter("anomalyList", anomalyList).setParameter("batch", batch).setMaxResults(FETCH_LIMIT);
    List<StockMove> stockMoveList;
    while (!(stockMoveList = query.getResultList()).isEmpty()) {
        for (StockMove stockMove : stockMoveList) {
            try {
                stockMoveInvoiceService.createInvoiceFromSaleOrder(stockMove, saleRepo.find(stockMove.getOriginId()), null);
                updateStockMove(stockMove);
            } catch (Exception e) {
                incrementAnomaly();
                anomalyList.add(stockMove.getId());
                query.setParameter("anomalyList", anomalyList);
                TraceBackService.trace(e, ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                break;
            }
        }
        JPA.clear();
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) BlockingService(com.axelor.apps.base.service.BlockingService)

Aggregations

BlockingService (com.axelor.apps.base.service.BlockingService)1 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)1 StockMove (com.axelor.apps.stock.db.StockMove)1 SupplychainBatch (com.axelor.apps.supplychain.db.SupplychainBatch)1