Search in sources :

Example 86 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class GenerateMessageController method templateDomain.

public void templateDomain(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    String model = (String) context.get("_templateContextModel");
    Object languageObj = context.get("language");
    Language language;
    if (languageObj == null) {
        language = null;
    } else if (languageObj instanceof Map) {
        Map<String, Object> languageMap = (Map<String, Object>) languageObj;
        language = Beans.get(LanguageRepository.class).find(Long.parseLong(languageMap.get("id").toString()));
    } else if (languageObj instanceof Language) {
        language = (Language) languageObj;
    } else {
        throw new IllegalArgumentException("erreur...");
    }
    String domain;
    if (language == null) {
        domain = "self.metaModel.fullName = '" + model + "' and self.isSystem != true";
    } else {
        domain = "self.metaModel.fullName = '" + model + "' and self.isSystem != true and self.language.id = " + language.getId();
    }
    response.setAttr("_xTemplate", "domain", domain);
}
Also used : Context(com.axelor.rpc.Context) LanguageRepository(com.axelor.apps.base.db.repo.LanguageRepository) Language(com.axelor.apps.base.db.Language) Map(java.util.Map)

Example 87 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class PartnerController method addContactToPartner.

public void addContactToPartner(ActionRequest request, ActionResponse response) {
    try {
        final Context context = request.getContext();
        final Partner contact = context.asType(Partner.class);
        final Context parentContext = context.getParent();
        if (parentContext != null && Partner.class.isAssignableFrom(parentContext.getContextClass()) && Objects.equals(parentContext.asType(Partner.class), contact.getMainPartner())) {
            return;
        }
        Beans.get(PartnerService.class).addContactToPartner(Beans.get(PartnerRepository.class).find(contact.getId()));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) BirtException(org.eclipse.birt.core.exception.BirtException) IbanFormatException(org.iban4j.IbanFormatException) InvalidCheckDigitException(org.iban4j.InvalidCheckDigitException) AxelorException(com.axelor.exception.AxelorException) UnsupportedCountryException(org.iban4j.UnsupportedCountryException) IOException(java.io.IOException)

Example 88 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class ProjectPlanningTimeController method addMultipleProjectPlanningTime.

public void addMultipleProjectPlanningTime(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    Beans.get(ProjectPlanningTimeService.class).addMultipleProjectPlanningTime(context);
    response.setCanClose(true);
}
Also used : Context(com.axelor.rpc.Context) ProjectPlanningTimeService(com.axelor.apps.hr.service.project.ProjectPlanningTimeService)

Example 89 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class TimesheetController method generateLines.

@SuppressWarnings("unchecked")
public void generateLines(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Timesheet timesheet = request.getContext().asType(Timesheet.class);
        Context context = request.getContext();
        LocalDate fromGenerationDate = null;
        if (context.get("fromGenerationDate") != null)
            fromGenerationDate = LocalDate.parse(context.get("fromGenerationDate").toString(), DateTimeFormatter.ISO_DATE);
        LocalDate toGenerationDate = null;
        if (context.get("toGenerationDate") != null)
            toGenerationDate = LocalDate.parse(context.get("toGenerationDate").toString(), DateTimeFormatter.ISO_DATE);
        BigDecimal logTime = BigDecimal.ZERO;
        if (context.get("logTime") != null)
            logTime = new BigDecimal(context.get("logTime").toString());
        Map<String, Object> projectContext = (Map<String, Object>) context.get("project");
        Project project = null;
        if (projectContext != null) {
            project = Beans.get(ProjectRepository.class).find(((Integer) projectContext.get("id")).longValue());
        }
        Map<String, Object> productContext = (Map<String, Object>) context.get("product");
        Product product = null;
        if (productContext != null) {
            product = Beans.get(ProductRepository.class).find(((Integer) productContext.get("id")).longValue());
        }
        if (context.get("showActivity") == null || !(Boolean) context.get("showActivity")) {
            product = Beans.get(UserHrService.class).getTimesheetProduct(timesheet.getUser());
        }
        timesheet = Beans.get(TimesheetService.class).generateLines(timesheet, fromGenerationDate, toGenerationDate, logTime, project, product);
        response.setValue("timesheetLineList", timesheet.getTimesheetLineList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) Timesheet(com.axelor.apps.hr.db.Timesheet) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Project(com.axelor.apps.project.db.Project) Map(java.util.Map)

Example 90 with Context

use of com.axelor.rpc.Context in project axelor-open-suite by axelor.

the class MoveLineController method computeCurrentRate.

public void computeCurrentRate(ActionRequest request, ActionResponse response) {
    try {
        Context parentContext = request.getContext().getParent();
        BigDecimal currencyRate = BigDecimal.ONE;
        if (parentContext != null && Move.class.equals(parentContext.getContextClass())) {
            Move move = parentContext.asType(Move.class);
            Currency currency = move.getCurrency();
            Currency companyCurrency = move.getCompanyCurrency();
            if (currency != null && companyCurrency != null && !currency.equals(companyCurrency)) {
                currencyRate = Beans.get(CurrencyService.class).getCurrencyConversionRate(currency, companyCurrency);
            }
        }
        response.setValue("currencyRate", currencyRate);
    } catch (AxelorException e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) Move(com.axelor.apps.account.db.Move) Currency(com.axelor.apps.base.db.Currency) BigDecimal(java.math.BigDecimal)

Aggregations

Context (com.axelor.rpc.Context)149 AxelorException (com.axelor.exception.AxelorException)52 BigDecimal (java.math.BigDecimal)37 Map (java.util.Map)37 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)23 SaleOrder (com.axelor.apps.sale.db.SaleOrder)19 List (java.util.List)18 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)17 Invoice (com.axelor.apps.account.db.Invoice)16 LinkedHashMap (java.util.LinkedHashMap)15 Product (com.axelor.apps.base.db.Product)14 Model (com.axelor.db.Model)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)12 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)11 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)11 LocalDate (java.time.LocalDate)11 Beans (com.axelor.inject.Beans)10 ActionRequest (com.axelor.rpc.ActionRequest)10