Search in sources :

Example 46 with ActionViewBuilder

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);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner)

Example 47 with ActionViewBuilder

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);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 48 with ActionViewBuilder

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());
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) PurchaseRequestService(com.axelor.apps.purchase.service.PurchaseRequestService) PurchaseRequestRepository(com.axelor.apps.purchase.db.repo.PurchaseRequestRepository) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) List(java.util.List) PurchaseRequest(com.axelor.apps.purchase.db.PurchaseRequest)

Example 49 with ActionViewBuilder

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());
}
Also used : Context(com.axelor.rpc.Context) BamlModelRepository(com.axelor.apps.bpm.db.repo.BamlModelRepository) MetaJsonModelRepository(com.axelor.meta.db.repo.MetaJsonModelRepository) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) BamlModel(com.axelor.apps.bpm.db.BamlModel) Model(com.axelor.db.Model) BamlModel(com.axelor.apps.bpm.db.BamlModel) Map(java.util.Map) BamlService(com.axelor.apps.baml.service.BamlService) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 50 with ActionViewBuilder

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());
}
Also used : MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) MetaJsonModelRepository(com.axelor.meta.db.repo.MetaJsonModelRepository) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) LinkedHashMap(java.util.LinkedHashMap) MetaModel(com.axelor.meta.db.MetaModel) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)54 AxelorException (com.axelor.exception.AxelorException)18 User (com.axelor.auth.db.User)17 List (java.util.List)15 Employee (com.axelor.apps.hr.db.Employee)14 Map (java.util.Map)14 ArrayList (java.util.ArrayList)13 Company (com.axelor.apps.base.db.Company)10 Partner (com.axelor.apps.base.db.Partner)9 Wizard (com.axelor.apps.base.db.Wizard)9 Invoice (com.axelor.apps.account.db.Invoice)8 Currency (com.axelor.apps.base.db.Currency)7 PriceList (com.axelor.apps.base.db.PriceList)7 LinkedHashMap (java.util.LinkedHashMap)6 SaleOrder (com.axelor.apps.sale.db.SaleOrder)5 StockMove (com.axelor.apps.stock.db.StockMove)5 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)5 HRMenuValidateService (com.axelor.apps.hr.service.HRMenuValidateService)4 StockMoveMultiInvoiceService (com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService)4 MetaJsonModel (com.axelor.meta.db.MetaJsonModel)4