Search in sources :

Example 71 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class CashManagementForecastRecapRepository method save.

@Override
public ForecastRecap save(ForecastRecap entity) {
    try {
        if (entity.getForecastRecapSeq() == null) {
            Company company = entity.getCompany();
            String sequence = Beans.get(SequenceService.class).getSequenceNumber(SequenceRepository.FORECAST_RECAP_SEQUENCE, company);
            if (sequence == null) {
                throw new AxelorException(company, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.FORCAST_RECAP_SEQUENCE_ERROR), company.getName());
            } else {
                entity.setForecastRecapSeq(sequence);
            }
        }
        return super.save(entity);
    } catch (AxelorException e) {
        TraceBackService.traceExceptionFromSaveMethod(e);
        throw new PersistenceException(e.getMessage(), e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) PersistenceException(javax.persistence.PersistenceException) SequenceService(com.axelor.apps.base.service.administration.SequenceService)

Example 72 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class PurchaseOrderController method supplierPartnerDomain.

/**
 * Called on supplier partner select. Set the domain for the field supplierPartner
 *
 * @param request
 * @param response
 */
public void supplierPartnerDomain(ActionRequest request, ActionResponse response) {
    try {
        PurchaseOrder purchaseOrder = request.getContext().asType(PurchaseOrder.class);
        Company company = purchaseOrder.getCompany();
        long companyId = company.getPartner() == null ? 0L : company.getPartner().getId();
        String domain = String.format("self.id != %d AND self.isContact = false AND self.isSupplier = true", companyId);
        String blockedPartnerQuery = Beans.get(BlockingService.class).listOfBlockedPartner(company, BlockingRepository.PURCHASE_BLOCKING);
        if (!Strings.isNullOrEmpty(blockedPartnerQuery)) {
            domain += String.format(" AND self.id NOT in (%s)", blockedPartnerQuery);
        }
        domain += " AND :company member of self.companySet";
        response.setAttr("supplierPartner", "domain", domain);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) BlockingService(com.axelor.apps.base.service.BlockingService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) AxelorException(com.axelor.exception.AxelorException)

Example 73 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class PurchaseOrderController method mergePurchaseOrder.

// Generate single purchase order from several
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergePurchaseOrder(ActionRequest request, ActionResponse response) {
    List<PurchaseOrder> purchaseOrderList = new ArrayList<PurchaseOrder>();
    List<Long> purchaseOrderIdList = new ArrayList<Long>();
    boolean fromPopup = false;
    if (request.getContext().get("purchaseOrderToMerge") != null) {
        if (request.getContext().get("purchaseOrderToMerge") instanceof List) {
            // No confirmation popup, purchase orders are content in a parameter list
            List<Map> purchaseOrderMap = (List<Map>) request.getContext().get("purchaseOrderToMerge");
            for (Map map : purchaseOrderMap) {
                purchaseOrderIdList.add(new Long((Integer) map.get("id")));
            }
        } else {
            // After confirmation popup, purchase order's id are in a string separated by ","
            String purchaseOrderIdListStr = (String) request.getContext().get("purchaseOrderToMerge");
            for (String purchaseOrderId : purchaseOrderIdListStr.split(",")) {
                purchaseOrderIdList.add(new Long(purchaseOrderId));
            }
            fromPopup = true;
        }
    }
    // Check if currency, supplierPartner, company and tradingName are the same for all selected
    // purchase orders
    Currency commonCurrency = null;
    Partner commonSupplierPartner = null;
    Company commonCompany = null;
    Partner commonContactPartner = null;
    TradingName commonTradingName = null;
    // Useful to determine if a difference exists between contact partners of all purchase orders
    boolean existContactPartnerDiff = false;
    PriceList commonPriceList = null;
    // Useful to determine if a difference exists between price lists of all purchase orders
    boolean existPriceListDiff = false;
    PurchaseOrder purchaseOrderTemp;
    boolean allTradingNamesAreNull = true;
    int count = 1;
    for (Long purchaseOrderId : purchaseOrderIdList) {
        purchaseOrderTemp = JPA.em().find(PurchaseOrder.class, purchaseOrderId);
        purchaseOrderList.add(purchaseOrderTemp);
        if (count == 1) {
            commonCurrency = purchaseOrderTemp.getCurrency();
            commonSupplierPartner = purchaseOrderTemp.getSupplierPartner();
            commonCompany = purchaseOrderTemp.getCompany();
            commonContactPartner = purchaseOrderTemp.getContactPartner();
            commonPriceList = purchaseOrderTemp.getPriceList();
            commonTradingName = purchaseOrderTemp.getTradingName();
            allTradingNamesAreNull = commonTradingName == null;
        } else {
            if (commonCurrency != null && !commonCurrency.equals(purchaseOrderTemp.getCurrency())) {
                commonCurrency = null;
            }
            if (commonSupplierPartner != null && !commonSupplierPartner.equals(purchaseOrderTemp.getSupplierPartner())) {
                commonSupplierPartner = null;
            }
            if (commonCompany != null && !commonCompany.equals(purchaseOrderTemp.getCompany())) {
                commonCompany = null;
            }
            if (commonContactPartner != null && !commonContactPartner.equals(purchaseOrderTemp.getContactPartner())) {
                commonContactPartner = null;
                existContactPartnerDiff = true;
            }
            if (commonPriceList != null && !commonPriceList.equals(purchaseOrderTemp.getPriceList())) {
                commonPriceList = null;
                existPriceListDiff = true;
            }
            if (!Objects.equals(commonTradingName, purchaseOrderTemp.getTradingName())) {
                commonTradingName = null;
                allTradingNamesAreNull = false;
            }
        }
        count++;
    }
    StringBuilder fieldErrors = new StringBuilder();
    if (commonCurrency == null) {
        fieldErrors.append(I18n.get(IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_CURRENCY));
    }
    if (commonSupplierPartner == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_SUPPLIER_PARTNER));
    }
    if (commonCompany == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_COMPANY));
    }
    if (commonTradingName == null && !allTradingNamesAreNull) {
        fieldErrors.append(I18n.get(IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_TRADING_NAME));
    }
    if (fieldErrors.length() > 0) {
        response.setFlash(fieldErrors.toString());
        return;
    }
    // Check if priceList or contactPartner are content in parameters
    if (request.getContext().get("priceList") != null) {
        commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
    }
    if (request.getContext().get("contactPartner") != null) {
        commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
    }
    if (!fromPopup && (existContactPartnerDiff || existPriceListDiff)) {
        // Need to display intermediate screen to select some values
        ActionViewBuilder confirmView = ActionView.define("Confirm merge purchase order").model(Wizard.class.getName()).add("form", "purchase-order-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
        if (existPriceListDiff) {
            confirmView.context("contextPriceListToCheck", "true");
        }
        if (existContactPartnerDiff) {
            confirmView.context("contextContactPartnerToCheck", "true");
            confirmView.context("contextPartnerId", commonSupplierPartner.getId().toString());
        }
        confirmView.context("purchaseOrderToMerge", Joiner.on(",").join(purchaseOrderIdList));
        response.setView(confirmView.map());
        return;
    }
    try {
        PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderService.class).mergePurchaseOrders(purchaseOrderList, commonCurrency, commonSupplierPartner, commonCompany, commonContactPartner, commonPriceList, commonTradingName);
        if (purchaseOrder != null) {
            // Open the generated purchase order in a new tab
            response.setView(ActionView.define("Purchase order").model(PurchaseOrder.class.getName()).add("grid", "purchase-order-grid").add("form", "purchase-order-form").param("search-filters", "purchase-order-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(purchaseOrder.getId())).map());
            response.setCanClose(true);
        }
    } catch (Exception e) {
        response.setFlash(e.getLocalizedMessage());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) PurchaseOrderService(com.axelor.apps.purchase.service.PurchaseOrderService) ArrayList(java.util.ArrayList) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) Currency(com.axelor.apps.base.db.Currency) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) TradingName(com.axelor.apps.base.db.TradingName) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) Wizard(com.axelor.apps.base.db.Wizard)

Example 74 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class StockMoveController method allocateAll.

/**
 * Called from stock move form view, on available qty boolean change. Only called if the user
 * accepted to allocate everything. Call {@link
 * StockMoveReservedQtyService#allocateAll(StockMove)}.
 *
 * @param request
 * @param response
 */
public void allocateAll(ActionRequest request, ActionResponse response) {
    try {
        StockMove stockMove = request.getContext().asType(StockMove.class);
        Company company = stockMove.getCompany();
        if (company == null) {
            return;
        }
        SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
        if (!Beans.get(AppSupplychainService.class).getAppSupplychain().getManageStockReservation() || !stockMove.getAvailabilityRequest() || !supplyChainConfig.getAutoAllocateOnAvailabilityRequest()) {
            return;
        }
        Beans.get(StockMoveReservedQtyService.class).allocateAll(stockMove);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveReservedQtyService(com.axelor.apps.supplychain.service.StockMoveReservedQtyService) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService)

Example 75 with Company

use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.

the class StockMoveInvoiceController method openInvoicingWizard.

public void openInvoicingWizard(ActionRequest request, ActionResponse response) {
    try {
        response.setReload(true);
        StockMove stockMove = request.getContext().asType(StockMove.class);
        stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
        StockMoveInvoiceService stockMoveInvoiceService = Beans.get(StockMoveInvoiceService.class);
        List<Map<String, Object>> stockMoveLines = stockMoveInvoiceService.getStockMoveLinesToInvoice(stockMove);
        Company company = stockMove.getCompany();
        SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
        boolean isPartialInvoicingActivated = (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING && supplyChainConfig.getActivateIncStockMovePartialInvoicing()) || (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && supplyChainConfig.getActivateOutStockMovePartialInvoicing());
        if (isPartialInvoicingActivated && !stockMoveLines.isEmpty()) {
            // open wizard view for partial invoicing
            response.setView(ActionView.define(I18n.get(ITranslation.INVOICING)).model(StockMove.class.getName()).add("form", "stock-move-invoicing-wizard-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("width", "large").param("popup-save", "false").context("_id", stockMove.getId()).map());
        } else if (!stockMoveLines.isEmpty()) {
            // invoice everything if config is disabled.
            Invoice invoice = stockMoveInvoiceService.createInvoice(stockMove, StockMoveRepository.INVOICE_ALL, null);
            if (invoice != null) {
                response.setView(ActionView.define(I18n.get(ITranslation.INVOICE)).model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoice.getId())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(company)).map());
            }
        } else {
            response.setAlert(I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_ERROR));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) StockMoveInvoiceService(com.axelor.apps.supplychain.service.StockMoveInvoiceService) Map(java.util.Map) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService)

Aggregations

Company (com.axelor.apps.base.db.Company)213 Transactional (com.google.inject.persist.Transactional)72 Partner (com.axelor.apps.base.db.Partner)68 AxelorException (com.axelor.exception.AxelorException)65 BigDecimal (java.math.BigDecimal)54 Move (com.axelor.apps.account.db.Move)35 MoveLine (com.axelor.apps.account.db.MoveLine)35 LocalDate (java.time.LocalDate)35 ArrayList (java.util.ArrayList)31 PaymentMode (com.axelor.apps.account.db.PaymentMode)28 AccountConfig (com.axelor.apps.account.db.AccountConfig)27 Journal (com.axelor.apps.account.db.Journal)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)25 BankDetails (com.axelor.apps.base.db.BankDetails)22 Currency (com.axelor.apps.base.db.Currency)19 Product (com.axelor.apps.base.db.Product)17 StockLocation (com.axelor.apps.stock.db.StockLocation)17 StockMove (com.axelor.apps.stock.db.StockMove)15 List (java.util.List)15