Search in sources :

Example 66 with Context

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

the class StockMoveLineController method setProductInfo.

/**
 * Called from stock move line form. Fill product info using the company either from the stock
 * move line, from the parent stock move or the parent manuf order.
 *
 * @param request
 * @param response
 */
public void setProductInfo(ActionRequest request, ActionResponse response) {
    StockMoveLine stockMoveLine;
    try {
        stockMoveLine = request.getContext().asType(StockMoveLine.class);
        Company company;
        StockMove stockMove = stockMoveLine.getStockMove();
        if (stockMove == null) {
            Context parentContext = request.getContext().getParent();
            if (parentContext.getContextClass().equals(StockMove.class)) {
                stockMove = parentContext.asType(StockMove.class);
                company = stockMove.getCompany();
            } else if (parentContext.getContextClass().equals(ManufOrder.class)) {
                ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
                company = manufOrder.getCompany();
            } else if (parentContext.getContextClass().equals(OperationOrder.class)) {
                OperationOrder operationOrder = parentContext.asType(OperationOrder.class);
                if (operationOrder.getManufOrder() == null) {
                    return;
                }
                company = operationOrder.getManufOrder().getCompany();
            } else {
                throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, IExceptionMessage.STOCK_MOVE_LINE_UNKNOWN_PARENT_CONTEXT);
            }
        } else {
            company = stockMove.getCompany();
        }
        if (stockMoveLine.getProduct() == null) {
            stockMoveLine = new StockMoveLine();
            response.setValues(Mapper.toMap(stockMoveLine));
            return;
        }
        Beans.get(StockMoveLineService.class).setProductInfo(stockMove, stockMoveLine, company);
        response.setValues(stockMoveLine);
    } catch (Exception e) {
        stockMoveLine = new StockMoveLine();
        response.setValues(Mapper.toMap(stockMoveLine));
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) OperationOrder(com.axelor.apps.production.db.OperationOrder) AxelorException(com.axelor.exception.AxelorException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 67 with Context

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

the class ProjectTemplateController method createProjectFromWizard.

@SuppressWarnings("unchecked")
public void createProjectFromWizard(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    String projectTemplateId = ((LinkedHashMap<String, Object>) context.get("_projectTemplate")).get("id").toString();
    ProjectTemplate projectTemplate = Beans.get(ProjectTemplateRepository.class).find(Long.parseLong(projectTemplateId));
    String projectCode = (String) context.get("code");
    Object clientPartnerContext = context.get("clientPartner");
    Partner clientPartner = null;
    if (clientPartnerContext != null) {
        String clientPartnerId = ((LinkedHashMap<String, Object>) clientPartnerContext).get("id").toString();
        clientPartner = Beans.get(PartnerRepository.class).find(Long.parseLong(clientPartnerId));
    }
    Project project;
    try {
        project = Beans.get(ProjectService.class).createProjectFromTemplate(projectTemplate, projectCode, clientPartner);
        response.setCanClose(true);
        response.setView(ActionView.define(I18n.get("Project")).model(Project.class.getName()).add("form", "project-form").add("grid", "project-grid").param("search-filters", "project-filters").context("_showRecord", project.getId()).map());
    } catch (AxelorException e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) AppProject(com.axelor.apps.base.db.AppProject) Project(com.axelor.apps.project.db.Project) AxelorException(com.axelor.exception.AxelorException) Partner(com.axelor.apps.base.db.Partner) ProjectTemplate(com.axelor.apps.project.db.ProjectTemplate) ProjectTemplateRepository(com.axelor.apps.project.db.repo.ProjectTemplateRepository)

Example 68 with Context

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

the class ProjectInvoicingAssistantBatchService method updateJsonObject.

@SuppressWarnings("unchecked")
public static void updateJsonObject(Batch batch, List<Object> recordList, String field, Map<String, Object> contextValues) {
    JsonContext jsonContext = (JsonContext) contextValues.get("jsonContext");
    List<Object> dataList = recordList;
    if (jsonContext.containsKey(field)) {
        dataList = ((List<Object>) jsonContext.get(field)).stream().map(obj -> {
            if (Mapper.toMap(EntityHelper.getEntity(obj)).get("id") != null) {
                Map<String, Object> idMap = new HashMap<String, Object>();
                idMap.put("id", Mapper.toMap(EntityHelper.getEntity(obj)).get("id"));
                return idMap;
            }
            return obj;
        }).collect(Collectors.toList());
        dataList.addAll(recordList);
    }
    jsonContext.put(field, dataList);
    Context context = (Context) contextValues.get("context");
    batch.setAttrs(context.get("attrs").toString());
}
Also used : JsonContext(com.axelor.rpc.JsonContext) Context(com.axelor.rpc.Context) JsonContext(com.axelor.rpc.JsonContext) HashMap(java.util.HashMap)

Example 69 with Context

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

the class TemplateMessageServiceImpl method computeTemplateContexts.

@SuppressWarnings("unchecked")
@Override
public Map<String, Object> computeTemplateContexts(List<TemplateContext> templateContextList, long objectId, String model, boolean isJson, Map<String, Object> templatesContext) throws ClassNotFoundException {
    if (templateContextList == null) {
        return templatesContext;
    }
    Context context = null;
    if (isJson) {
        context = new com.axelor.rpc.Context(objectId, MetaJsonRecord.class);
    } else {
        Class<? extends Model> myClass = (Class<? extends Model>) Class.forName(model);
        context = new com.axelor.rpc.Context(objectId, myClass);
    }
    for (TemplateContext templateContext : templateContextList) {
        Object result = templateContextService.computeTemplateContext(templateContext, context);
        templatesContext.put(templateContext.getName(), result);
    }
    return templatesContext;
}
Also used : TemplateContext(com.axelor.apps.message.db.TemplateContext) Context(com.axelor.rpc.Context) MetaJsonModel(com.axelor.meta.db.MetaJsonModel) Model(com.axelor.db.Model) MetaModel(com.axelor.meta.db.MetaModel) TemplateContext(com.axelor.apps.message.db.TemplateContext) Context(com.axelor.rpc.Context) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 70 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 = parentContext.asType(Invoice.class);
    if (!parentContext.getContextClass().toString().equals(Invoice.class.toString())) {
        InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
        invoice = invoiceLine.getInvoice();
    }
    return invoice;
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

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