Search in sources :

Example 1 with PartnerPriceListService

use of com.axelor.apps.base.service.PartnerPriceListService in project axelor-open-suite by axelor.

the class SaleOrderController method fillPriceList.

/**
 * Called from sale order form view on partner change. Get the default price list for the sale
 * order. Call {@link PartnerPriceListService#getDefaultPriceList(Partner, int)}.
 *
 * @param request
 * @param response
 */
@SuppressWarnings("unchecked")
public void fillPriceList(ActionRequest request, ActionResponse response) {
    SaleOrder saleOrder;
    if (request.getContext().get("_saleOrderTemplate") != null) {
        LinkedHashMap<String, Object> saleOrderTemplateContext = (LinkedHashMap<String, Object>) request.getContext().get("_saleOrderTemplate");
        Integer saleOrderId = (Integer) saleOrderTemplateContext.get("id");
        saleOrder = Beans.get(SaleOrderRepository.class).find(Long.valueOf(saleOrderId));
    } else {
        saleOrder = request.getContext().asType(SaleOrder.class);
    }
    response.setValue("priceList", saleOrder.getClientPartner() != null ? Beans.get(PartnerPriceListService.class).getDefaultPriceList(saleOrder.getClientPartner(), PriceListRepository.TYPE_SALE) : null);
}
Also used : PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with PartnerPriceListService

use of com.axelor.apps.base.service.PartnerPriceListService in project axelor-open-suite by axelor.

the class InvoiceController method changePriceListDomain.

/**
 * Called from invoice view on price list select. Call {@link
 * PartnerPriceListService#getPriceListDomain(Partner, int)}.
 *
 * @param request
 * @param response
 */
public void changePriceListDomain(ActionRequest request, ActionResponse response) {
    try {
        Invoice invoice = request.getContext().asType(Invoice.class);
        int priceListTypeSelect = Beans.get(InvoiceService.class).getPurchaseTypeOrSaleType(invoice);
        String domain = Beans.get(PartnerPriceListService.class).getPriceListDomain(invoice.getPartner(), priceListTypeSelect);
        response.setAttr("priceList", "domain", domain);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) AxelorException(com.axelor.exception.AxelorException)

Example 3 with PartnerPriceListService

use of com.axelor.apps.base.service.PartnerPriceListService in project axelor-open-suite by axelor.

the class PartnerPriceListController method checkDates.

/**
 * Called from partner price list form view call {@link
 * PartnerPriceListService#checkDates(PartnerPriceList)} return a warning with the response if
 * dates validation fails for the price list set.
 *
 * @param request
 * @param response
 */
public void checkDates(ActionRequest request, ActionResponse response) {
    PartnerPriceList partnerPriceList;
    Class partnerOrPriceLists = request.getContext().getContextClass();
    if (partnerOrPriceLists.equals(Partner.class)) {
        partnerPriceList = request.getContext().asType(Partner.class).getSalePartnerPriceList();
    } else if (partnerOrPriceLists.equals(PartnerPriceList.class)) {
        partnerPriceList = request.getContext().asType(PartnerPriceList.class);
    } else {
        return;
    }
    try {
        Beans.get(PartnerPriceListService.class).checkDates(partnerPriceList);
    } catch (Exception e) {
        response.setAlert(e.getMessage());
    }
}
Also used : PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) PartnerPriceList(com.axelor.apps.base.db.PartnerPriceList)

Example 4 with PartnerPriceListService

use of com.axelor.apps.base.service.PartnerPriceListService in project axelor-open-suite by axelor.

the class SaleOrderController method changePriceListDomain.

/**
 * Called from sale order view on price list select. Call {@link
 * PartnerPriceListService#getPriceListDomain(Partner, int)}.
 *
 * @param request
 * @param response
 */
@SuppressWarnings("unchecked")
public void changePriceListDomain(ActionRequest request, ActionResponse response) {
    SaleOrder saleOrder;
    if (request.getContext().get("_saleOrderTemplate") != null) {
        LinkedHashMap<String, Object> saleOrderTemplateContext = (LinkedHashMap<String, Object>) request.getContext().get("_saleOrderTemplate");
        Integer saleOrderId = (Integer) saleOrderTemplateContext.get("id");
        saleOrder = Beans.get(SaleOrderRepository.class).find(Long.valueOf(saleOrderId));
    } else {
        saleOrder = request.getContext().asType(SaleOrder.class);
    }
    String domain = Beans.get(PartnerPriceListService.class).getPriceListDomain(saleOrder.getClientPartner(), PriceListRepository.TYPE_SALE);
    response.setAttr("priceList", "domain", domain);
}
Also used : PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PartnerPriceListService (com.axelor.apps.base.service.PartnerPriceListService)4 SaleOrder (com.axelor.apps.sale.db.SaleOrder)2 LinkedHashMap (java.util.LinkedHashMap)2 Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)1 PartnerPriceList (com.axelor.apps.base.db.PartnerPriceList)1 AxelorException (com.axelor.exception.AxelorException)1