Search in sources :

Example 96 with Context

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

the class SaleOrderLineController method getProductInformation.

/**
 * Called by the sale order line form. Update all fields when the product is changed.
 *
 * @param request
 * @param response
 */
public void getProductInformation(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);
        Product product = saleOrderLine.getProduct();
        if (saleOrder == null || product == null) {
            resetProductInformation(response, saleOrderLine);
            return;
        }
        try {
            product = Beans.get(ProductRepository.class).find(product.getId());
            saleOrderLineService.computeProductInformation(saleOrderLine, saleOrder);
            response.setValue("saleSupplySelect", product.getSaleSupplySelect());
            response.setValues(saleOrderLine);
        } catch (Exception e) {
            resetProductInformation(response, saleOrderLine);
            TraceBackService.trace(response, e);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AxelorException(com.axelor.exception.AxelorException)

Example 97 with Context

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

the class SaleOrderLineController method fillMaxDiscount.

/**
 * Called from sale order line form view on load and on discount type select change. Call {@link
 * SaleOrderLineService#computeMaxDiscount} and set the message to the view.
 *
 * @param request
 * @param response
 */
public void fillMaxDiscount(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);
        BigDecimal maxDiscount = saleOrderLineService.computeMaxDiscount(saleOrder, saleOrderLine);
        response.setValue("$maxDiscount", maxDiscount);
    } 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) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 98 with Context

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

the class SaleOrderLineController method computeSubMargin.

public void computeSubMargin(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
    SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
    saleOrderLine.setSaleOrder(saleOrder);
    Map<String, BigDecimal> map = saleOrderLineService.computeSubMargin(saleOrder, saleOrderLine);
    response.setValues(map);
}
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)

Example 99 with Context

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

the class SaleOrderLineController method updatePrice.

/**
 * Update the ex. tax unit price of an invoice line from its in. tax unit price.
 *
 * @param request
 * @param response
 */
public void updatePrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    try {
        BigDecimal inTaxPrice = saleOrderLine.getInTaxPrice();
        TaxLine taxLine = saleOrderLine.getTaxLine();
        response.setValue("price", Beans.get(SaleOrderLineService.class).convertUnitPrice(true, taxLine, inTaxPrice));
    } 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 100 with Context

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

the class PackLineController method getProductInformation.

public void getProductInformation(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    PackLine packLine = context.asType(PackLine.class);
    Pack pack = this.getPack(context);
    Product product = packLine.getProduct();
    PackLineService packLineService = Beans.get(PackLineService.class);
    if (product == null) {
        packLine = packLineService.resetProductInformation(packLine);
        response.setValues(packLine);
        return;
    }
    try {
        packLine = packLineService.computeProductInformation(pack, packLine);
        response.setValues(packLine);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) Product(com.axelor.apps.base.db.Product) Pack(com.axelor.apps.sale.db.Pack) PackLineService(com.axelor.apps.sale.service.PackLineService) PackLine(com.axelor.apps.sale.db.PackLine)

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