use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class InvoiceLineController method computeAnalyticDistribution.
public void computeAnalyticDistribution(ActionRequest request, ActionResponse response) throws AxelorException {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
if (Beans.get(AppAccountService.class).getAppAccount().getManageAnalyticAccounting()) {
response.setValue("analyticMoveLineList", Beans.get(InvoiceLineService.class).computeAnalyticDistribution(invoiceLine));
}
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class InvoiceLineController method getInvoice.
public Invoice getInvoice(Context context) {
Context parentContext = context.getParent();
Invoice invoice;
if (parentContext == null || !parentContext.getContextClass().toString().equals(Invoice.class.toString())) {
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
invoice = invoiceLine.getInvoice();
} else {
invoice = parentContext.asType(Invoice.class);
}
return invoice;
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class MoveController method generateReverse.
public void generateReverse(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
Move move = context.asType(Move.class);
move = Beans.get(MoveRepository.class).find(move.getId());
Map<String, Object> assistantMap = Beans.get(ExtractContextMoveService.class).getMapFromMoveWizardGenerateReverseForm(context);
Move newMove = Beans.get(MoveService.class).generateReverse(move, assistantMap);
if (newMove != null) {
response.setView(ActionView.define(I18n.get("Account move")).model("com.axelor.apps.account.db.Move").add("grid", "move-grid").add("form", "move-form").param("forceEdit", "true").context("_showRecord", newMove.getId().toString()).map());
response.setCanClose(true);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class FixedAssetController method disposal.
public void disposal(ActionRequest request, ActionResponse response) throws AxelorException {
Context context = request.getContext();
if (context.get("disposalDate") == null || context.get("disposalAmount") == null) {
return;
}
LocalDate disposalDate = (LocalDate) context.get("disposalDate");
BigDecimal disposalAmount = new BigDecimal(context.get("disposalAmount").toString());
Long fixedAssetId = Long.valueOf(context.get("_id").toString());
FixedAsset fixedAsset = Beans.get(FixedAssetRepository.class).find(fixedAssetId);
Beans.get(FixedAssetService.class).disposal(disposalDate, disposalAmount, fixedAsset);
response.setCanClose(true);
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class CurrencyConversionLineController method convert.
@SuppressWarnings("unchecked")
public void convert(ActionRequest request, ActionResponse response) throws MalformedURLException, JSONException, AxelorException {
Context context = request.getContext();
Currency fromCurrency = null;
Currency toCurrency = null;
CurrencyRepository currencyRepository = Beans.get(CurrencyRepository.class);
if (context.get("startCurrency") instanceof Currency) {
fromCurrency = (Currency) context.get("startCurrency");
toCurrency = (Currency) context.get("endCurrency");
} else {
Map<String, Object> startCurrency = (Map<String, Object>) context.get("startCurrency");
Map<String, Object> endCurrency = (Map<String, Object>) context.get("endCurrency");
fromCurrency = currencyRepository.find(Long.parseLong(startCurrency.get("id").toString()));
toCurrency = currencyRepository.find(Long.parseLong(endCurrency.get("id").toString()));
}
CurrencyConversionLine prevLine = null;
if (fromCurrency != null && toCurrency != null) {
if (context.get("id") != null)
prevLine = Beans.get(CurrencyConversionLineRepository.class).all().filter("startCurrency.id = ?1 AND endCurrency.id = ?2 AND id != ?3", fromCurrency.getId(), toCurrency.getId(), context.get("id")).order("-fromDate").fetchOne();
else
prevLine = Beans.get(CurrencyConversionLineRepository.class).all().filter("startCurrency.id = ?1 AND endCurrency.id = ?2", fromCurrency.getId(), toCurrency.getId()).order("-fromDate").fetchOne();
LOG.debug("Previous currency conversion line: {}", prevLine);
fromCurrency = currencyRepository.find(fromCurrency.getId());
toCurrency = currencyRepository.find(toCurrency.getId());
try {
CurrencyConversionService currencyConversionService = Beans.get(CurrencyConversionFactory.class).getCurrencyConversionService();
BigDecimal rate = currencyConversionService.convert(fromCurrency, toCurrency);
if (rate.compareTo(new BigDecimal(-1)) == 0)
response.setFlash(I18n.get(IExceptionMessage.CURRENCY_6));
else {
response.setValue("variations", "0");
if (context.get("_model").equals("com.axelor.apps.base.db.Wizard"))
response.setValue("newExchangeRate", rate);
else
response.setValue("exchangeRate", rate);
response.setValue("fromDate", Beans.get(AppBaseService.class).getTodayDateTime());
if (prevLine != null)
response.setValue("variations", currencyConversionService.getVariations(rate, prevLine.getExchangeRate()));
}
} catch (AxelorException axelorException) {
response.setFlash(axelorException.getMessage());
response.setCanClose(true);
}
}
}
Aggregations