Search in sources :

Example 61 with StockMoveLine

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

the class AccountingCutOffServiceImpl method generateCutOffMoves.

@Transactional(rollbackOn = { Exception.class })
public List<Move> generateCutOffMoves(StockMove stockMove, LocalDate moveDate, LocalDate reverseMoveDate, int accountingCutOffTypeSelect, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct) throws AxelorException {
    List<Move> moveList = new ArrayList<>();
    List<StockMoveLine> stockMoveLineSortedList = stockMove.getStockMoveLineList();
    Collections.sort(stockMoveLineSortedList, Comparator.comparing(StockMoveLine::getSequence));
    Move move = generateCutOffMove(stockMove, stockMoveLineSortedList, moveDate, moveDate, accountingCutOffTypeSelect == SupplychainBatchRepository.ACCOUNTING_CUT_OFF_TYPE_SUPPLIER_INVOICES, recoveredTax, ati, moveDescription, includeNotStockManagedProduct, false);
    if (move == null) {
        return null;
    }
    moveList.add(move);
    Move reverseMove = generateCutOffMove(stockMove, stockMoveLineSortedList, reverseMoveDate, moveDate, accountingCutOffTypeSelect == SupplychainBatchRepository.ACCOUNTING_CUT_OFF_TYPE_SUPPLIER_INVOICES, recoveredTax, ati, moveDescription, includeNotStockManagedProduct, true);
    if (reverseMove == null) {
        return null;
    }
    moveList.add(reverseMove);
    reconcile(move, reverseMove);
    return moveList;
}
Also used : Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Example 62 with StockMoveLine

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

the class ReservedQtyServiceImpl method updateReservedQty.

@Override
public void updateReservedQty(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 reservedQty = BigDecimal.ZERO;
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        reservedQty = reservedQty.add(convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), stockMoveLine.getReservedQty(), stockLocationLine.getProduct()));
    }
    stockLocationLine.setReservedQty(reservedQty);
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 63 with StockMoveLine

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

the class ReservedQtyServiceImpl method allocateAll.

@Override
public void allocateAll(SaleOrderLine saleOrderLine) throws AxelorException {
    if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
        return;
    }
    // request the maximum quantity
    requestQty(saleOrderLine);
    StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
    if (stockMoveLine == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_NO_STOCK_MOVE));
    }
    // search for the maximum quantity that can be allocated.
    StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
    BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
    Product product = stockMoveLine.getProduct();
    BigDecimal availableQtyToBeReservedSaleOrderLine = convertUnitWithProduct(saleOrderLine.getUnit(), stockLocationLine.getUnit(), availableQtyToBeReserved, product).add(saleOrderLine.getReservedQty());
    BigDecimal qtyThatWillBeAllocated = saleOrderLine.getQty().min(availableQtyToBeReservedSaleOrderLine);
    // allocate it
    if (qtyThatWillBeAllocated.compareTo(saleOrderLine.getReservedQty()) > 0) {
        updateReservedQty(saleOrderLine, qtyThatWillBeAllocated);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) 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)

Example 64 with StockMoveLine

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

the class ReservedQtyServiceImpl method cancelReservation.

@Override
@Transactional(rollbackOn = { Exception.class })
public void cancelReservation(SaleOrderLine saleOrderLine) throws AxelorException {
    if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
        return;
    }
    saleOrderLine.setIsQtyRequested(false);
    StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
    if (stockMoveLine != null) {
        stockMoveLine.setIsQtyRequested(false);
    }
    this.updateRequestedReservedQty(saleOrderLine, saleOrderLine.getDeliveredQty());
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Example 65 with StockMoveLine

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

the class ReservedQtyServiceImpl method updateReservedQuantityInStockMoveLineFromSaleOrderLine.

@Override
public void updateReservedQuantityInStockMoveLineFromSaleOrderLine(SaleOrderLine saleOrderLine, Product product, BigDecimal newReservedQty) throws AxelorException {
    if (product == null || !product.getStockManaged()) {
        return;
    }
    List<StockMoveLine> stockMoveLineList = getPlannedStockMoveLines(saleOrderLine);
    BigDecimal allocatedQty = newReservedQty;
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        BigDecimal stockMoveAllocatedQty = convertUnitWithProduct(saleOrderLine.getUnit(), stockMoveLine.getUnit(), allocatedQty, product);
        BigDecimal reservedQtyInStockMoveLine = stockMoveLine.getRequestedReservedQty().min(stockMoveAllocatedQty);
        stockMoveLine.setReservedQty(reservedQtyInStockMoveLine);
        BigDecimal saleOrderReservedQtyInStockMoveLine = convertUnitWithProduct(stockMoveLine.getUnit(), saleOrderLine.getUnit(), reservedQtyInStockMoveLine, product);
        allocatedQty = allocatedQty.subtract(saleOrderReservedQtyInStockMoveLine);
    }
    updateReservedQty(saleOrderLine);
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

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