Search in sources :

Example 41 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class InvoiceLineGenerator method computeCompanyTotal.

public void computeCompanyTotal(InvoiceLine invoiceLine) throws AxelorException {
    if (typeSelect == InvoiceLineRepository.TYPE_TITLE) {
        return;
    }
    Company company = invoice.getCompany();
    Currency companyCurrency = company.getCurrency();
    if (companyCurrency == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICE_LINE_GENERATOR_2), company.getName());
    }
    invoiceLine.setCompanyExTaxTotal(currencyService.getAmountCurrencyConvertedAtDate(invoice.getCurrency(), companyCurrency, exTaxTotal, today).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP));
    invoiceLine.setCompanyInTaxTotal(currencyService.getAmountCurrencyConvertedAtDate(invoice.getCurrency(), companyCurrency, inTaxTotal, today).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP));
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Currency(com.axelor.apps.base.db.Currency)

Example 42 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class InvoiceServiceImpl method getBankDetails.

@Override
public BankDetails getBankDetails(Invoice invoice) throws AxelorException {
    BankDetails bankDetails;
    if (invoice.getSchedulePaymentOk() && invoice.getPaymentSchedule() != null) {
        bankDetails = invoice.getPaymentSchedule().getBankDetails();
        if (bankDetails != null) {
            return bankDetails;
        }
    }
    bankDetails = invoice.getBankDetails();
    if (bankDetails != null) {
        return bankDetails;
    }
    Partner partner = invoice.getPartner();
    Preconditions.checkNotNull(partner);
    bankDetails = Beans.get(BankDetailsRepository.class).findDefaultByPartner(partner);
    if (bankDetails != null) {
        return bankDetails;
    }
    throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.PARTNER_BANK_DETAILS_MISSING), partner.getName());
}
Also used : AxelorException(com.axelor.exception.AxelorException) BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner)

Example 43 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class BatchDoubtfulCustomer method createDoubtFulCustomerRejectMove.

/**
 * Procédure permettant de créer les écritures de passage en client douteux pour chaque ligne
 * d'écriture de rejet de facture
 *
 * @param moveLineList Une liste de lignes d'écritures de rejet de facture
 * @param doubtfulCustomerAccount Un compte client douteux
 * @param debtPassReason Un motif de passage en client douteux
 * @throws AxelorException
 */
public void createDoubtFulCustomerRejectMove(List<MoveLine> moveLineList, Account doubtfulCustomerAccount, String debtPassReason) {
    int i = 0;
    for (MoveLine moveLine : moveLineList) {
        try {
            doubtfulCustomerService.createDoubtFulCustomerRejectMove(moveLineRepo.find(moveLine.getId()), accountRepo.find(doubtfulCustomerAccount.getId()), debtPassReason);
            updateInvoice(moveLineRepo.find(moveLine.getId()).getInvoiceReject());
            i++;
        } catch (AxelorException e) {
            TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Invoice") + " %s", moveLine.getInvoiceReject().getInvoiceId()), ExceptionOriginRepository.DOUBTFUL_CUSTOMER, batch.getId());
            incrementAnomaly();
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get("Invoice") + " %s", moveLine.getInvoiceReject().getInvoiceId()), e), ExceptionOriginRepository.DOUBTFUL_CUSTOMER, batch.getId());
            incrementAnomaly();
            log.error("Bug(Anomalie) généré(e) pour la facture {}", moveLineRepo.find(moveLine.getId()).getInvoiceReject().getInvoiceId());
        } finally {
            if (i % 10 == 0) {
                JPA.clear();
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) AxelorException(com.axelor.exception.AxelorException)

Example 44 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class BatchReimbursementExport method runReimbursementExportProcess.

public void runReimbursementExportProcess(Company company) {
    int i = 0;
    // On récupère les remboursements dont les trop perçu ont été annulés
    List<Reimbursement> reimbursementToCancelList = reimbursementRepo.all().filter("self.company = ?1 and self.statusSelect = ?2 and self.amountToReimburse = 0", ReimbursementRepository.STATUS_VALIDATED, company).fetch();
    // On annule les remboursements
    for (Reimbursement reimbursement : reimbursementToCancelList) {
        reimbursement.setStatusSelect(ReimbursementRepository.STATUS_CANCELED);
    }
    // On récupère les remboursement à rembourser
    List<Reimbursement> reimbursementList = reimbursementRepo.all().filter("self.company = ?1 and self.statusSelect = ?2 and self.amountToReimburse > 0 AND self.partner", company, ReimbursementRepository.STATUS_VALIDATED).fetch();
    List<Reimbursement> reimbursementToExport = new ArrayList<>();
    for (Reimbursement reimbursement : reimbursementList) {
        try {
            reimbursement = reimbursementRepo.find(reimbursement.getId());
            if (reimbursementExportService.canBeReimbursed(reimbursement.getPartner(), reimbursement.getCompany())) {
                reimbursementExportService.reimburse(reimbursement, company);
                updateReimbursement(reimbursementRepo.find(reimbursement.getId()));
                reimbursementToExport.add(reimbursement);
                this.totalAmount = this.totalAmount.add(reimbursementRepo.find(reimbursement.getId()).getAmountReimbursed());
                i++;
            }
        } catch (AxelorException e) {
            TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Reimbursement") + " %s", reimbursementRepo.find(reimbursement.getId()).getRef()), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
            incrementAnomaly();
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get("Reimbursement") + " %s", reimbursementRepo.find(reimbursement.getId()).getRef()), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
            incrementAnomaly();
            log.error("Bug(Anomalie) généré(e) pour l'export du remboursement {}", reimbursementRepo.find(reimbursement.getId()).getRef());
        } finally {
            if (i % 10 == 0) {
                JPA.clear();
            }
        }
    }
    if (reimbursementToExport != null && !reimbursementToExport.isEmpty()) {
        try {
            cfonbExportService.exportCFONB(companyRepo.find(company.getId()), batchRepo.find(batch.getId()).getStartDate(), reimbursementToExport, batchRepo.find(batch.getId()).getAccountingBatch().getBankDetails());
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_1), batch.getId()), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
            incrementAnomaly();
            log.error("Bug(Anomalie) généré(e)e dans l'export CFONB - Batch {}", batch.getId());
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) Reimbursement(com.axelor.apps.account.db.Reimbursement) AxelorException(com.axelor.exception.AxelorException)

Example 45 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class BatchReimbursementImport method validateMove.

public void validateMove(Move move, LocalDate rejectDate, int seq) {
    try {
        if (seq != 1) {
            MoveLine oppositeMoveLine = reimbursementImportService.createOppositeRejectMoveLine(moveRepo.find(move.getId()), seq, rejectDate);
            reimbursementImportService.validateMove(moveRepo.find(move.getId()));
            this.totalAmount = this.totalAmount.add(moveLineRepo.find(oppositeMoveLine.getId()).getDebit());
        } else {
            reimbursementImportService.deleteMove(moveRepo.find(move.getId()));
        }
    } catch (AxelorException e) {
        TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_6), batch.getId()), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
        incrementAnomaly();
    } catch (Exception e) {
        TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_6), batch.getId()), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
        incrementAnomaly();
        log.error("Bug(Anomalie) généré(e) pour le batch d'import des remboursements {}", batch.getId());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) AxelorException(com.axelor.exception.AxelorException)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27