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;
}
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);
}
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);
}
}
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());
}
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);
}
Aggregations