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);
}
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);
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations