Search in sources :

Example 51 with SaleOrderLine

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

the class SaleOrderStockServiceImpl method createStockMove.

protected Optional<StockMove> createStockMove(SaleOrder saleOrder, LocalDate estimatedDeliveryDate, List<SaleOrderLine> saleOrderLineList) throws AxelorException {
    StockMove stockMove = this.createStockMove(saleOrder, saleOrder.getCompany(), estimatedDeliveryDate);
    stockMove.setDeliveryCondition(saleOrder.getDeliveryCondition());
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        if (saleOrderLine.getProduct() != null) {
            BigDecimal qty = saleOrderLineServiceSupplyChain.computeUndeliveredQty(saleOrderLine);
            if (qty.signum() > 0 && !existActiveStockMoveForSaleOrderLine(saleOrderLine)) {
                createStockMoveLine(stockMove, saleOrderLine, qty);
            }
        }
    }
    if (stockMove.getStockMoveLineList() == null || stockMove.getStockMoveLineList().isEmpty()) {
        return Optional.empty();
    }
    if (stockMove.getStockMoveLineList().stream().noneMatch(stockMoveLine -> stockMoveLine.getSaleOrderLine() != null && stockMoveLine.getSaleOrderLine().getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL)) {
        stockMove.setFullySpreadOverLogisticalFormsFlag(true);
    }
    boolean isNeedingConformityCertificate = saleOrder.getIsNeedingConformityCertificate();
    stockMove.setIsNeedingConformityCertificate(isNeedingConformityCertificate);
    if (isNeedingConformityCertificate) {
        stockMove.setSignatoryUser(stockConfigService.getStockConfig(stockMove.getCompany()).getSignatoryUser());
    }
    SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(saleOrder.getCompany());
    if (supplychainConfig.getDefaultEstimatedDate() != null && supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()));
    } else if (supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()).plusDays(supplychainConfig.getNumberOfDays().longValue()));
    }
    setReservationDateTime(stockMove, saleOrder);
    stockMoveService.plan(stockMove);
    return Optional.of(stockMove);
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Example 52 with SaleOrderLine

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

the class SaleOrderStockServiceImpl method getAllSaleOrderLinePerDate.

protected Map<LocalDate, List<SaleOrderLine>> getAllSaleOrderLinePerDate(SaleOrder saleOrder) {
    Map<LocalDate, List<SaleOrderLine>> saleOrderLinePerDateMap = new HashMap<>();
    for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
        if (saleOrderLineServiceSupplyChain.computeUndeliveredQty(saleOrderLine).signum() <= 0) {
            continue;
        }
        LocalDate dateKey = saleOrderLine.getEstimatedDelivDate();
        if (dateKey == null) {
            dateKey = saleOrderLine.getSaleOrder().getDeliveryDate();
        }
        if (dateKey == null) {
            dateKey = saleOrderLine.getDesiredDelivDate();
        }
        List<SaleOrderLine> saleOrderLineLists = saleOrderLinePerDateMap.get(dateKey);
        if (saleOrderLineLists == null) {
            saleOrderLineLists = new ArrayList<>();
            saleOrderLinePerDateMap.put(dateKey, saleOrderLineLists);
        }
        saleOrderLineLists.add(saleOrderLine);
    }
    return saleOrderLinePerDateMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) LocalDate(java.time.LocalDate)

Example 53 with SaleOrderLine

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

the class SaleOrderStockServiceImpl method createStocksMovesFromSaleOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public List<Long> createStocksMovesFromSaleOrder(SaleOrder saleOrder) throws AxelorException {
    if (!this.isSaleOrderWithProductsToDeliver(saleOrder)) {
        return null;
    }
    if (saleOrder.getStockLocation() == null) {
        throw new AxelorException(saleOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_MISSING_STOCK_LOCATION), saleOrder.getSaleOrderSeq());
    }
    List<Long> stockMoveList = new ArrayList<>();
    Map<LocalDate, List<SaleOrderLine>> saleOrderLinePerDateMap = getAllSaleOrderLinePerDate(saleOrder);
    for (LocalDate estimatedDeliveryDate : saleOrderLinePerDateMap.keySet().stream().filter(x -> x != null).sorted((x, y) -> x.compareTo(y)).collect(Collectors.toList())) {
        List<SaleOrderLine> saleOrderLineList = saleOrderLinePerDateMap.get(estimatedDeliveryDate);
        Optional<StockMove> stockMove = createStockMove(saleOrder, estimatedDeliveryDate, saleOrderLineList);
        stockMove.map(StockMove::getId).ifPresent(stockMoveList::add);
    }
    Optional<List<SaleOrderLine>> saleOrderLineList = Optional.ofNullable(saleOrderLinePerDateMap.get(null));
    if (saleOrderLineList.isPresent()) {
        Optional<StockMove> stockMove = createStockMove(saleOrder, null, saleOrderLineList.get());
        stockMove.map(StockMove::getId).ifPresent(stockMoveList::add);
    }
    return stockMoveList;
}
Also used : Company(com.axelor.apps.base.db.Company) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) Map(java.util.Map) I18n(com.axelor.i18n.I18n) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) PartnerStockSettings(com.axelor.apps.stock.db.PartnerStockSettings) RoundingMode(java.math.RoundingMode) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) Collectors(java.util.stream.Collectors) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) PartnerStockSettingsService(com.axelor.apps.stock.service.PartnerStockSettingsService) LocalDate(java.time.LocalDate) Optional(java.util.Optional) SupplyChainConfigRepository(com.axelor.apps.supplychain.db.repo.SupplyChainConfigRepository) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) LocalDate(java.time.LocalDate) ArrayList(java.util.ArrayList) List(java.util.List) Transactional(com.google.inject.persist.Transactional)

Example 54 with SaleOrderLine

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

the class StockLocationLineReservationServiceImpl method deallocateAll.

@Override
@Transactional(rollbackOn = { Exception.class })
public void deallocateAll(StockLocationLine stockLocationLine) throws AxelorException {
    List<StockMoveLine> stockMoveLineList = Beans.get(StockMoveLineRepository.class).all().filter("self.product = :product " + "AND self.stockMove.fromStockLocation = :stockLocation " + "AND self.stockMove.statusSelect = :planned " + "AND (self.stockMove.availabilityRequest IS FALSE " + "OR self.stockMove.availabilityRequest IS NULL) " + "AND self.reservedQty > 0").bind("product", stockLocationLine.getProduct()).bind("stockLocation", stockLocationLine.getStockLocation()).bind("planned", StockMoveRepository.STATUS_PLANNED).fetch();
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        stockMoveLine.setReservedQty(BigDecimal.ZERO);
        SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
        if (saleOrderLine != null) {
            saleOrderLine.setReservedQty(BigDecimal.ZERO);
        }
    }
    Beans.get(ReservedQtyService.class).updateReservedQty(stockLocationLine);
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Transactional(com.google.inject.persist.Transactional)

Example 55 with SaleOrderLine

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

the class WorkflowCancelServiceSupplychainImpl method saleOrderLineProcess.

public SaleOrder saleOrderLineProcess(Invoice invoice, InvoiceLine invoiceLine) throws AxelorException {
    SaleOrderLine saleOrderLine = invoiceLine.getSaleOrderLine();
    if (saleOrderLine == null) {
        return null;
    }
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    // Update invoiced amount on sale order line
    BigDecimal invoicedAmountToAdd = invoiceLine.getExTaxTotal();
    // If is it a refund invoice, so we negate the amount invoiced
    if (InvoiceToolService.isRefund(invoiceLine.getInvoice())) {
        invoicedAmountToAdd = invoicedAmountToAdd.negate();
    }
    if (!invoice.getCurrency().equals(saleOrder.getCurrency()) && saleOrderLine.getCompanyExTaxTotal().compareTo(BigDecimal.ZERO) != 0) {
        // If the sale order currency is different from the invoice currency, use company currency to
        // calculate a rate. This rate will be applied to sale order line
        BigDecimal currentCompanyInvoicedAmount = invoiceLine.getCompanyExTaxTotal();
        BigDecimal rate = currentCompanyInvoicedAmount.divide(saleOrderLine.getCompanyExTaxTotal(), 4, RoundingMode.HALF_UP);
        invoicedAmountToAdd = rate.multiply(saleOrderLine.getExTaxTotal());
    }
    saleOrderLine.setAmountInvoiced(saleOrderLine.getAmountInvoiced().subtract(invoicedAmountToAdd));
    return saleOrder;
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal)

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