Search in sources :

Example 46 with AxelorException

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

the class DebtRecoveryActionService method runMessage.

/**
 * Generate a message from a debtRecovery, save, and send it.
 *
 * @param debtRecovery
 * @throws AxelorException
 * @throws ClassNotFoundException
 * @throws IOException
 * @throws InstantiationException
 * @throws IllegalAccessException
 */
@Transactional(rollbackOn = { Exception.class })
public void runMessage(DebtRecovery debtRecovery) throws AxelorException, ClassNotFoundException, IOException, InstantiationException, IllegalAccessException, JSONException {
    Set<Message> messageSet = this.runStandardMessage(debtRecovery);
    for (Message message : messageSet) {
        message = Beans.get(MessageRepository.class).save(message);
        if (!debtRecovery.getDebtRecoveryMethodLine().getManualValidationOk() && message.getMailAccount() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.DEBT_RECOVERY_ACTION_4));
        }
        if (CollectionUtils.isEmpty(message.getToEmailAddressSet())) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.DEBT_RECOVERY_ACTION_5), debtRecovery.getDebtRecoveryMethodLine().getDebtRecoveryLevelLabel());
        }
        Beans.get(MessageService.class).sendMessage(message);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) MessageService(com.axelor.apps.message.service.MessageService) Transactional(com.google.inject.persist.Transactional)

Example 47 with AxelorException

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

the class AccountingBatchService method run.

@Override
public Batch run(Model batchModel) throws AxelorException {
    Batch batch;
    AccountingBatch accountingBatch = (AccountingBatch) batchModel;
    switch(accountingBatch.getActionSelect()) {
        case AccountingBatchRepository.ACTION_REIMBURSEMENT:
            if (accountingBatch.getReimbursementTypeSelect() == AccountingBatchRepository.REIMBURSEMENT_TYPE_EXPORT) {
                batch = reimbursementExport(accountingBatch);
            } else if (accountingBatch.getReimbursementTypeSelect() == AccountingBatchRepository.REIMBURSEMENT_TYPE_IMPORT) {
                batch = reimbursementImport(accountingBatch);
            }
            batch = null;
            break;
        case AccountingBatchRepository.ACTION_DEBT_RECOVERY:
            batch = debtRecovery(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_DOUBTFUL_CUSTOMER:
            batch = doubtfulCustomer(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_ACCOUNT_CUSTOMER:
            batch = accountCustomer(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_MOVE_LINE_EXPORT:
            batch = moveLineExport(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_CREDIT_TRANSFER:
            batch = creditTransfer(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_REALIZE_FIXED_ASSET_LINES:
            batch = realizeFixedAssetLines(accountingBatch);
            break;
        default:
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BASE_BATCH_1), accountingBatch.getActionSelect(), accountingBatch.getCode());
    }
    return batch;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Batch(com.axelor.apps.base.db.Batch) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) AccountingBatch(com.axelor.apps.account.db.AccountingBatch)

Example 48 with AxelorException

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

the class BatchCloseAnnualAccounts method process.

protected void process() {
    if (!end) {
        AccountingBatch accountingBatch = batch.getAccountingBatch();
        boolean allocatePerPartner = accountingBatch.getAllocatePerPartner();
        boolean closeYear = accountingBatch.getCloseYear();
        boolean openYear = accountingBatch.getOpenYear();
        Year year = accountingBatch.getYear();
        LocalDate endOfYearDate = year.getToDate();
        LocalDate reportedBalanceDate = year.getReportedBalanceDate();
        String origin = accountingBatch.getCode();
        String moveDescription = accountingBatch.getMoveDescription();
        List<Long> accountIdList = accountingCloseAnnualService.getAllAccountOfYear(accountingBatch.getAccountSet(), year);
        List<Pair<Long, Long>> accountAndPartnerPairList = accountingCloseAnnualService.assignPartner(accountIdList, year, allocatePerPartner);
        Account account = null;
        Partner partner = null;
        for (Pair<Long, Long> accountAndPartnerPair : accountAndPartnerPairList) {
            try {
                account = accountRepository.find(accountAndPartnerPair.getLeft());
                if (accountAndPartnerPair.getRight() != null) {
                    partner = partnerRepository.find(accountAndPartnerPair.getRight());
                } else {
                    partner = null;
                }
                List<Move> generateMoves = accountingCloseAnnualService.generateCloseAnnualAccount(yearRepository.find(year.getId()), account, partner, endOfYearDate, reportedBalanceDate, origin, moveDescription, closeYear, openYear, allocatePerPartner);
                if (generateMoves != null && !generateMoves.isEmpty()) {
                    updateAccount(account);
                    for (Move move : generateMoves) {
                        updateAccountMove(move, false);
                    }
                }
            } catch (AxelorException e) {
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Account") + " %s", account.getCode()), null, batch.getId());
                incrementAnomaly();
                break;
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get("Account") + " %s", account.getCode()), e), null, batch.getId());
                incrementAnomaly();
                LOG.error("Anomaly generated for the account {}", account.getCode());
                break;
            } finally {
                JPA.clear();
            }
        }
    }
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) Year(com.axelor.apps.base.db.Year) Move(com.axelor.apps.account.db.Move) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) Partner(com.axelor.apps.base.db.Partner) Pair(org.apache.commons.lang3.tuple.Pair)

Example 49 with AxelorException

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

the class FixedAssetServiceImpl method createFixedAssets.

@Override
@Transactional(rollbackOn = { Exception.class })
public List<FixedAsset> createFixedAssets(Invoice invoice) throws AxelorException {
    List<FixedAsset> fixedAssetList = new ArrayList<>();
    if (invoice == null || CollectionUtils.isEmpty(invoice.getInvoiceLineList())) {
        return fixedAssetList;
    }
    AccountConfig accountConfig = accountConfigService.getAccountConfig(invoice.getCompany());
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        if (accountConfig.getFixedAssetCatReqOnInvoice() && invoiceLine.getFixedAssets() && invoiceLine.getFixedAssetCategory() == null) {
            throw new AxelorException(invoiceLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_LINE_ERROR_FIXED_ASSET_CATEGORY), invoiceLine.getProductName());
        }
        if (!invoiceLine.getFixedAssets() || invoiceLine.getFixedAssetCategory() == null) {
            continue;
        }
        FixedAsset fixedAsset = new FixedAsset();
        fixedAsset.setFixedAssetCategory(invoiceLine.getFixedAssetCategory());
        if (fixedAsset.getFixedAssetCategory().getIsValidateFixedAsset()) {
            fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_VALIDATED);
        } else {
            fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_DRAFT);
        }
        fixedAsset.setAcquisitionDate(invoice.getInvoiceDate());
        fixedAsset.setFirstDepreciationDate(invoice.getInvoiceDate());
        fixedAsset.setReference(invoice.getInvoiceId());
        fixedAsset.setName(invoiceLine.getProductName() + " (" + invoiceLine.getQty() + ")");
        fixedAsset.setCompany(fixedAsset.getFixedAssetCategory().getCompany());
        fixedAsset.setJournal(fixedAsset.getFixedAssetCategory().getJournal());
        fixedAsset.setComputationMethodSelect(fixedAsset.getFixedAssetCategory().getComputationMethodSelect());
        fixedAsset.setDegressiveCoef(fixedAsset.getFixedAssetCategory().getDegressiveCoef());
        fixedAsset.setNumberOfDepreciation(fixedAsset.getFixedAssetCategory().getNumberOfDepreciation());
        fixedAsset.setPeriodicityInMonth(fixedAsset.getFixedAssetCategory().getPeriodicityInMonth());
        fixedAsset.setDurationInMonth(fixedAsset.getFixedAssetCategory().getDurationInMonth());
        fixedAsset.setGrossValue(invoiceLine.getCompanyExTaxTotal());
        fixedAsset.setPartner(invoice.getPartner());
        fixedAsset.setPurchaseAccount(invoiceLine.getAccount());
        fixedAsset.setInvoiceLine(invoiceLine);
        this.generateAndComputeLines(fixedAsset);
        fixedAssetList.add(fixedAssetRepo.save(fixedAsset));
    }
    return fixedAssetList;
}
Also used : AxelorException(com.axelor.exception.AxelorException) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) FixedAsset(com.axelor.apps.account.db.FixedAsset) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 50 with AxelorException

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

the class ICalendarService method getCalendar.

public net.fortuna.ical4j.model.Calendar getCalendar(String uid, ICalendar calendar) throws ICalendarException, MalformedURLException {
    net.fortuna.ical4j.model.Calendar cal = null;
    PathResolver RESOLVER = getPathResolver(calendar.getTypeSelect());
    Protocol protocol = getProtocol(calendar.getIsSslConnection());
    URL url = new URL(protocol.getScheme(), calendar.getUrl(), calendar.getPort(), "");
    ICalendarStore store = new ICalendarStore(url, RESOLVER);
    try {
        if (store.connect(calendar.getLogin(), calendar.getPassword())) {
            List<CalDavCalendarCollection> colList = store.getCollections();
            if (!colList.isEmpty()) {
                CalDavCalendarCollection collection = colList.get(0);
                cal = collection.getCalendar(uid);
            }
        } else {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CALENDAR_NOT_VALID));
        }
    } catch (Exception e) {
        throw new ICalendarException(e);
    } finally {
        store.disconnect();
    }
    return cal;
}
Also used : AxelorException(com.axelor.exception.AxelorException) PathResolver(net.fortuna.ical4j.connector.dav.PathResolver) Protocol(org.apache.commons.httpclient.protocol.Protocol) Calendar(net.fortuna.ical4j.model.Calendar) CalDavCalendarCollection(net.fortuna.ical4j.connector.dav.CalDavCalendarCollection) URL(java.net.URL) FailedOperationException(net.fortuna.ical4j.connector.FailedOperationException) URISyntaxException(java.net.URISyntaxException) ObjectStoreException(net.fortuna.ical4j.connector.ObjectStoreException) ParseException(java.text.ParseException) ParserException(net.fortuna.ical4j.data.ParserException) ValidationException(net.fortuna.ical4j.validate.ValidationException) SocketException(java.net.SocketException) AxelorException(com.axelor.exception.AxelorException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DavException(org.apache.jackrabbit.webdav.DavException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConstraintViolationException(net.fortuna.ical4j.model.ConstraintViolationException)

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