Search in sources :

Example 6 with SupplychainBatch

use of com.axelor.apps.supplychain.db.SupplychainBatch in project axelor-open-suite by axelor.

the class SupplychainBatchController method invoiceOrders.

public void invoiceOrders(ActionRequest request, ActionResponse response) {
    try {
        SupplychainBatch supplychainBatch = request.getContext().asType(SupplychainBatch.class);
        supplychainBatch = Beans.get(SupplychainBatchRepository.class).find(supplychainBatch.getId());
        Batch batch = Beans.get(SupplychainBatchService.class).invoiceOrders(supplychainBatch);
        response.setFlash(batch.getComments());
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Batch(com.axelor.apps.base.db.Batch) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) SupplychainBatchService(com.axelor.apps.supplychain.service.batch.SupplychainBatchService)

Example 7 with SupplychainBatch

use of com.axelor.apps.supplychain.db.SupplychainBatch in project axelor-open-suite by axelor.

the class SupplychainBatchController method invoiceOutgoingStockMoves.

public void invoiceOutgoingStockMoves(ActionRequest request, ActionResponse response) {
    try {
        SupplychainBatch supplychainBatch = request.getContext().asType(SupplychainBatch.class);
        supplychainBatch = Beans.get(SupplychainBatchRepository.class).find(supplychainBatch.getId());
        Batch batch = Beans.get(SupplychainBatchService.class).invoiceOutgoingStockMoves(supplychainBatch);
        response.setFlash(batch.getComments());
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Batch(com.axelor.apps.base.db.Batch) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) SupplychainBatchService(com.axelor.apps.supplychain.service.batch.SupplychainBatchService)

Example 8 with SupplychainBatch

use of com.axelor.apps.supplychain.db.SupplychainBatch in project axelor-open-suite by axelor.

the class BatchOrderInvoicingPurchase method process.

@Override
protected void process() {
    SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
    List<String> filterList = new ArrayList<>();
    Query<PurchaseOrder> query = Beans.get(PurchaseOrderRepository.class).all();
    if (supplychainBatch.getCompany() != null) {
        filterList.add("self.company = :company");
        query.bind("company", supplychainBatch.getCompany());
    }
    if (supplychainBatch.getSalespersonOrBuyerSet() != null && !supplychainBatch.getSalespersonOrBuyerSet().isEmpty()) {
        filterList.add("self.buyerUser IN (:buyerSet)");
        query.bind("buyerSet", supplychainBatch.getSalespersonOrBuyerSet());
    }
    if (supplychainBatch.getTeam() != null) {
        filterList.add("self.buyerUser IS NOT NULL AND self.buyerUser.activeTeam = :team");
        query.bind("team", supplychainBatch.getTeam());
    }
    if (!Strings.isNullOrEmpty(supplychainBatch.getDeliveryOrReceiptState())) {
        List<Integer> receiptStateList = StringTool.getIntegerList(supplychainBatch.getDeliveryOrReceiptState());
        filterList.add("self.receiptState IN (:receiptStateList)");
        query.bind("receiptStateList", receiptStateList);
    }
    if (!Strings.isNullOrEmpty(supplychainBatch.getStatusSelect())) {
        List<Integer> statusSelectList = StringTool.getIntegerList(supplychainBatch.getStatusSelect());
        filterList.add("self.statusSelect IN (:statusSelectList)");
        query.bind("statusSelectList", statusSelectList);
    }
    if (supplychainBatch.getOrderUpToDate() != null) {
        filterList.add("self.orderDate <= :orderUpToDate");
        query.bind("orderUpToDate", supplychainBatch.getOrderUpToDate());
    }
    filterList.add("self.amountInvoiced < self.exTaxTotal");
    filterList.add("NOT EXISTS (SELECT 1 FROM Invoice invoice WHERE invoice.statusSelect != :invoiceStatusSelect " + "AND (invoice.purchaseOrder = self " + "OR invoice.purchaseOrder IS NULL AND EXISTS (SELECT 1 FROM invoice.invoiceLineList invoiceLine " + "WHERE invoiceLine.purchaseOrderLine MEMBER OF self.purchaseOrderLineList)))");
    filterList.add("self.supplierPartner.id NOT IN (" + Beans.get(BlockingService.class).listOfBlockedPartner(supplychainBatch.getCompany(), BlockingRepository.INVOICING_BLOCKING) + ")");
    query.bind("invoiceStatusSelect", InvoiceRepository.STATUS_CANCELED);
    List<Long> anomalyList = Lists.newArrayList(0L);
    filterList.add("self.id NOT IN (:anomalyList)");
    query.bind("anomalyList", anomalyList);
    String filter = filterList.stream().map(item -> String.format("(%s)", item)).collect(Collectors.joining(" AND "));
    query.filter(filter);
    PurchaseOrderInvoiceService purchaseOrderInvoiceService = Beans.get(PurchaseOrderInvoiceService.class);
    Set<Long> treatedSet = new HashSet<>();
    for (List<PurchaseOrder> purchaseOrderList; !(purchaseOrderList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
        for (PurchaseOrder purchaseOrder : purchaseOrderList) {
            if (treatedSet.contains(purchaseOrder.getId())) {
                throw new IllegalArgumentException("Invoice generation error");
            }
            treatedSet.add(purchaseOrder.getId());
            try {
                purchaseOrderInvoiceService.generateInvoice(purchaseOrder);
                incrementDone();
            } catch (Exception e) {
                incrementAnomaly();
                anomalyList.add(purchaseOrder.getId());
                query.bind("anomalyList", anomalyList);
                TraceBackService.trace(e, ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                e.printStackTrace();
                break;
            }
        }
    }
}
Also used : Query(com.axelor.db.Query) StringTool(com.axelor.apps.tool.StringTool) JPA(com.axelor.db.JPA) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) TraceBackService(com.axelor.exception.service.TraceBackService) Set(java.util.Set) PurchaseOrderInvoiceService(com.axelor.apps.supplychain.service.PurchaseOrderInvoiceService) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) BlockingRepository(com.axelor.apps.base.db.repo.BlockingRepository) List(java.util.List) Lists(com.google.common.collect.Lists) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) BlockingService(com.axelor.apps.base.service.BlockingService) ExceptionOriginRepository(com.axelor.exception.db.repo.ExceptionOriginRepository) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) ArrayList(java.util.ArrayList) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderInvoiceService(com.axelor.apps.supplychain.service.PurchaseOrderInvoiceService) HashSet(java.util.HashSet)

Example 9 with SupplychainBatch

use of com.axelor.apps.supplychain.db.SupplychainBatch 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

SupplychainBatch (com.axelor.apps.supplychain.db.SupplychainBatch)9 Batch (com.axelor.apps.base.db.Batch)4 BlockingService (com.axelor.apps.base.service.BlockingService)3 SupplychainBatchService (com.axelor.apps.supplychain.service.batch.SupplychainBatchService)3 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)2 BlockingRepository (com.axelor.apps.base.db.repo.BlockingRepository)2 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)2 StockMove (com.axelor.apps.stock.db.StockMove)2 StringTool (com.axelor.apps.tool.StringTool)2 JPA (com.axelor.db.JPA)2 Query (com.axelor.db.Query)2 AxelorException (com.axelor.exception.AxelorException)2 ExceptionOriginRepository (com.axelor.exception.db.repo.ExceptionOriginRepository)2 TraceBackService (com.axelor.exception.service.TraceBackService)2 Beans (com.axelor.inject.Beans)2 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2