Search in sources :

Example 11 with Context

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

the class SaleOrderLineController method convertUnitPrice.

public void convertUnitPrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    SaleOrder saleOrder = Beans.get(SaleOrderLineService.class).getSaleOrder(context);
    if (saleOrder == null || saleOrderLine.getProduct() == null || saleOrderLine.getPrice() == null || saleOrderLine.getInTaxPrice() == null) {
        return;
    }
    try {
        BigDecimal price = saleOrderLine.getPrice();
        BigDecimal inTaxPrice = price.add(price.multiply(saleOrderLine.getTaxLine().getValue()));
        response.setValue("inTaxPrice", inTaxPrice);
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 12 with Context

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

the class SaleOrderLineController method updateInTaxPrice.

/**
 * Update the in. tax unit price of an invoice line from its ex. tax unit price.
 *
 * @param request
 * @param response
 */
public void updateInTaxPrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    try {
        BigDecimal exTaxPrice = saleOrderLine.getPrice();
        TaxLine taxLine = saleOrderLine.getTaxLine();
        response.setValue("inTaxPrice", Beans.get(SaleOrderLineService.class).convertUnitPrice(false, taxLine, exTaxPrice));
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 13 with Context

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

the class SaleOrderLineController method computeProductDomain.

/**
 * Called from sale order line form view, on product selection. Call {@link
 * SaleOrderLineService#computeProductDomain(SaleOrderLine, SaleOrder)}.
 *
 * @param request
 * @param response
 */
public void computeProductDomain(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
        SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
        SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
        response.setAttr("product", "domain", saleOrderLineService.computeProductDomain(saleOrderLine, saleOrder));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AxelorException(com.axelor.exception.AxelorException)

Example 14 with Context

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

the class SaleOrderLineController method getTaxEquiv.

public void getTaxEquiv(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    SaleOrder saleOrder = Beans.get(SaleOrderLineService.class).getSaleOrder(context);
    response.setValue("taxEquiv", null);
    if (saleOrder == null || saleOrderLine == null || saleOrder.getClientPartner() == null || saleOrderLine.getTaxLine() == null)
        return;
    response.setValue("taxEquiv", Beans.get(FiscalPositionService.class).getTaxEquiv(saleOrder.getClientPartner().getFiscalPosition(), saleOrderLine.getTaxLine().getTax()));
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 15 with Context

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

the class BatchJob method applyBeanPropertiesWithScriptHelper.

private Map<String, Object> applyBeanPropertiesWithScriptHelper(Object bean, Map<String, Object> properties) {
    Context scriptContext = new Context(Mapper.toMap(bean), bean.getClass());
    ScriptHelper scriptHelper = new GroovyScriptHelper(scriptContext);
    return applyBeanProperties(bean, properties, value -> scriptHelper.eval(value.toString()));
}
Also used : JobExecutionContext(org.quartz.JobExecutionContext) Context(com.axelor.rpc.Context) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) ScriptHelper(com.axelor.script.ScriptHelper) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper)

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