Search in sources :

Example 36 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class SaleOrderLineController method supplierPartnerDefault.

/**
 * Called from sale order line form, on product change and on sale supply select change
 *
 * @param request
 * @param response
 */
public void supplierPartnerDefault(ActionRequest request, ActionResponse response) {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    if (saleOrderLine.getSaleSupplySelect() != SaleOrderLineRepository.SALE_SUPPLY_PURCHASE) {
        return;
    }
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    if (saleOrder == null) {
        Context parentContext = request.getContext().getParent();
        if (parentContext == null) {
            return;
        }
        saleOrder = parentContext.asType(SaleOrder.class);
    }
    if (saleOrder == null) {
        return;
    }
    Partner supplierPartner = null;
    if (saleOrderLine.getProduct() != null) {
        supplierPartner = saleOrderLine.getProduct().getDefaultSupplierPartner();
    }
    if (supplierPartner != null) {
        Blocking blocking = Beans.get(BlockingService.class).getBlocking(supplierPartner, saleOrder.getCompany(), BlockingRepository.PURCHASE_BLOCKING);
        if (blocking != null) {
            supplierPartner = null;
        }
    }
    response.setValue("supplierPartner", supplierPartner);
}
Also used : Context(com.axelor.rpc.Context) Blocking(com.axelor.apps.base.db.Blocking) BlockingService(com.axelor.apps.base.service.BlockingService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner)

Example 37 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class SaleOrderController method mergeSaleOrder.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergeSaleOrder(ActionRequest request, ActionResponse response) {
    List<SaleOrder> saleOrderList = new ArrayList<>();
    List<Long> saleOrderIdList = new ArrayList<>();
    boolean fromPopup = false;
    String lineToMerge;
    if (request.getContext().get("saleQuotationToMerge") != null) {
        lineToMerge = "saleQuotationToMerge";
    } else {
        lineToMerge = "saleOrderToMerge";
    }
    if (request.getContext().get(lineToMerge) != null) {
        if (request.getContext().get(lineToMerge) instanceof List) {
            // No confirmation popup, sale orders are content in a parameter list
            List<Map> saleOrderMap = (List<Map>) request.getContext().get(lineToMerge);
            for (Map map : saleOrderMap) {
                saleOrderIdList.add(new Long((Integer) map.get("id")));
            }
        } else {
            // After confirmation popup, sale order's id are in a string separated by ","
            String saleOrderIdListStr = (String) request.getContext().get(lineToMerge);
            for (String saleOrderId : saleOrderIdListStr.split(",")) {
                saleOrderIdList.add(new Long(saleOrderId));
            }
            fromPopup = true;
        }
    }
    // Check if currency, clientPartner and company are the same for all selected
    // sale orders
    Currency commonCurrency = null;
    Partner commonClientPartner = null;
    Company commonCompany = null;
    Partner commonContactPartner = null;
    Team commonTeam = null;
    // Useful to determine if a difference exists between teams of all sale orders
    boolean existTeamDiff = false;
    // Useful to determine if a difference exists between contact partners of all
    // sale orders
    boolean existContactPartnerDiff = false;
    PriceList commonPriceList = null;
    // Useful to determine if a difference exists between price lists of all sale
    // orders
    boolean existPriceListDiff = false;
    StockLocation commonLocation = null;
    // Useful to determine if a difference exists between stock locations of all
    // sale orders
    boolean existLocationDiff = false;
    SaleOrder saleOrderTemp;
    int count = 1;
    for (Long saleOrderId : saleOrderIdList) {
        saleOrderTemp = JPA.em().find(SaleOrder.class, saleOrderId);
        saleOrderList.add(saleOrderTemp);
        if (count == 1) {
            commonCurrency = saleOrderTemp.getCurrency();
            commonClientPartner = saleOrderTemp.getClientPartner();
            commonCompany = saleOrderTemp.getCompany();
            commonContactPartner = saleOrderTemp.getContactPartner();
            commonTeam = saleOrderTemp.getTeam();
            commonPriceList = saleOrderTemp.getPriceList();
            commonLocation = saleOrderTemp.getStockLocation();
        } else {
            if (commonCurrency != null && !commonCurrency.equals(saleOrderTemp.getCurrency())) {
                commonCurrency = null;
            }
            if (commonClientPartner != null && !commonClientPartner.equals(saleOrderTemp.getClientPartner())) {
                commonClientPartner = null;
            }
            if (commonCompany != null && !commonCompany.equals(saleOrderTemp.getCompany())) {
                commonCompany = null;
            }
            if (commonContactPartner != null && !commonContactPartner.equals(saleOrderTemp.getContactPartner())) {
                commonContactPartner = null;
                existContactPartnerDiff = true;
            }
            if (commonTeam != null && !commonTeam.equals(saleOrderTemp.getTeam())) {
                commonTeam = null;
                existTeamDiff = true;
            }
            if (commonPriceList != null && !commonPriceList.equals(saleOrderTemp.getPriceList())) {
                commonPriceList = null;
                existPriceListDiff = true;
            }
            if (commonLocation != null && !commonLocation.equals(saleOrderTemp.getStockLocation())) {
                commonLocation = null;
                existLocationDiff = true;
            }
        }
        count++;
    }
    StringBuilder fieldErrors = new StringBuilder();
    if (commonCurrency == null) {
        fieldErrors.append(I18n.get(com.axelor.apps.sale.exception.IExceptionMessage.SALE_ORDER_MERGE_ERROR_CURRENCY));
    }
    if (commonClientPartner == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(com.axelor.apps.sale.exception.IExceptionMessage.SALE_ORDER_MERGE_ERROR_CLIENT_PARTNER));
    }
    if (commonCompany == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(com.axelor.apps.sale.exception.IExceptionMessage.SALE_ORDER_MERGE_ERROR_COMPANY));
    }
    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 (request.getContext().get("team") != null) {
        commonTeam = JPA.em().find(Team.class, new Long((Integer) ((Map) request.getContext().get("team")).get("id")));
    }
    if (request.getContext().get("stockLocation") != null) {
        commonLocation = JPA.em().find(StockLocation.class, new Long((Integer) ((Map) request.getContext().get("stockLocation")).get("id")));
    }
    if (!fromPopup && (existContactPartnerDiff || existPriceListDiff || existTeamDiff)) {
        // Need to display intermediate screen to select some values
        ActionViewBuilder confirmView = ActionView.define("Confirm merge sale order").model(Wizard.class.getName()).add("form", "sale-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", commonClientPartner.getId().toString());
        }
        if (existTeamDiff) {
            confirmView.context("contextTeamToCheck", "true");
        }
        if (existLocationDiff) {
            confirmView.context("contextLocationToCheck", "true");
        }
        confirmView.context(lineToMerge, Joiner.on(",").join(saleOrderIdList));
        response.setView(confirmView.map());
        return;
    }
    try {
        SaleOrder saleOrder = Beans.get(SaleOrderCreateServiceSupplychainImpl.class).mergeSaleOrders(saleOrderList, commonCurrency, commonClientPartner, commonCompany, commonLocation, commonContactPartner, commonPriceList, commonTeam);
        if (saleOrder != null) {
            // Open the generated sale order in a new tab
            response.setView(ActionView.define("Sale order").model(SaleOrder.class.getName()).add("grid", "sale-order-grid").add("form", "sale-order-form").param("search-filters", "sale-order-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(saleOrder.getId())).map());
            response.setCanClose(true);
        }
    } catch (Exception e) {
        response.setFlash(e.getLocalizedMessage());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) SaleOrder(com.axelor.apps.sale.db.SaleOrder) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) SaleOrderCreateServiceSupplychainImpl(com.axelor.apps.supplychain.service.SaleOrderCreateServiceSupplychainImpl) Currency(com.axelor.apps.base.db.Currency) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) Team(com.axelor.team.db.Team) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) Wizard(com.axelor.apps.base.db.Wizard)

Example 38 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class SaleOrderController method showPopUpInvoicingWizard.

public void showPopUpInvoicingWizard(ActionRequest request, ActionResponse response) {
    try {
        SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
        saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrder.getId());
        Beans.get(SaleOrderInvoiceService.class).displayErrorMessageBtnGenerateInvoice(saleOrder);
        response.setView(ActionView.define("Invoicing").model(SaleOrder.class.getName()).add("form", "sale-order-invoicing-wizard-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true").context("_showRecord", String.valueOf(saleOrder.getId())).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : SaleOrderInvoiceService(com.axelor.apps.supplychain.service.SaleOrderInvoiceService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AxelorException(com.axelor.exception.AxelorException)

Example 39 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class SaleOrderController method createShipmentCostLine.

public void createShipmentCostLine(ActionRequest request, ActionResponse response) {
    try {
        SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
        String message = Beans.get(SaleOrderSupplychainService.class).createShipmentCostLine(saleOrder);
        if (message != null) {
            response.setFlash(message);
        }
        response.setValues(saleOrder);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : SaleOrderSupplychainService(com.axelor.apps.supplychain.service.SaleOrderSupplychainService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AxelorException(com.axelor.exception.AxelorException)

Example 40 with SaleOrder

use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.

the class SaleOrderController method reserveAll.

/**
 * Called from the toolbar in sale order form view. Call {@link
 * com.axelor.apps.supplychain.service.SaleOrderReservedQtyService#reserveAll(SaleOrder)}.
 *
 * @param request
 * @param response
 */
public void reserveAll(ActionRequest request, ActionResponse response) {
    try {
        SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
        saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrder.getId());
        Beans.get(SaleOrderReservedQtyService.class).reserveAll(saleOrder);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : SaleOrderReservedQtyService(com.axelor.apps.supplychain.service.SaleOrderReservedQtyService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AxelorException(com.axelor.exception.AxelorException)

Aggregations

SaleOrder (com.axelor.apps.sale.db.SaleOrder)129 AxelorException (com.axelor.exception.AxelorException)53 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)35 BigDecimal (java.math.BigDecimal)24 Context (com.axelor.rpc.Context)20 Transactional (com.google.inject.persist.Transactional)19 ArrayList (java.util.ArrayList)19 SaleOrderRepository (com.axelor.apps.sale.db.repo.SaleOrderRepository)18 Company (com.axelor.apps.base.db.Company)16 Partner (com.axelor.apps.base.db.Partner)15 IOException (java.io.IOException)13 BirtException (org.eclipse.birt.core.exception.BirtException)13 Invoice (com.axelor.apps.account.db.Invoice)12 List (java.util.List)12 Currency (com.axelor.apps.base.db.Currency)11 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)10 LinkedHashMap (java.util.LinkedHashMap)10 Map (java.util.Map)9 Product (com.axelor.apps.base.db.Product)8 StockMove (com.axelor.apps.stock.db.StockMove)8