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);
}
}
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;
}
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();
}
}
}
}
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;
}
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;
}
Aggregations