Search in sources :

Example 41 with Context

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

the class InvoiceLineController method getProductInformation.

public void getProductInformation(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
    Invoice invoice = this.getInvoice(context);
    Product product = invoiceLine.getProduct();
    Map<String, Object> productInformation = new HashMap<>();
    if (invoice != null && product != null) {
        try {
            productInformation = Beans.get(InvoiceLineService.class).fillProductInformation(invoice, invoiceLine);
            String errorMsg = (String) productInformation.get("error");
            if (!Strings.isNullOrEmpty(errorMsg)) {
                response.setFlash(errorMsg);
            }
        } catch (Exception e) {
            TraceBackService.trace(response, e);
        }
    } else {
        productInformation = Beans.get(InvoiceLineService.class).resetProductInformation(invoice);
    }
    response.setValues(productInformation);
}
Also used : Context(com.axelor.rpc.Context) Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) HashMap(java.util.HashMap) Product(com.axelor.apps.base.db.Product) AxelorException(com.axelor.exception.AxelorException)

Example 42 with Context

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

the class ABCAnalysisController method printReport.

public void printReport(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    Long abcAnalysisId = Long.parseLong(context.get("_abcAnalysisId").toString());
    String reportType = (String) context.get("reportTypeSelect");
    ABCAnalysis abcAnalysis = Beans.get(ABCAnalysisRepository.class).find(abcAnalysisId);
    try {
        String name = I18n.get("ABC Analysis N°") + " " + abcAnalysis.getAbcAnalysisSeq();
        String fileLink = Beans.get(ABCAnalysisServiceImpl.class).printReport(abcAnalysis, reportType);
        if (!Strings.isNullOrEmpty(fileLink)) {
            response.setView(ActionView.define(name).add("html", fileLink).map());
        }
    } catch (AxelorException e) {
        response.setError(e.getMessage());
    }
    response.setCanClose(true);
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) ABCAnalysis(com.axelor.apps.base.db.ABCAnalysis) ABCAnalysisServiceImpl(com.axelor.apps.base.service.ABCAnalysisServiceImpl) ABCAnalysisRepository(com.axelor.apps.base.db.repo.ABCAnalysisRepository)

Example 43 with Context

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

the class AddressController method createPartnerAddress.

public void createPartnerAddress(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    Context parentContext = context.getParent();
    if (parentContext.isEmpty()) {
        return;
    }
    String parentModel = (String) parentContext.get("_model");
    LOG.debug("Create partner address : Parent model = {}", parentModel);
    String partnerField = PartnerAddressRepository.modelPartnerFieldMap.get(parentModel);
    LOG.debug("Create partner address : Parent field = {}", partnerField);
    Partner partner = null;
    if (parentContext.get(partnerField) instanceof Partner) {
        partner = (Partner) parentContext.get(partnerField);
    } else if (parentContext.get(partnerField) instanceof Map) {
        partner = Mapper.toBean(Partner.class, (Map<String, Object>) parentContext.get(partnerField));
    }
    LOG.debug("Create partner address : Partner = {}", partner);
    if (partner == null || partner.getId() == null) {
        return;
    }
    Address address = context.asType(Address.class);
    PartnerAddress partnerAddress = Beans.get(PartnerAddressRepository.class).all().filter("self.partner.id = ? AND self.address.id = ?", partner.getId(), address.getId()).fetchOne();
    LOG.debug("Create partner address : Partner Address = {}", partnerAddress);
    if (partnerAddress == null) {
        partner = Beans.get(PartnerRepository.class).find(partner.getId());
        address = Beans.get(AddressRepository.class).find(address.getId());
        Boolean invoicing = (Boolean) context.get("isInvoicingAddr");
        if (invoicing == null) {
            invoicing = false;
        }
        Boolean delivery = (Boolean) context.get("isDeliveryAddr");
        if (delivery == null) {
            delivery = false;
        }
        Boolean isDefault = (Boolean) context.get("isDefault");
        if (isDefault == null) {
            isDefault = false;
        }
        PartnerService partnerService = Beans.get(PartnerService.class);
        partnerService.addPartnerAddress(partner, address, isDefault, invoicing, delivery);
        partnerService.savePartner(partner);
    }
}
Also used : Context(com.axelor.rpc.Context) PartnerAddressRepository(com.axelor.apps.base.db.repo.PartnerAddressRepository) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner) HashMap(java.util.HashMap) Map(java.util.Map)

Example 44 with Context

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

the class AdvancedExportController method fillTitle.

public void fillTitle(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    MetaField metaField = (MetaField) context.get("metaField");
    if (metaField != null) {
        if (Strings.isNullOrEmpty(metaField.getLabel())) {
            inflector = Inflector.getInstance();
            response.setValue("title", I18n.get(this.getFieldTitle(inflector, metaField.getName())));
        } else {
            response.setValue("title", I18n.get(metaField.getLabel()));
        }
    } else {
        response.setValue("title", null);
    }
}
Also used : Context(com.axelor.rpc.Context) MetaField(com.axelor.meta.db.MetaField)

Example 45 with Context

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

the class AdvancedExportController method fillTargetField.

public void fillTargetField(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    MetaField metaField = (MetaField) context.get("metaField");
    if (metaField != null) {
        String targetField = "";
        if (context.get("targetField") == null) {
            targetField = metaField.getName();
        } else {
            targetField = context.get("targetField").toString();
            targetField += "." + metaField.getName();
        }
        response.setValue("targetField", targetField);
        if (metaField.getRelationship() != null) {
            response.setValue("currentDomain", metaField.getTypeName());
            response.setValue("metaField", null);
        } else {
            response.setAttr("metaField", "readonly", true);
            response.setAttr("validateFieldSelectionBtn", "readonly", true);
            response.setAttr("$viewerMessage", "hidden", false);
            response.setAttr("$isValidate", "value", true);
        }
    }
}
Also used : Context(com.axelor.rpc.Context) MetaField(com.axelor.meta.db.MetaField)

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