Search in sources :

Example 96 with SaleOrderLine

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

the class ConfiguratorServiceImpl method addLineToSaleOrder.

@Transactional(rollbackOn = { Exception.class })
@Override
public void addLineToSaleOrder(Configurator configurator, SaleOrder saleOrder, JsonContext jsonAttributes, JsonContext jsonIndicators) throws AxelorException {
    SaleOrderLine saleOrderLine;
    if (configurator.getConfiguratorCreator().getGenerateProduct()) {
        // generate sale order line from product
        saleOrderLine = new SaleOrderLine();
        saleOrderLine.setSaleOrder(saleOrder);
        generate(configurator, jsonAttributes, jsonIndicators);
        saleOrderLine.setProduct(configurator.getProduct());
        this.fillSaleOrderWithProduct(saleOrderLine);
        Beans.get(SaleOrderLineService.class).computeValues(saleOrderLine.getSaleOrder(), saleOrderLine);
        String qtyFormula = configurator.getConfiguratorCreator().getQtyFormula();
        BigDecimal qty = BigDecimal.ONE;
        if (qtyFormula != null && !"".equals(qtyFormula)) {
            Object result = computeFormula(qtyFormula, jsonAttributes);
            if (result != null) {
                qty = new BigDecimal(result.toString());
            }
        }
        saleOrderLine.setQty(qty);
        Beans.get(SaleOrderLineRepository.class).save(saleOrderLine);
    } else {
        generateSaleOrderLine(configurator, jsonAttributes, jsonIndicators, saleOrder);
    }
    Beans.get(SaleOrderComputeService.class).computeSaleOrder(saleOrder);
    Beans.get(SaleOrderRepository.class).save(saleOrder);
}
Also used : SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrderComputeService(com.axelor.apps.sale.service.saleorder.SaleOrderComputeService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 97 with SaleOrderLine

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

the class ConfiguratorServiceImpl method generateSaleOrderLine.

/**
 * Create a sale order line from the configurator
 *
 * @param configurator
 * @param jsonAttributes
 * @param jsonIndicators
 * @param saleOrder
 * @return
 */
protected SaleOrderLine generateSaleOrderLine(Configurator configurator, JsonContext jsonAttributes, JsonContext jsonIndicators, SaleOrder saleOrder) throws AxelorException {
    cleanIndicators(jsonIndicators);
    SaleOrderLine saleOrderLine = Mapper.toBean(SaleOrderLine.class, jsonIndicators);
    saleOrderLine.setSaleOrder(saleOrder);
    fixRelationalFields(saleOrderLine);
    fetchManyToManyFields(saleOrderLine);
    fillOneToManyFields(configurator, saleOrderLine, jsonAttributes);
    this.fillSaleOrderWithProduct(saleOrderLine);
    this.overwriteFieldToUpdate(configurator, saleOrderLine, jsonAttributes);
    if (saleOrderLine.getProductName() == null) {
        throw new AxelorException(configurator, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.CONFIGURATOR_SALE_ORDER_LINE_MISSING_PRODUCT_NAME));
    }
    saleOrderLine = Beans.get(SaleOrderLineRepository.class).save(saleOrderLine);
    Beans.get(SaleOrderLineService.class).computeValues(saleOrderLine.getSaleOrder(), saleOrderLine);
    return saleOrderLine;
}
Also used : AxelorException(com.axelor.exception.AxelorException) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 98 with SaleOrderLine

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

the class SaleOrderManagementRepository method copy.

@Override
public SaleOrder copy(SaleOrder entity, boolean deep) {
    SaleOrder copy = super.copy(entity, deep);
    copy.setStatusSelect(SaleOrderRepository.STATUS_DRAFT_QUOTATION);
    copy.setSaleOrderSeq(null);
    copy.clearBatchSet();
    copy.setImportId(null);
    copy.setCreationDate(Beans.get(AppBaseService.class).getTodayDate(entity.getCompany()));
    copy.setConfirmationDateTime(null);
    copy.setConfirmedByUser(null);
    copy.setOrderDate(null);
    copy.setOrderNumber(null);
    copy.setVersionNumber(1);
    copy.setTotalCostPrice(null);
    copy.setTotalGrossMargin(null);
    copy.setMarginRate(null);
    copy.setEndOfValidityDate(null);
    copy.setDeliveryDate(null);
    copy.setOrderBeingEdited(false);
    if (copy.getAdvancePaymentAmountNeeded().compareTo(copy.getAdvanceTotal()) <= 0) {
        copy.setAdvancePaymentAmountNeeded(BigDecimal.ZERO);
        copy.setAdvancePaymentNeeded(false);
        copy.clearAdvancePaymentList();
    }
    if (copy.getSaleOrderLineList() != null) {
        for (SaleOrderLine saleOrderLine : copy.getSaleOrderLineList()) {
            saleOrderLine.setDesiredDelivDate(null);
            saleOrderLine.setEstimatedDelivDate(null);
            saleOrderLine.setDiscountDerogation(null);
        }
    }
    return copy;
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 99 with SaleOrderLine

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

the class ABCAnalysisServiceSaleImpl method createABCAnalysisLine.

@Override
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
    ABCAnalysisLine abcAnalysisLine = null;
    BigDecimal productQty = BigDecimal.ZERO;
    BigDecimal productWorth = BigDecimal.ZERO;
    List<SaleOrderLine> saleOrderLineList;
    int offset = 0;
    Query<SaleOrderLine> saleOrderLineQuery = saleOrderLineRepository.all().filter("(self.saleOrder.statusSelect = :statusConfirmed OR self.saleOrder.statusSelect = :statusCompleted) AND self.saleOrder.confirmationDateTime >= :startDate AND self.saleOrder.confirmationDateTime <= :endDate AND self.product.id = :productId").bind("statusConfirmed", SaleOrderRepository.STATUS_ORDER_CONFIRMED).bind("statusCompleted", SaleOrderRepository.STATUS_ORDER_COMPLETED).bind("startDate", toLocalDateT(toDate(abcAnalysis.getStartDate()))).bind("endDate", toLocalDateT(toDate(abcAnalysis.getEndDate())).withHour(23).withMinute(59).withSecond(59)).bind("productId", product.getId()).order("id");
    while (!(saleOrderLineList = saleOrderLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
        offset += saleOrderLineList.size();
        abcAnalysis = abcAnalysisRepository.find(abcAnalysis.getId());
        if (abcAnalysisLine == null) {
            abcAnalysisLine = super.createABCAnalysisLine(abcAnalysis, product).get();
        }
        for (SaleOrderLine saleOrderLine : saleOrderLineList) {
            BigDecimal convertedQty = unitConversionService.convert(saleOrderLine.getUnit(), product.getUnit(), saleOrderLine.getQty(), 5, product);
            productQty = productQty.add(convertedQty);
            productWorth = productWorth.add(saleOrderLine.getCompanyExTaxTotal());
        }
        super.incTotalQty(productQty);
        super.incTotalWorth(productWorth);
        JPA.clear();
    }
    if (abcAnalysisLine != null) {
        setQtyWorth(abcAnalysisLineRepository.find(abcAnalysisLine.getId()), productQty, productWorth);
    }
    return Optional.ofNullable(abcAnalysisLine);
}
Also used : ABCAnalysisLine(com.axelor.apps.base.db.ABCAnalysisLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Example 100 with SaleOrderLine

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

the class SaleOrderServiceSupplychainImpl method createShippingCostLine.

@Override
public SaleOrderLine createShippingCostLine(SaleOrder saleOrder, Product shippingCostProduct) throws AxelorException {
    SaleOrderLine shippingCostLine = new SaleOrderLine();
    shippingCostLine.setSaleOrder(saleOrder);
    shippingCostLine.setProduct(shippingCostProduct);
    SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
    saleOrderLineService.computeProductInformation(shippingCostLine, saleOrder);
    saleOrderLineService.computeValues(saleOrder, shippingCostLine);
    return shippingCostLine;
}
Also used : SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

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