Search in sources :

Example 56 with AxelorException

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

the class MapService method getJSON.

private JSONObject getJSON(Response response) throws AxelorException, JSONException {
    LOG.debug("Gmap connection status code: {}, message: {}", response.getStatusCode(), response.getStatusMessage());
    AppBase appBase = appBaseService.getAppBase();
    if (response.getStatusCode() != HttpStatus.SC_OK) {
        String msg = String.format("%d: %s", response.getStatusCode(), response.getStatusMessage());
        throw new AxelorException(appBase, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, msg);
    }
    JSONObject json = new JSONObject(response.getContentAsString());
    String status = json.getString("status");
    if (!"OK".equalsIgnoreCase(status)) {
        String msg = json.has("error_message") ? String.format("%s: %s", status, json.getString("error_message")) : status;
        throw new AxelorException(appBase, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, msg);
    }
    return json;
}
Also used : AxelorException(com.axelor.exception.AxelorException) JSONObject(wslite.json.JSONObject) AppBase(com.axelor.apps.base.db.AppBase)

Example 57 with AxelorException

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

the class PartnerPriceListServiceImpl method checkDates.

@Override
public void checkDates(PartnerPriceList partnerPriceList) throws AxelorException {
    Set<PriceList> priceListSet = partnerPriceList.getPriceListSet();
    if (priceListSet == null) {
        return;
    }
    Set<PriceList> sortedPriceListSet = priceListSet.stream().sorted(Comparator.comparing(priceList -> priceList.getApplicationBeginDate() != null ? priceList.getApplicationBeginDate() : LocalDate.MIN)).collect(Collectors.toSet());
    LocalDate beginDate;
    LocalDate previousEndDate = LocalDate.MIN;
    String previousTitle = "";
    for (PriceList priceList : sortedPriceListSet) {
        beginDate = priceList.getApplicationBeginDate() != null ? priceList.getApplicationBeginDate() : LocalDate.MIN;
        if (beginDate.compareTo(previousEndDate) < 0) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, String.format(I18n.get(IExceptionMessage.PARTNER_PRICE_LIST_DATE_INCONSISTENT), previousTitle.replace("%", "%%"), priceList.getTitle().replace("%", "%%")), partnerPriceList);
        }
        previousEndDate = priceList.getApplicationEndDate() != null ? priceList.getApplicationEndDate() : LocalDate.MAX;
        previousTitle = priceList.getTitle();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) PriceList(com.axelor.apps.base.db.PriceList) PartnerPriceList(com.axelor.apps.base.db.PartnerPriceList) LocalDate(java.time.LocalDate)

Example 58 with AxelorException

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

the class ExpenseController method fillKilometricExpenseProduct.

public void fillKilometricExpenseProduct(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Expense expense = request.getContext().getParent().asType(Expense.class);
        Product expenseProduct = Beans.get(ExpenseService.class).getKilometricExpenseProduct(expense);
        logger.debug("Get Kilometric expense product : {}", expenseProduct);
        response.setValue("expenseProduct", expenseProduct);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Expense(com.axelor.apps.hr.db.Expense) Product(com.axelor.apps.base.db.Product) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Example 59 with AxelorException

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

the class ExpenseController method cancel.

public void cancel(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Expense expense = request.getContext().asType(Expense.class);
        expense = Beans.get(ExpenseRepository.class).find(expense.getId());
        ExpenseService expenseService = Beans.get(ExpenseService.class);
        expenseService.cancel(expense);
        Message message = expenseService.sendCancellationEmail(expense);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) Expense(com.axelor.apps.hr.db.Expense) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Example 60 with AxelorException

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

the class ExpenseController method validateAndCompute.

public void validateAndCompute(ActionRequest request, ActionResponse response) {
    Expense expense = request.getContext().asType(Expense.class);
    ExpenseService expenseService = Beans.get(ExpenseService.class);
    List<Integer> expenseLineListId = new ArrayList<>();
    int compt = 0;
    for (ExpenseLine expenseLine : expenseService.getExpenseLineList(expense)) {
        compt++;
        if (expenseLine.getExpenseDate().isAfter(Beans.get(AppBaseService.class).getTodayDate(expense.getCompany()))) {
            expenseLineListId.add(compt);
        }
    }
    try {
        if (!expenseLineListId.isEmpty()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get("Date can't be in the future for line(s) : %s"), expenseLineListId.stream().map(id -> id.toString()).collect(Collectors.joining(",")));
        }
    } catch (AxelorException e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
    response.setValue("personalExpenseAmount", expenseService.computePersonalExpenseAmount(expense));
    response.setValue("advanceAmount", expenseService.computeAdvanceAmount(expense));
    if (expense.getKilometricExpenseLineList() != null && !expense.getKilometricExpenseLineList().isEmpty()) {
        response.setValue("kilometricExpenseLineList", expense.getKilometricExpenseLineList());
    }
    compute(request, response);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Expense(com.axelor.apps.hr.db.Expense) ArrayList(java.util.ArrayList) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine)

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