use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method updateSaleOrderLinesDeliveryState.
protected void updateSaleOrderLinesDeliveryState(StockMove stockMove, boolean qtyWasDelivered) throws AxelorException {
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
if (stockMoveLine.getSaleOrderLine() != null) {
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
BigDecimal realQty = unitConversionService.convert(stockMoveLine.getUnit(), saleOrderLine.getUnit(), stockMoveLine.getRealQty(), stockMoveLine.getRealQty().scale(), saleOrderLine.getProduct());
if (stockMove.getTypeSelect() != StockMoveRepository.TYPE_INTERNAL) {
if (qtyWasDelivered) {
saleOrderLine.setDeliveredQty(saleOrderLine.getDeliveredQty().add(realQty));
} else {
saleOrderLine.setDeliveredQty(saleOrderLine.getDeliveredQty().subtract(realQty));
}
}
if (saleOrderLine.getDeliveredQty().signum() == 0) {
saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_NOT_DELIVERED);
} else if (saleOrderLine.getDeliveredQty().compareTo(saleOrderLine.getQty()) < 0) {
saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_PARTIALLY_DELIVERED);
} else {
saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_DELIVERED);
}
}
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method createSplitStockMoveLine.
@Override
protected StockMoveLine createSplitStockMoveLine(StockMove originalStockMove, StockMoveLine originalStockMoveLine, StockMoveLine modifiedStockMoveLine) {
StockMoveLine newStockMoveLine = super.createSplitStockMoveLine(originalStockMove, originalStockMoveLine, modifiedStockMoveLine);
if (originalStockMoveLine.getQty().compareTo(originalStockMoveLine.getRequestedReservedQty()) < 0) {
newStockMoveLine.setRequestedReservedQty(originalStockMoveLine.getRequestedReservedQty().subtract(originalStockMoveLine.getQty()));
originalStockMoveLine.setRequestedReservedQty(originalStockMoveLine.getQty());
}
newStockMoveLine.setPurchaseOrderLine(originalStockMoveLine.getPurchaseOrderLine());
newStockMoveLine.setSaleOrderLine(originalStockMoveLine.getSaleOrderLine());
return newStockMoveLine;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method isAllocatedStockMoveLineRemoved.
@Override
public boolean isAllocatedStockMoveLineRemoved(StockMove stockMove) {
StockMove storedStockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
Boolean isAllocatedStockMoveLineRemoved = false;
if (ObjectUtils.notEmpty(storedStockMove)) {
List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
List<StockMoveLine> storedStockMoveLineList = storedStockMove.getStockMoveLineList();
if (stockMoveLineList != null && storedStockMoveLineList != null) {
for (StockMoveLine stockMoveLine : storedStockMoveLineList) {
if (Beans.get(StockMoveLineServiceSupplychain.class).isAllocatedStockMoveLine(stockMoveLine) && !stockMoveLineList.contains(stockMoveLine)) {
stockMoveLineList.add(stockMoveLine);
isAllocatedStockMoveLineRemoved = true;
}
if (isAllocatedStockMoveLineRemoved) {
stockMove.setStockMoveLineList(stockMoveLineList);
}
}
}
}
return isAllocatedStockMoveLineRemoved;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveLineServiceSupplychainImpl method getMergedStockMoveLine.
@Override
public StockMoveLine getMergedStockMoveLine(List<StockMoveLine> stockMoveLineList) throws AxelorException {
if (stockMoveLineList == null || stockMoveLineList.isEmpty()) {
return null;
}
if (stockMoveLineList.size() == 1) {
return stockMoveLineList.get(0);
}
StockMove stockMove = stockMoveLineList.get(0).getStockMove();
SaleOrderLine saleOrderLine = stockMoveLineList.get(0).getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLineList.get(0).getPurchaseOrderLine();
Product product;
String productName;
String description;
BigDecimal quantity = BigDecimal.ZERO;
Unit unit;
if (saleOrderLine != null) {
product = saleOrderLine.getProduct();
productName = saleOrderLine.getProductName();
description = saleOrderLine.getDescription();
unit = saleOrderLine.getUnit();
} else if (purchaseOrderLine != null) {
product = purchaseOrderLine.getProduct();
productName = purchaseOrderLine.getProductName();
description = purchaseOrderLine.getDescription();
unit = purchaseOrderLine.getUnit();
} else {
// shouldn't ever happen or you misused this function
return null;
}
for (StockMoveLine stockMoveLine : stockMoveLineList) {
quantity = quantity.add(stockMoveLine.getRealQty());
}
StockMoveLine generatedStockMoveLine = createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, unit, stockMove, null);
generatedStockMoveLine.setSaleOrderLine(saleOrderLine);
generatedStockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
generatedStockMoveLine.setIsMergedStockMoveLine(true);
return generatedStockMoveLine;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveLineServiceSupplychainImpl method splitStockMoveLine.
@Override
public StockMoveLine splitStockMoveLine(StockMoveLine stockMoveLine, BigDecimal qty, TrackingNumber trackingNumber) throws AxelorException {
StockMoveLine newStockMoveLine = super.splitStockMoveLine(stockMoveLine, qty, trackingNumber);
if (!Beans.get(AppBaseService.class).isApp("supplychain")) {
return newStockMoveLine;
}
BigDecimal reservedQtyAfterSplit = BigDecimal.ZERO.max(stockMoveLine.getRequestedReservedQty().subtract(qty));
BigDecimal reservedQtyInNewLine = stockMoveLine.getRequestedReservedQty().min(qty);
stockMoveLine.setRequestedReservedQty(reservedQtyAfterSplit);
newStockMoveLine.setRequestedReservedQty(reservedQtyInNewLine);
newStockMoveLine.setSaleOrderLine(stockMoveLine.getSaleOrderLine());
newStockMoveLine.setPurchaseOrderLine(stockMoveLine.getPurchaseOrderLine());
return newStockMoveLine;
}
Aggregations