Search in sources :

Example 11 with SaleOrderLine

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

the class SaleOrderComputeServiceSupplychainImpl method _computeSaleOrder.

@Override
public void _computeSaleOrder(SaleOrder saleOrder) throws AxelorException {
    super._computeSaleOrder(saleOrder);
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return;
    }
    int maxDelay = 0;
    if (saleOrder.getSaleOrderLineList() != null && !saleOrder.getSaleOrderLineList().isEmpty()) {
        for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
            if ((saleOrderLine.getSaleSupplySelect() == SaleOrderLineRepository.SALE_SUPPLY_PRODUCE || saleOrderLine.getSaleSupplySelect() == SaleOrderLineRepository.SALE_SUPPLY_PURCHASE)) {
                maxDelay = Integer.max(maxDelay, saleOrderLine.getStandardDelay() == null ? 0 : saleOrderLine.getStandardDelay());
            }
        }
    }
    saleOrder.setStandardDelay(maxDelay);
    if (Beans.get(AppAccountService.class).getAppAccount().getManageAdvancePaymentInvoice()) {
        saleOrder.setAdvanceTotal(computeTotalInvoiceAdvancePayment(saleOrder));
    }
    Beans.get(SaleOrderServiceSupplychainImpl.class).updateAmountToBeSpreadOverTheTimetable(saleOrder);
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 12 with SaleOrderLine

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

the class SaleOrderLineServiceSupplyChainImpl method createSaleOrderLine.

@Override
public SaleOrderLine createSaleOrderLine(PackLine packLine, SaleOrder saleOrder, BigDecimal packQty, BigDecimal conversionRate, Integer sequence) {
    SaleOrderLine soLine = super.createSaleOrderLine(packLine, saleOrder, packQty, conversionRate, sequence);
    if (soLine != null && soLine.getProduct() != null) {
        soLine.setSaleSupplySelect(soLine.getProduct().getSaleSupplySelect());
        getAndComputeAnalyticDistribution(soLine, saleOrder);
        if (ObjectUtils.notEmpty(soLine.getAnalyticMoveLineList())) {
            soLine.getAnalyticMoveLineList().stream().forEach(analyticMoveLine -> analyticMoveLine.setSaleOrderLine(soLine));
        }
        try {
            SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(saleOrder.getCompany());
            if (supplyChainConfig.getAutoRequestReservedQty()) {
                Beans.get(ReservedQtyService.class).requestQty(soLine);
            }
        } catch (AxelorException e) {
            TraceBackService.trace(e);
        }
    }
    return soLine;
}
Also used : AxelorException(com.axelor.exception.AxelorException) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 13 with SaleOrderLine

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

the class SaleOrderPurchaseServiceImpl method createPurchaseOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public PurchaseOrder createPurchaseOrder(Partner supplierPartner, List<SaleOrderLine> saleOrderLineList, SaleOrder saleOrder) throws AxelorException {
    LOG.debug("Création d'une commande fournisseur pour le devis client : {}", saleOrder.getSaleOrderSeq());
    PurchaseOrder purchaseOrder = purchaseOrderSupplychainService.createPurchaseOrder(AuthUtils.getUser(), saleOrder.getCompany(), supplierPartner.getContactPartnerSet().size() == 1 ? supplierPartner.getContactPartnerSet().iterator().next() : null, supplierPartner.getCurrency(), null, saleOrder.getSaleOrderSeq(), saleOrder.getExternalReference(), saleOrder.getDirectOrderLocation() ? saleOrder.getStockLocation() : Beans.get(StockLocationService.class).getDefaultReceiptStockLocation(saleOrder.getCompany()), Beans.get(AppBaseService.class).getTodayDate(saleOrder.getCompany()), Beans.get(PartnerPriceListService.class).getDefaultPriceList(supplierPartner, PriceListRepository.TYPE_PURCHASE), supplierPartner, saleOrder.getTradingName());
    purchaseOrder.setGeneratedSaleOrderId(saleOrder.getId());
    purchaseOrder.setGroupProductsOnPrintings(supplierPartner.getGroupProductsOnPrintings());
    Integer atiChoice = Beans.get(PurchaseConfigService.class).getPurchaseConfig(saleOrder.getCompany()).getPurchaseOrderInAtiSelect();
    if (atiChoice == AccountConfigRepository.INVOICE_ATI_ALWAYS || atiChoice == AccountConfigRepository.INVOICE_ATI_DEFAULT) {
        purchaseOrder.setInAti(true);
    } else {
        purchaseOrder.setInAti(false);
    }
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLineServiceSupplychain.createPurchaseOrderLine(purchaseOrder, saleOrderLine));
    }
    purchaseOrderService.computePurchaseOrder(purchaseOrder);
    purchaseOrder.setNotes(supplierPartner.getPurchaseOrderComments());
    Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
    return purchaseOrder;
}
Also used : StockLocationService(com.axelor.apps.stock.service.StockLocationService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) Transactional(com.google.inject.persist.Transactional)

Example 14 with SaleOrderLine

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

the class MrpServiceImpl method createSaleOrderMrpLines.

protected void createSaleOrderMrpLines() throws AxelorException {
    MrpLineType saleOrderMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_SALE_ORDER);
    if (saleOrderMrpLineType == null) {
        return;
    }
    String statusSelect = saleOrderMrpLineType.getStatusSelect();
    List<Integer> statusList = StringTool.getIntegerList(statusSelect);
    List<SaleOrderLine> saleOrderLineList = new ArrayList<>();
    mrp = mrpRepository.find(mrp.getId());
    if (mrp.getSaleOrderLineSet().isEmpty()) {
        saleOrderLineList.addAll(saleOrderLineRepository.all().filter("self.product.id in (?1) AND self.saleOrder.stockLocation in (?2) AND self.deliveryState != ?3 " + "AND self.saleOrder.statusSelect IN (?4)", this.productMap.keySet(), this.stockLocationList, SaleOrderLineRepository.DELIVERY_STATE_DELIVERED, statusList).fetch());
    } else {
        saleOrderLineList.addAll(mrp.getSaleOrderLineSet());
    }
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        this.createSaleOrderMrpLines(mrpRepository.find(mrp.getId()), saleOrderLineRepository.find(saleOrderLine.getId()), mrpLineTypeRepository.find(saleOrderMrpLineType.getId()), statusList);
        JPA.clear();
    }
}
Also used : ArrayList(java.util.ArrayList) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 15 with SaleOrderLine

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

the class ReservedQtyServiceImpl method updateReservedQuantityFromStockMoveLine.

@Override
public void updateReservedQuantityFromStockMoveLine(StockMoveLine stockMoveLine, Product product, BigDecimal reservedQtyToAdd) throws AxelorException {
    if (product == null || !product.getStockManaged()) {
        return;
    }
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    stockMoveLine.setReservedQty(stockMoveLine.getReservedQty().add(reservedQtyToAdd));
    if (saleOrderLine != null) {
        updateReservedQty(saleOrderLine);
    }
}
Also used : 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