Search in sources :

Example 61 with Context

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

the class SaleOrderLineController method supplierPartnerDomain.

/**
 * Called from sale order line form. Set domain for supplier partner.
 *
 * @param request
 * @param response
 */
public void supplierPartnerDomain(ActionRequest request, ActionResponse response) {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    String domain = "self.isContact = false AND self.isSupplier = true";
    Product product = saleOrderLine.getProduct();
    if (product != null) {
        List<Long> authorizedPartnerIdsList = Beans.get(SaleOrderLineServiceSupplyChain.class).getSupplierPartnerList(saleOrderLine);
        if (authorizedPartnerIdsList.isEmpty()) {
            response.setAttr("supplierPartner", "domain", "self.id IN (0)");
            return;
        } else {
            domain += String.format(" AND self.id IN (%s)", authorizedPartnerIdsList.stream().map(Object::toString).collect(Collectors.joining(",")));
        }
    }
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    if (saleOrder == null) {
        Context parentContext = request.getContext().getParent();
        if (parentContext == null) {
            response.setAttr("supplierPartner", "domain", domain);
            return;
        }
        saleOrder = parentContext.asType(SaleOrder.class);
        if (saleOrder == null) {
            response.setAttr("supplierPartner", "domain", domain);
            return;
        }
    }
    String blockedPartnerQuery = Beans.get(BlockingService.class).listOfBlockedPartner(saleOrder.getCompany(), BlockingRepository.PURCHASE_BLOCKING);
    if (!Strings.isNullOrEmpty(blockedPartnerQuery)) {
        domain += String.format(" AND self.id NOT in (%s)", blockedPartnerQuery);
    }
    if (saleOrder.getCompany() != null) {
        domain += " AND " + saleOrder.getCompany().getId() + " in (SELECT id FROM self.companySet)";
    }
    response.setAttr("supplierPartner", "domain", domain);
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineServiceSupplyChain(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChain) BlockingService(com.axelor.apps.base.service.BlockingService) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 62 with Context

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

the class BankOrderController method validate.

public void validate(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    BankOrderService bankOrderService = Beans.get(BankOrderService.class);
    BankOrder bankOrder = context.asType(BankOrder.class);
    bankOrder = Beans.get(BankOrderRepository.class).find(bankOrder.getId());
    try {
        EbicsUser ebicsUser = bankOrder.getSignatoryEbicsUser();
        if (ebicsUser == null) {
            response.setError(I18n.get(IExceptionMessage.EBICS_MISSING_NAME));
        } else {
            if (ebicsUser.getEbicsPartner().getEbicsTypeSelect() == EbicsPartnerRepository.EBICS_TYPE_TS) {
                bankOrderService.validate(bankOrder);
            } else {
                if (context.get("password") == null) {
                    response.setError(I18n.get(IExceptionMessage.EBICS_WRONG_PASSWORD));
                }
                if (context.get("password") != null) {
                    String password = (String) context.get("password");
                    if (ebicsUser.getPassword() == null || !ebicsUser.getPassword().equals(password)) {
                        response.setValue("password", "");
                        response.setError(I18n.get(IExceptionMessage.EBICS_WRONG_PASSWORD));
                    } else {
                        bankOrderService.validate(bankOrder);
                    }
                }
                response.setReload(true);
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) BankOrderService(com.axelor.apps.bankpayment.service.bankorder.BankOrderService) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) AxelorException(com.axelor.exception.AxelorException)

Example 63 with Context

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

the class BankReconciliationController method validateMultipleReconcile.

public void validateMultipleReconcile(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        Map<String, Object> bankReconciliationContext = (Map<String, Object>) context.get("_bankReconciliation");
        BankReconciliation bankReconciliation = Beans.get(BankReconciliationRepository.class).find(((Integer) bankReconciliationContext.get("id")).longValue());
        List<HashMap<String, Object>> moveLinesToReconcileContext = (List<HashMap<String, Object>>) context.get("toReconcileMoveLineSet");
        Map<String, Object> selectedBankReconciliationLineContext = (Map<String, Object>) context.get("_selectedBankReconciliationLine");
        BankReconciliationLine bankReconciliationLine = Beans.get(BankReconciliationLineRepository.class).find(((Integer) selectedBankReconciliationLineContext.get("id")).longValue());
        Beans.get(BankReconciliationValidateService.class).validateMultipleBankReconciles(bankReconciliation, bankReconciliationLine, moveLinesToReconcileContext);
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) BankReconciliationLineRepository(com.axelor.apps.bankpayment.db.repo.BankReconciliationLineRepository) BankReconciliationRepository(com.axelor.apps.bankpayment.db.repo.BankReconciliationRepository) HashMap(java.util.HashMap) BankReconciliationValidateService(com.axelor.apps.bankpayment.service.bankreconciliation.BankReconciliationValidateService) BankReconciliation(com.axelor.apps.bankpayment.db.BankReconciliation) BankReconciliationLine(com.axelor.apps.bankpayment.db.BankReconciliationLine) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 64 with Context

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

the class BankReconciliationLineController method setAccountDomain.

public void setAccountDomain(ActionRequest request, ActionResponse response) {
    try {
        Context parentContext = request.getContext().getParent();
        BankReconciliation bankReconciliation = null;
        if (parentContext != null && parentContext.getContextClass().toString().equals(BankReconciliation.class.toString())) {
            bankReconciliation = parentContext.asType(BankReconciliation.class);
        } else if (parentContext == null || !parentContext.getContextClass().toString().equals(BankReconciliation.class.toString())) {
            bankReconciliation = (BankReconciliation) request.getContext().get("bankReconciliation");
        }
        String domain = Beans.get(BankReconciliationService.class).getAccountDomain(bankReconciliation);
        response.setAttr("account", "domain", domain);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) BankReconciliationService(com.axelor.apps.bankpayment.service.bankreconciliation.BankReconciliationService) BankReconciliation(com.axelor.apps.bankpayment.db.BankReconciliation)

Example 65 with Context

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

the class StockMoveLineController method compute.

public void compute(ActionRequest request, ActionResponse response) throws AxelorException {
    StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
    Optional<StockMove> stockMove = Optional.ofNullable(stockMoveLine.getStockMove());
    if (!stockMove.isPresent()) {
        Context parentContext = request.getContext().getParent();
        if (parentContext.getContextClass().equals(StockMove.class)) {
            stockMove = Optional.ofNullable(parentContext.asType(StockMove.class));
        } else if (parentContext.getContextClass().equals(ManufOrder.class)) {
            ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
            ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
            stockMove = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getInStockMoveList());
        }
        if (!stockMove.isPresent()) {
            return;
        }
    }
    stockMoveLine = Beans.get(StockMoveLineService.class).compute(stockMoveLine, stockMove.get());
    response.setValue("companyPurchasePrice", stockMoveLine.getCompanyPurchasePrice());
    response.setValue("unitPriceUntaxed", stockMoveLine.getUnitPriceUntaxed());
    response.setValue("unitPriceTaxed", stockMoveLine.getUnitPriceTaxed());
}
Also used : Context(com.axelor.rpc.Context) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) ManufOrder(com.axelor.apps.production.db.ManufOrder)

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