Search in sources :

Example 66 with SaleOrderLine

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

the class SaleOrderPurchaseServiceImpl method splitBySupplierPartner.

@Override
public Map<Partner, List<SaleOrderLine>> splitBySupplierPartner(List<SaleOrderLine> saleOrderLineList) throws AxelorException {
    Map<Partner, List<SaleOrderLine>> saleOrderLinesBySupplierPartner = new HashMap<>();
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        if (saleOrderLine.getSaleSupplySelect() == ProductRepository.SALE_SUPPLY_PURCHASE) {
            Partner supplierPartner = saleOrderLine.getSupplierPartner();
            if (supplierPartner == null) {
                throw new AxelorException(saleOrderLine, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_PURCHASE_1), saleOrderLine.getProductName());
            }
            if (!saleOrderLinesBySupplierPartner.containsKey(supplierPartner)) {
                saleOrderLinesBySupplierPartner.put(supplierPartner, new ArrayList<SaleOrderLine>());
            }
            saleOrderLinesBySupplierPartner.get(supplierPartner).add(saleOrderLine);
        }
    }
    return saleOrderLinesBySupplierPartner;
}
Also used : AxelorException(com.axelor.exception.AxelorException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Partner(com.axelor.apps.base.db.Partner)

Example 67 with SaleOrderLine

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

the class ReservedQtyServiceImpl method requestQty.

@Override
@Transactional(rollbackOn = { Exception.class })
public void requestQty(StockMoveLine stockMoveLine) throws AxelorException {
    if (stockMoveLine.getProduct() == null || !stockMoveLine.getProduct().getStockManaged()) {
        return;
    }
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    if (saleOrderLine != null) {
        requestQty(saleOrderLine);
    } else {
        stockMoveLine.setReservationDateTime(appBaseService.getTodayDateTime().toLocalDateTime());
        stockMoveLine.setIsQtyRequested(true);
        if (stockMoveLine.getQty().signum() < 0) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_REQUEST_QTY_NEGATIVE));
        }
        this.updateRequestedReservedQty(stockMoveLine, stockMoveLine.getQty());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Transactional(com.google.inject.persist.Transactional)

Example 68 with SaleOrderLine

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

the class SaleOrderSupplychainRepository method copy.

@Override
public SaleOrder copy(SaleOrder entity, boolean deep) {
    SaleOrder copy = super.copy(entity, deep);
    if (!Beans.get(AppService.class).isApp("supplychain")) {
        return copy;
    }
    copy.setShipmentDate(null);
    copy.setDeliveryState(DELIVERY_STATE_NOT_DELIVERED);
    copy.setAmountInvoiced(null);
    copy.setStockMoveList(null);
    if (copy.getSaleOrderLineList() != null) {
        for (SaleOrderLine saleOrderLine : copy.getSaleOrderLineList()) {
            saleOrderLine.setDeliveryState(null);
            saleOrderLine.setDeliveredQty(null);
            saleOrderLine.setAmountInvoiced(null);
            saleOrderLine.setInvoiced(null);
            saleOrderLine.setInvoicingDate(null);
            saleOrderLine.setIsInvoiceControlled(null);
            saleOrderLine.setReservedQty(BigDecimal.ZERO);
        }
    }
    return copy;
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 69 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine 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)

Example 70 with SaleOrderLine

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

the class SaleOrderLineController method fillMaxDiscount.

/**
 * Called from sale order line form view on load and on discount type select change. Call {@link
 * SaleOrderLineService#computeMaxDiscount} and set the message to the view.
 *
 * @param request
 * @param response
 */
public void fillMaxDiscount(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);
        BigDecimal maxDiscount = saleOrderLineService.computeMaxDiscount(saleOrder, saleOrderLine);
        response.setValue("$maxDiscount", maxDiscount);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

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