use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method generateInvoiceConcatOutStockMoveCheckMissingFields.
/**
* Called from mass invoicing out stock move form view. Call method to check for missing fields.
* If there are missing fields, show a wizard. Else call {@link
* StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List)} and show the
* generated invoice.
*
* @param request
* @param response
*/
public void generateInvoiceConcatOutStockMoveCheckMissingFields(ActionRequest request, ActionResponse response) {
try {
List<StockMove> stockMoveList = new ArrayList<>();
List<Long> stockMoveIdList = new ArrayList<>();
// No confirmation popup, stock Moves are content in a parameter list
List<Map> stockMoveMap = (List<Map>) request.getContext().get("customerStockMoveToInvoice");
for (Map map : stockMoveMap) {
stockMoveIdList.add(Long.valueOf((Integer) map.get("id")));
}
for (Long stockMoveId : stockMoveIdList) {
stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
}
Map<String, Object> mapResult = Beans.get(StockMoveMultiInvoiceService.class).areFieldsConflictedToGenerateCustInvoice(stockMoveList);
boolean paymentConditionToCheck = (Boolean) mapResult.getOrDefault("paymentConditionToCheck", false);
boolean paymentModeToCheck = (Boolean) mapResult.getOrDefault("paymentModeToCheck", false);
boolean contactPartnerToCheck = (Boolean) mapResult.getOrDefault("contactPartnerToCheck", false);
StockMove stockMove = stockMoveList.get(0);
Partner partner = stockMove.getPartner();
if (paymentConditionToCheck || paymentModeToCheck || contactPartnerToCheck) {
ActionViewBuilder confirmView = ActionView.define("StockMove").model(StockMove.class.getName()).add("form", "stock-move-supplychain-concat-cust-invoice-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
if (paymentConditionToCheck) {
confirmView.context("contextPaymentConditionToCheck", "true");
} else {
confirmView.context("paymentCondition", mapResult.get("paymentCondition"));
}
if (paymentModeToCheck) {
confirmView.context("contextPaymentModeToCheck", "true");
} else {
confirmView.context("paymentMode", mapResult.get("paymentMode"));
}
if (contactPartnerToCheck) {
confirmView.context("contextContactPartnerToCheck", "true");
confirmView.context("contextPartnerId", partner.getId().toString());
} else {
confirmView.context("contactPartner", mapResult.get("contactPartner"));
}
confirmView.context("customerStockMoveToInvoice", Joiner.on(",").join(stockMoveIdList));
response.setView(confirmView.map());
} else {
Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiOutgoingStockMove(stockMoveList);
invoice.ifPresent(inv -> response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(stockMove.getCompany())).context("_showRecord", String.valueOf(inv.getId())).map()));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class StockMoveInvoiceController method generateMultiCustomerInvoice.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void generateMultiCustomerInvoice(ActionRequest request, ActionResponse response) {
try {
List<Map> stockMoveMap = (List<Map>) request.getContext().get("customerStockMoveToInvoice");
List<Long> stockMoveIdList = new ArrayList<>();
List<StockMove> stockMoveList = new ArrayList<>();
for (Map map : stockMoveMap) {
stockMoveIdList.add(((Number) map.get("id")).longValue());
}
for (Long stockMoveId : stockMoveIdList) {
stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
}
Beans.get(StockMoveMultiInvoiceService.class).checkForAlreadyInvoicedStockMove(stockMoveList);
Entry<List<Long>, String> result = Beans.get(StockMoveMultiInvoiceService.class).generateMultipleInvoices(stockMoveIdList);
List<Long> invoiceIdList = result.getKey();
String warningMessage = result.getValue();
if (!invoiceIdList.isEmpty()) {
ActionViewBuilder viewBuilder;
viewBuilder = ActionView.define("Cust. Invoices");
viewBuilder.model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").domain("self.id IN (" + Joiner.on(",").join(invoiceIdList) + ")").context("_operationTypeSelect", InvoiceRepository.OPERATION_TYPE_CLIENT_SALE).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null)));
response.setView(viewBuilder.map());
}
if (warningMessage != null && !warningMessage.isEmpty()) {
response.setFlash(warningMessage);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class PurchaseRequestController method generatePo.
public void generatePo(ActionRequest request, ActionResponse response) {
@SuppressWarnings("unchecked") List<Long> requestIds = (List<Long>) request.getContext().get("_ids");
if (requestIds != null && !requestIds.isEmpty()) {
Boolean groupBySupplier = (Boolean) request.getContext().get("groupBySupplier");
groupBySupplier = groupBySupplier == null ? false : groupBySupplier;
Boolean groupByProduct = (Boolean) request.getContext().get("groupByProduct");
groupByProduct = groupByProduct == null ? false : groupByProduct;
try {
List<PurchaseRequest> purchaseRequests = Beans.get(PurchaseRequestRepository.class).all().filter("self.id in (?1)", requestIds).fetch();
List<String> purchaseRequestSeqs = purchaseRequests.stream().filter(pr -> pr.getSupplierUser() == null).map(PurchaseRequest::getPurchaseRequestSeq).collect(Collectors.toList());
if (purchaseRequestSeqs != null && !purchaseRequestSeqs.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PURCHASE_REQUEST_MISSING_SUPPLIER_USER), purchaseRequestSeqs.toString());
}
response.setCanClose(true);
List<PurchaseOrder> purchaseOrderList = Beans.get(PurchaseRequestService.class).generatePo(purchaseRequests, groupBySupplier, groupByProduct);
ActionViewBuilder actionViewBuilder = ActionView.define(String.format("Purchase Order%s generated", (purchaseOrderList.size() > 1 ? "s" : ""))).model(PurchaseOrder.class.getName()).add("grid", "purchase-order-quotation-grid").add("form", "purchase-order-form").param("search-filters", "purchase-order-filters").context("_showSingle", true).domain(String.format("self.id in (%s)", StringTool.getIdListString(purchaseOrderList)));
response.setView(actionViewBuilder.map());
} catch (AxelorException e) {
response.setFlash(e.getMessage());
}
}
}
use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class BamlModelController method execute.
public void execute(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
String model = (String) context.get("modelName");
Model entity = null;
if (context.get("recordId") != null && model != null) {
Long recordId = Long.parseLong(context.get("recordId").toString());
entity = WkfContextHelper.getRepository(model).find(recordId);
}
Map<String, Object> bamlModelMap = (Map<String, Object>) context.get("bamlModel");
BamlModel bamlModel = Beans.get(BamlModelRepository.class).find(Long.parseLong(bamlModelMap.get("id").toString()));
Model object = Beans.get(BamlService.class).execute(bamlModel, entity);
String modelName = object.getClass().getSimpleName();
String dasherizeModel = Inflector.getInstance().dasherize(modelName);
String title = object.getClass().getSimpleName();
String formView = dasherizeModel + "-form";
String gridView = dasherizeModel + "-grid";
String jsonModel = null;
if (object instanceof MetaJsonRecord) {
jsonModel = ((MetaJsonRecord) object).getJsonModel();
title = Beans.get(MetaJsonModelRepository.class).findByName(jsonModel).getTitle();
if (Strings.isNullOrEmpty(title)) {
title = jsonModel;
}
formView = "custom-model-" + jsonModel + "-form";
gridView = "custom-model-" + jsonModel + "-grid";
}
response.setCanClose(true);
ActionViewBuilder builder = ActionView.define(I18n.get(title)).model(object.getClass().getName()).add("form", formView).add("grid", gridView).context("_showRecord", object.getId());
if (jsonModel != null) {
builder.context("jsonModel", jsonModel);
builder.domain("self.jsonModel = :jsonModel");
}
response.setView(builder.map());
}
use of com.axelor.meta.schema.actions.ActionView.ActionViewBuilder in project axelor-open-suite by axelor.
the class WkfModelController method openRecordView.
@SuppressWarnings("unchecked")
private void openRecordView(ActionRequest request, ActionResponse response, String statusKey, String modelKey, String recordkey) {
LinkedHashMap<String, Object> _map = (LinkedHashMap<String, Object>) request.getData().get("context");
String status = "";
if (statusKey != null) {
status = _map.get("title").toString();
}
String modelName = _map.get(modelKey).toString();
boolean isMetaModel = (boolean) _map.get("isMetaModel");
List<Long> recordIds = (List<Long>) _map.get(recordkey);
ActionViewBuilder actionViewBuilder = null;
if (isMetaModel) {
MetaModel metaModel = Beans.get(MetaModelRepository.class).findByName(modelName);
actionViewBuilder = this.createActionBuilder(status, metaModel);
} else {
MetaJsonModel metaJsonModel = Beans.get(MetaJsonModelRepository.class).findByName(modelName);
actionViewBuilder = this.createActionBuilder(status, metaJsonModel);
}
response.setView(actionViewBuilder.context("ids", !recordIds.isEmpty() ? recordIds : 0).map());
}
Aggregations