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