Search in sources :

Example 76 with SaleOrder

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

the class SaleOrderController method validateChanges.

/**
 * Called from sale order form view, on clicking validate change button. Call {@link
 * SaleOrderService#validateChanges(SaleOrder)}.
 *
 * @param request
 * @param response
 */
public void validateChanges(ActionRequest request, ActionResponse response) {
    try {
        SaleOrder saleOrderView = request.getContext().asType(SaleOrder.class);
        SaleOrder saleOrder = Beans.get(SaleOrderRepository.class).find(saleOrderView.getId());
        Beans.get(SaleOrderService.class).validateChanges(saleOrder);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : SaleOrderService(com.axelor.apps.sale.service.saleorder.SaleOrderService) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 77 with SaleOrder

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

the class SaleOrderController method exportSaleOrder.

@SuppressWarnings("unchecked")
public void exportSaleOrder(ActionRequest request, ActionResponse response, boolean proforma, String format) {
    Context context = request.getContext();
    String fileLink;
    String title;
    SaleOrderPrintService saleOrderPrintService = Beans.get(SaleOrderPrintService.class);
    try {
        if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
            List<Long> ids = Lists.transform((List) request.getContext().get("_ids"), new Function<Object, Long>() {

                @Nullable
                @Override
                public Long apply(@Nullable Object input) {
                    return Long.parseLong(input.toString());
                }
            });
            fileLink = saleOrderPrintService.printSaleOrders(ids);
            title = I18n.get("Sale orders");
        } else if (context.get("id") != null) {
            SaleOrder saleOrder = Beans.get(SaleOrderRepository.class).find(Long.parseLong(context.get("id").toString()));
            title = Beans.get(SaleOrderService.class).getFileName(saleOrder);
            fileLink = saleOrderPrintService.printSaleOrder(saleOrder, proforma, format);
            response.setCanClose(true);
            logger.debug("Printing " + title);
        } else {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.SALE_ORDER_PRINT));
        }
        response.setView(ActionView.define(title).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderPrintService(com.axelor.apps.sale.service.saleorder.print.SaleOrderPrintService) AxelorException(com.axelor.exception.AxelorException) SaleOrderService(com.axelor.apps.sale.service.saleorder.SaleOrderService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 78 with SaleOrder

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

the class SaleOrderController method computeEndOfValidityDate.

public void computeEndOfValidityDate(ActionRequest request, ActionResponse response) {
    SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
    try {
        saleOrder = Beans.get(SaleOrderService.class).computeEndOfValidityDate(saleOrder);
        response.setValue("endOfValidityDate", saleOrder.getEndOfValidityDate());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 79 with SaleOrder

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

the class SaleOrderController method cancelSaleOrder.

public void cancelSaleOrder(ActionRequest request, ActionResponse response) {
    SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
    Beans.get(SaleOrderWorkflowService.class).cancelSaleOrder(Beans.get(SaleOrderRepository.class).find(saleOrder.getId()), saleOrder.getCancelReason(), saleOrder.getCancelReasonStr());
    response.setFlash(I18n.get("The sale order was canceled"));
    response.setCanClose(true);
}
Also used : SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 80 with SaleOrder

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

the class SaleOrderLineController method getProductInformation.

/**
 * Called by the sale order line form. Update all fields when the product is changed.
 *
 * @param request
 * @param response
 */
public void getProductInformation(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
        SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
        SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
        Product product = saleOrderLine.getProduct();
        if (saleOrder == null || product == null) {
            resetProductInformation(response, saleOrderLine);
            return;
        }
        try {
            product = Beans.get(ProductRepository.class).find(product.getId());
            saleOrderLineService.computeProductInformation(saleOrderLine, saleOrder);
            response.setValue("saleSupplySelect", product.getSaleSupplySelect());
            response.setValues(saleOrderLine);
        } catch (Exception e) {
            resetProductInformation(response, saleOrderLine);
            TraceBackService.trace(response, e);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) 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