Search in sources :

Example 26 with SaleOrderLine

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

the class SaleOrderLineServiceImpl method getSaleOrder.

@Override
public SaleOrder getSaleOrder(Context context) {
    Context parentContext = context.getParent();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    if (parentContext != null && !parentContext.getContextClass().equals(SaleOrder.class)) {
        parentContext = parentContext.getParent();
    }
    if (parentContext != null && parentContext.getContextClass().equals(SaleOrder.class)) {
        saleOrder = parentContext.asType(SaleOrder.class);
    }
    return saleOrder;
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 27 with SaleOrderLine

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

the class SaleOrderServiceImpl method updateProductQtyWithPackHeaderQty.

@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder updateProductQtyWithPackHeaderQty(SaleOrder saleOrder) throws AxelorException {
    List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
    boolean isStartOfPack = false;
    BigDecimal newQty = BigDecimal.ZERO;
    BigDecimal oldQty = BigDecimal.ZERO;
    this.sortSaleOrderLineList(saleOrder);
    for (SaleOrderLine SOLine : saleOrderLineList) {
        if (SOLine.getTypeSelect() == SaleOrderLineRepository.TYPE_START_OF_PACK && !isStartOfPack) {
            newQty = SOLine.getQty();
            oldQty = saleOrderLineRepo.find(SOLine.getId()).getQty();
            if (newQty.compareTo(oldQty) != 0) {
                isStartOfPack = true;
                SOLine = EntityHelper.getEntity(SOLine);
                saleOrderLineRepo.save(SOLine);
            }
        } else if (isStartOfPack) {
            if (SOLine.getTypeSelect() == SaleOrderLineRepository.TYPE_END_OF_PACK) {
                break;
            }
            saleOrderLineService.updateProductQty(SOLine, saleOrder, oldQty, newQty);
        }
    }
    return saleOrder;
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 28 with SaleOrderLine

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

the class SaleOrderLineSaleRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    if (context.get("_model") != null && context.get("_model").toString().contains("SaleOrder") && context.get("id") != null) {
        Long id = (Long) json.get("id");
        if (id != null) {
            SaleOrderLine saleOrderLine = find(id);
            json.put("$hasWarning", saleOrderLine.getSaleOrder() != null && (saleOrderLine.getSaleOrder().getStatusSelect() == SaleOrderRepository.STATUS_DRAFT_QUOTATION || (saleOrderLine.getSaleOrder().getStatusSelect() == SaleOrderRepository.STATUS_ORDER_CONFIRMED && saleOrderLine.getSaleOrder().getOrderBeingEdited())) && saleOrderLine.getDiscountsNeedReview());
        }
    }
    return super.populate(json, context);
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 29 with SaleOrderLine

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

the class SaleOrderLineController method cancelReservation.

/**
 * Called from sale order line form view, on request qty click. Call {@link
 * ReservedQtyService#cancelReservation(SaleOrderLine)}
 *
 * @param request
 * @param response
 */
public void cancelReservation(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).cancelReservation(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 30 with SaleOrderLine

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

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