Search in sources :

Example 1 with SupplychainBatch

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

the class SupplychainBatchSupplychainRepository method copy.

@Override
public SupplychainBatch copy(SupplychainBatch entity, boolean deep) {
    SupplychainBatch copy = super.copy(entity, deep);
    copy.setBatchList(null);
    return copy;
}
Also used : SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch)

Example 2 with SupplychainBatch

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

the class BatchOrderInvoicingSale method process.

@Override
protected void process() {
    SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
    List<String> filterList = new ArrayList<>();
    Query<SaleOrder> query = Beans.get(SaleOrderRepository.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.salespersonUser IN (:salespersonSet)");
        query.bind("salespersonSet", supplychainBatch.getSalespersonOrBuyerSet());
    }
    if (supplychainBatch.getTeam() != null) {
        filterList.add("self.team = :team " + "OR self.team IS NULL AND self.salespersonUser IS NOT NULL AND self.salespersonUser.activeTeam = :team");
        query.bind("team", supplychainBatch.getTeam());
    }
    if (!Strings.isNullOrEmpty(supplychainBatch.getDeliveryOrReceiptState())) {
        List<Integer> delivereyStateList = StringTool.getIntegerList(supplychainBatch.getDeliveryOrReceiptState());
        filterList.add("self.deliveryState IN (:delivereyStateList)");
        query.bind("delivereyStateList", delivereyStateList);
    }
    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.saleOrder = self " + "OR invoice.saleOrder IS NULL AND EXISTS (SELECT 1 FROM invoice.invoiceLineList invoiceLine " + "WHERE invoiceLine.saleOrderLine MEMBER OF self.saleOrderLineList)))");
    filterList.add("self.clientPartner.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);
    SaleOrderInvoiceService saleOrderInvoiceService = Beans.get(SaleOrderInvoiceService.class);
    Set<Long> treatedSet = new HashSet<>();
    for (List<SaleOrder> saleOrderList; !(saleOrderList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
        for (SaleOrder saleOrder : saleOrderList) {
            if (treatedSet.contains(saleOrder.getId())) {
                throw new IllegalArgumentException("Invoice generation error");
            }
            treatedSet.add(saleOrder.getId());
            try {
                saleOrderInvoiceService.generateInvoice(saleOrder);
                incrementDone();
            } catch (Exception e) {
                incrementAnomaly();
                anomalyList.add(saleOrder.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) TraceBackService(com.axelor.exception.service.TraceBackService) Set(java.util.Set) 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) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) 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) SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderInvoiceService(com.axelor.apps.supplychain.service.SaleOrderInvoiceService) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) SaleOrderInvoiceService(com.axelor.apps.supplychain.service.SaleOrderInvoiceService) ArrayList(java.util.ArrayList) SaleOrder(com.axelor.apps.sale.db.SaleOrder) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) HashSet(java.util.HashSet)

Example 3 with SupplychainBatch

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

the class SupplychainBatchService method run.

@Override
public Batch run(Model batchModel) throws AxelorException {
    Batch batch;
    SupplychainBatch supplychainBatch = (SupplychainBatch) batchModel;
    switch(supplychainBatch.getActionSelect()) {
        case SupplychainBatchRepository.ACTION_ACCOUNTING_CUT_OFF:
            batch = accountingCutOff(supplychainBatch);
            break;
        case SupplychainBatchRepository.ACTION_INVOICE_OUTGOING_STOCK_MOVES:
            batch = invoiceOutgoingStockMoves(supplychainBatch);
            break;
        case SupplychainBatchRepository.ACTION_INVOICE_ORDERS:
            batch = invoiceOrders(supplychainBatch);
            break;
        default:
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BASE_BATCH_1), supplychainBatch.getActionSelect(), supplychainBatch.getCode());
    }
    return batch;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Batch(com.axelor.apps.base.db.Batch) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch)

Example 4 with SupplychainBatch

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

the class BatchAccountingCutOff method process.

@Override
protected void process() {
    int offset = 0;
    SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
    LocalDate moveDate = supplychainBatch.getMoveDate();
    LocalDate reverseMoveDate = supplychainBatch.getReverseMoveDate();
    boolean recoveredTax = supplychainBatch.getRecoveredTax();
    boolean ati = supplychainBatch.getAti();
    String moveDescription = supplychainBatch.getMoveDescription();
    int accountingCutOffTypeSelect = supplychainBatch.getAccountingCutOffTypeSelect();
    updateBatch(moveDate, accountingCutOffTypeSelect);
    Company company = supplychainBatch.getCompany();
    boolean includeNotStockManagedProduct = supplychainBatch.getIncludeNotStockManagedProduct();
    if (accountingCutOffTypeSelect == 0) {
        return;
    }
    List<StockMove> stockMoveList;
    while (!(stockMoveList = cutOffService.getStockMoves(company, accountingCutOffTypeSelect, moveDate, FETCH_LIMIT, offset)).isEmpty()) {
        findBatch();
        for (StockMove stockMove : stockMoveList) {
            ++offset;
            try {
                List<Move> moveList = cutOffService.generateCutOffMoves(stockMove, moveDate, reverseMoveDate, accountingCutOffTypeSelect, recoveredTax, ati, moveDescription, includeNotStockManagedProduct);
                if (moveList != null && !moveList.isEmpty()) {
                    updateStockMove(stockMove);
                    for (Move move : moveList) {
                        updateAccountMove(move, false);
                    }
                }
            } catch (AxelorException e) {
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("StockMove") + " %s", stockMove.getStockMoveSeq()), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                incrementAnomaly();
                break;
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get("StockMove") + " %s", stockMove.getStockMoveSeq()), e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                incrementAnomaly();
                LOG.error("Anomaly generated for the stock move {}", stockMove.getStockMoveSeq());
                break;
            }
        }
        JPA.clear();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException)

Example 5 with SupplychainBatch

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

the class SupplychainBatchController method accountingCutOff.

public void accountingCutOff(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).accountingCutOff(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)

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