Search in sources :

Example 31 with SaleOrderLine

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

the class SaleOrderLineController method changeReservedQty.

/**
 * Called from sale order line request quantity wizard view. Call {@link
 * ReservedQtyService#updateReservedQty(SaleOrderLine, BigDecimal)}.
 *
 * @param request
 * @param response
 */
public void changeReservedQty(ActionRequest request, ActionResponse response) {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    BigDecimal newReservedQty = saleOrderLine.getReservedQty();
    try {
        saleOrderLine = Beans.get(SaleOrderLineRepository.class).find(saleOrderLine.getId());
        Product product = saleOrderLine.getProduct();
        if (product == null || !product.getStockManaged()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
        }
        Beans.get(ReservedQtyService.class).updateReservedQty(saleOrderLine, newReservedQty);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 32 with SaleOrderLine

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

the class SaleOrderLineController method changeRequestedReservedQty.

public void changeRequestedReservedQty(ActionRequest request, ActionResponse response) {
    SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
    BigDecimal newReservedQty = saleOrderLine.getRequestedReservedQty();
    try {
        saleOrderLine = Beans.get(SaleOrderLineRepository.class).find(saleOrderLine.getId());
        Beans.get(ReservedQtyService.class).updateRequestedReservedQty(saleOrderLine, newReservedQty);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 33 with SaleOrderLine

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

the class SaleOrderLineController method deallocateAll.

/**
 * Called from sale order form view, on clicking deallocate button on one sale order line. Call
 * {@link ReservedQtyService#updateReservedQty(SaleOrderLine, BigDecimal.ZERO)}.
 *
 * @param request
 * @param response
 */
public void deallocateAll(ActionRequest request, ActionResponse response) {
    try {
        SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
        saleOrderLine = Beans.get(SaleOrderLineRepository.class).find(saleOrderLine.getId());
        Beans.get(ReservedQtyService.class).updateReservedQty(saleOrderLine, BigDecimal.ZERO);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AxelorException(com.axelor.exception.AxelorException)

Example 34 with SaleOrderLine

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

the class SaleOrderLineController method allocateAll.

/**
 * Called from sale order form view, on clicking allocateAll button on one sale order line. Call
 * {@link ReservedQtyService#allocateAll(SaleOrderLine)}.
 *
 * @param request
 * @param response
 */
public void allocateAll(ActionRequest request, ActionResponse response) {
    try {
        SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
        saleOrderLine = Beans.get(SaleOrderLineRepository.class).find(saleOrderLine.getId());
        Product product = saleOrderLine.getProduct();
        if (product == null || !product.getStockManaged()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
        }
        Beans.get(ReservedQtyService.class).allocateAll(saleOrderLine);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AxelorException(com.axelor.exception.AxelorException)

Example 35 with SaleOrderLine

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

the class SaleOrderController method getSelectedId.

@SuppressWarnings("rawtypes")
private Map<String, Object> getSelectedId(ActionRequest request, ActionResponse response, SaleOrder saleOrder) throws AxelorException {
    Partner supplierPartner = null;
    List<Long> saleOrderLineIdSelected = new ArrayList<>();
    Map<String, Object> values = new HashMap<String, Object>();
    Boolean isDirectOrderLocation = false;
    Boolean noProduct = true;
    if (saleOrder.getDirectOrderLocation() && saleOrder.getStockLocation() != null && saleOrder.getStockLocation().getPartner() != null && saleOrder.getStockLocation().getPartner().getIsSupplier()) {
        values.put("supplierPartner", saleOrder.getStockLocation().getPartner());
        for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
            if (saleOrderLine.isSelected()) {
                if (saleOrderLine.getProduct() != null) {
                    noProduct = false;
                }
                saleOrderLineIdSelected.add(saleOrderLine.getId());
            }
        }
        values.put("saleOrderLineIdSelected", saleOrderLineIdSelected);
        isDirectOrderLocation = true;
        values.put("isDirectOrderLocation", isDirectOrderLocation);
        if (saleOrderLineIdSelected.isEmpty() || noProduct) {
            throw new AxelorException(3, I18n.get(IExceptionMessage.SO_LINE_PURCHASE_AT_LEAST_ONE));
        }
    } else if (request.getContext().get("supplierPartnerSelect") != null) {
        supplierPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("supplierPartnerSelect")).get("id")));
        values.put("supplierPartner", supplierPartner);
        String saleOrderLineIdSelectedStr = (String) request.getContext().get("saleOrderLineIdSelected");
        for (String saleOrderId : saleOrderLineIdSelectedStr.split(",")) {
            saleOrderLineIdSelected.add(new Long(saleOrderId));
        }
        values.put("saleOrderLineIdSelected", saleOrderLineIdSelected);
        values.put("isDirectOrderLocation", isDirectOrderLocation);
    }
    return values;
}
Also used : AxelorException(com.axelor.exception.AxelorException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Partner(com.axelor.apps.base.db.Partner)

Aggregations

SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)116 AxelorException (com.axelor.exception.AxelorException)41 BigDecimal (java.math.BigDecimal)39 SaleOrder (com.axelor.apps.sale.db.SaleOrder)33 ArrayList (java.util.ArrayList)24 Transactional (com.google.inject.persist.Transactional)23 Product (com.axelor.apps.base.db.Product)21 Context (com.axelor.rpc.Context)16 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)14 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)9 Partner (com.axelor.apps.base.db.Partner)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 Unit (com.axelor.apps.base.db.Unit)7 HashMap (java.util.HashMap)7 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)6 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 SaleOrderLineRepository (com.axelor.apps.sale.db.repo.SaleOrderLineRepository)6 ReservedQtyService (com.axelor.apps.supplychain.service.ReservedQtyService)6 List (java.util.List)6