Search in sources :

Example 76 with Context

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));
    }
}
Also used : Context(com.axelor.rpc.Context) InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

Example 77 with Context

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;
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

Example 78 with Context

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);
    }
}
Also used : Context(com.axelor.rpc.Context) MoveService(com.axelor.apps.account.service.move.MoveService) ExtractContextMoveService(com.axelor.apps.account.service.extract.ExtractContextMoveService) Move(com.axelor.apps.account.db.Move) ExtractContextMoveService(com.axelor.apps.account.service.extract.ExtractContextMoveService) AxelorException(com.axelor.exception.AxelorException)

Example 79 with Context

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);
}
Also used : Context(com.axelor.rpc.Context) FixedAssetService(com.axelor.apps.account.service.fixedasset.FixedAssetService) FixedAssetRepository(com.axelor.apps.account.db.repo.FixedAssetRepository) FixedAsset(com.axelor.apps.account.db.FixedAsset) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 80 with Context

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);
        }
    }
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) Currency(com.axelor.apps.base.db.Currency) CurrencyRepository(com.axelor.apps.base.db.repo.CurrencyRepository) CurrencyConversionLine(com.axelor.apps.base.db.CurrencyConversionLine) CurrencyConversionFactory(com.axelor.apps.base.service.currency.CurrencyConversionFactory) CurrencyConversionService(com.axelor.apps.base.service.currency.CurrencyConversionService) Map(java.util.Map) 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