Search in sources :

Example 56 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveServiceSupplychainImpl method updatePurchaseOrderLines.

protected void updatePurchaseOrderLines(StockMove stockMove, boolean qtyWasReceived) throws AxelorException {
    for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
        if (stockMoveLine.getPurchaseOrderLine() != null) {
            PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
            BigDecimal realQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty(), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
            if (qtyWasReceived) {
                purchaseOrderLine.setReceivedQty(purchaseOrderLine.getReceivedQty().add(realQty));
            } else {
                purchaseOrderLine.setReceivedQty(purchaseOrderLine.getReceivedQty().subtract(realQty));
            }
            if (purchaseOrderLine.getReceivedQty().signum() == 0) {
                purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_NOT_RECEIVED);
            } else if (purchaseOrderLine.getReceivedQty().compareTo(purchaseOrderLine.getQty()) < 0) {
                purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_PARTIALLY_RECEIVED);
            } else {
                purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_RECEIVED);
            }
        }
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 57 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method updateRequestedReservedQty.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateRequestedReservedQty(SaleOrderLine saleOrderLine, BigDecimal newReservedQty) throws AxelorException {
    if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
        return;
    }
    StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
    if (stockMoveLine == null) {
        // only change requested quantity in sale order line
        saleOrderLine.setRequestedReservedQty(newReservedQty);
        return;
    }
    checkBeforeUpdatingQties(stockMoveLine, newReservedQty);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getBlockDeallocationOnAvailabilityRequest()) {
        checkAvailabilityRequest(stockMoveLine, newReservedQty, true);
    }
    BigDecimal diffReservedQuantity = newReservedQty.subtract(saleOrderLine.getRequestedReservedQty());
    // update in stock move line and sale order line
    BigDecimal newAllocatedQty = updateRequestedReservedQuantityInStockMoveLines(saleOrderLine, stockMoveLine.getProduct(), newReservedQty);
    StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
    Product product = stockMoveLine.getProduct();
    // update in stock location line
    BigDecimal diffReservedQuantityLocation = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), diffReservedQuantity, product);
    stockLocationLine.setRequestedReservedQty(stockLocationLine.getRequestedReservedQty().add(diffReservedQuantityLocation));
    // update reserved qty
    if (newAllocatedQty.compareTo(saleOrderLine.getReservedQty()) < 0) {
        updateReservedQty(saleOrderLine, newAllocatedQty);
    }
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 58 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method updateRequestedReservedQty.

@Override
public void updateRequestedReservedQty(StockLocationLine stockLocationLine) throws AxelorException {
    // compute from stock move lines
    List<StockMoveLine> stockMoveLineList = stockMoveLineRepository.all().filter("self.product.id = :productId " + "AND self.stockMove.fromStockLocation.id = :stockLocationId " + "AND self.stockMove.statusSelect = :planned").bind("productId", stockLocationLine.getProduct().getId()).bind("stockLocationId", stockLocationLine.getStockLocation().getId()).bind("planned", StockMoveRepository.STATUS_PLANNED).fetch();
    BigDecimal requestedReservedQty = BigDecimal.ZERO;
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        requestedReservedQty = requestedReservedQty.add(convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), stockMoveLine.getRequestedReservedQty(), stockLocationLine.getProduct()));
    }
    stockLocationLine.setRequestedReservedQty(requestedReservedQty);
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 59 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method consolidateReservedQtyInStockMoveLineByProduct.

@Override
public void consolidateReservedQtyInStockMoveLineByProduct(StockMove stockMove) {
    if (stockMove.getStockMoveLineList() == null) {
        return;
    }
    List<Product> productList = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getProduct).filter(Objects::nonNull).filter(Product::getStockManaged).distinct().collect(Collectors.toList());
    for (Product product : productList) {
        if (product != null) {
            List<StockMoveLine> stockMoveLineListToConsolidate = stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> product.equals(stockMoveLine1.getProduct())).collect(Collectors.toList());
            if (stockMoveLineListToConsolidate.size() > 1) {
                stockMoveLineListToConsolidate.sort(Comparator.comparing(StockMoveLine::getId));
                BigDecimal reservedQtySum = stockMoveLineListToConsolidate.stream().map(StockMoveLine::getReservedQty).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
                stockMoveLineListToConsolidate.forEach(toConsolidateStockMoveLine -> toConsolidateStockMoveLine.setReservedQty(BigDecimal.ZERO));
                stockMoveLineListToConsolidate.get(0).setReservedQty(reservedQtySum);
            }
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) Inject(com.google.inject.Inject) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) CancelReason(com.axelor.apps.base.db.CancelReason) I18n(com.axelor.i18n.I18n) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) 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) Collectors(java.util.stream.Collectors) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) Objects(java.util.Objects) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Comparator(java.util.Comparator) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 60 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class AccountingCutOffServiceImpl method generateMoveLines.

protected List<MoveLine> generateMoveLines(Move move, List<StockMoveLine> stockMoveLineList, String origin, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean isReverse, LocalDate originDate, boolean includeNotStockManagedProduct) throws AxelorException {
    if (stockMoveLineList != null) {
        for (StockMoveLine stockMoveLine : stockMoveLineList) {
            Product product = stockMoveLine.getProduct();
            if (checkStockMoveLine(stockMoveLine, product, includeNotStockManagedProduct)) {
                continue;
            }
            generateProductMoveLine(move, stockMoveLine, origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate);
        }
    }
    return move.getMoveLineList();
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product)

Aggregations

StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)121 BigDecimal (java.math.BigDecimal)59 StockMove (com.axelor.apps.stock.db.StockMove)44 AxelorException (com.axelor.exception.AxelorException)41 Product (com.axelor.apps.base.db.Product)33 Transactional (com.google.inject.persist.Transactional)31 ArrayList (java.util.ArrayList)28 List (java.util.List)18 Company (com.axelor.apps.base.db.Company)16 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)16 StockLocation (com.axelor.apps.stock.db.StockLocation)14 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)14 Unit (com.axelor.apps.base.db.Unit)13 Beans (com.axelor.inject.Beans)13 ProdProduct (com.axelor.apps.production.db.ProdProduct)12 StockMoveService (com.axelor.apps.stock.service.StockMoveService)12 I18n (com.axelor.i18n.I18n)12 Inject (com.google.inject.Inject)12 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)10