use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class StockCorrectionServiceImpl method generateStockMove.
public StockMove generateStockMove(StockCorrection stockCorrection) throws AxelorException {
StockLocation toStockLocation = stockCorrection.getStockLocation();
Company company = toStockLocation.getCompany();
StockLocation fromStockLocation = stockConfigService.getInventoryVirtualStockLocation(stockConfigService.getStockConfig(company));
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
StockLocationLine stockLocationLine = null;
StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
if (stockCorrection.getTrackingNumber() == null) {
stockLocationLine = stockLocationLineService.getStockLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct());
} else {
stockLocationLine = stockLocationLineService.getDetailLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct(), stockCorrection.getTrackingNumber());
}
BigDecimal realQty = stockCorrection.getRealQty();
Product product = stockCorrection.getProduct();
TrackingNumber trackingNumber = stockCorrection.getTrackingNumber();
BigDecimal diff = realQty.subtract(stockLocationLine.getCurrentQty());
StockMove stockMove = null;
if (diff.compareTo(BigDecimal.ZERO) == 0) {
return null;
} else if (diff.compareTo(BigDecimal.ZERO) > 0) {
stockMove = this.createStockMoveHeader(company, fromStockLocation, toStockLocation);
} else {
stockMove = this.createStockMoveHeader(company, toStockLocation, fromStockLocation);
}
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_STOCK_CORRECTION);
stockMove.setOriginId(stockCorrection.getId());
stockMove.setStockCorrectionReason(stockCorrection.getStockCorrectionReason());
BigDecimal productCostPrice = (BigDecimal) productCompanyService.get(product, "costPrice", company);
StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff.abs(), productCostPrice, productCostPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
if (stockMoveLine == null) {
throw new AxelorException(stockCorrection, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_CORRECTION_1));
}
if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
stockMoveLine.setTrackingNumber(trackingNumber);
}
stockMoveService.plan(stockMove);
stockMoveService.copyQtyToRealQty(stockMove);
stockMoveService.realize(stockMove, false);
return stockMove;
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class StockLocationServiceImpl method getAllLocationAndSubLocation.
public List<StockLocation> getAllLocationAndSubLocation(StockLocation stockLocation, boolean isVirtualInclude) {
List<StockLocation> resultList = new ArrayList<>();
if (stockLocation == null) {
return resultList;
}
if (isVirtualInclude) {
for (StockLocation subLocation : stockLocationRepo.all().filter("self.parentStockLocation.id = :stockLocationId").bind("stockLocationId", stockLocation.getId()).fetch()) {
resultList.addAll(this.getAllLocationAndSubLocation(subLocation, isVirtualInclude));
}
} else {
for (StockLocation subLocation : stockLocationRepo.all().filter("self.parentStockLocation.id = :stockLocationId AND self.typeSelect != :virtual").bind("stockLocationId", stockLocation.getId()).bind("virtual", StockLocationRepository.TYPE_VIRTUAL).fetch()) {
resultList.addAll(this.getAllLocationAndSubLocation(subLocation, isVirtualInclude));
}
}
resultList.add(stockLocation);
return resultList;
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method fillRealizeWapPrice.
public void fillRealizeWapPrice(StockMoveLine stockMoveLine) {
StockLocation stockLocation = stockMoveLine.getStockMove().getFromStockLocation();
Optional<StockLocationLine> stockLocationLineOpt = Optional.ofNullable(stockLocationLineService.getStockLocationLine(stockLocation, stockMoveLine.getProduct()));
stockLocationLineOpt.ifPresent(stockLocationLine -> stockMoveLine.setWapPrice(stockLocationLine.getAvgPrice()));
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class InventoryLineService method compute.
public InventoryLine compute(InventoryLine inventoryLine, Inventory inventory) {
StockLocation stockLocation = inventory.getStockLocation();
Product product = inventoryLine.getProduct();
if (product != null) {
inventoryLine.setUnit(product.getUnit());
BigDecimal gap = inventoryLine.getRealQty() != null ? inventoryLine.getCurrentQty().subtract(inventoryLine.getRealQty()).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
inventoryLine.setGap(gap);
BigDecimal price;
int value = stockLocation.getCompany().getStockConfig().getInventoryValuationTypeSelect();
switch(value) {
case StockConfigRepository.VALUATION_TYPE_ACCOUNTING_VALUE:
price = product.getCostPrice();
break;
case StockConfigRepository.VALUATION_TYPE_SALE_VALUE:
price = product.getSalePrice();
break;
default:
price = product.getAvgPrice();
break;
}
inventoryLine.setGapValue(gap.multiply(price).setScale(2, RoundingMode.HALF_UP));
inventoryLine.setRealValue(inventoryLine.getRealQty() != null ? inventoryLine.getRealQty().multiply(price).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO);
}
return inventoryLine;
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class InventoryLineService method updateInventoryLine.
public InventoryLine updateInventoryLine(InventoryLine inventoryLine, Inventory inventory) {
StockLocation stockLocation = inventory.getStockLocation();
Product product = inventoryLine.getProduct();
if (product != null) {
StockLocationLine stockLocationLine = Beans.get(StockLocationLineService.class).getOrCreateStockLocationLine(stockLocation, product);
if (stockLocationLine != null) {
inventoryLine.setCurrentQty(stockLocationLine.getCurrentQty());
inventoryLine.setRack(stockLocationLine.getRack());
if (inventoryLine.getTrackingNumber() != null) {
inventoryLine.setCurrentQty(Beans.get(StockLocationLineRepository.class).all().filter("self.product = :product and self.detailsStockLocation = :stockLocation and self.trackingNumber = :trackingNumber").bind("product", inventoryLine.getProduct()).bind("stockLocation", stockLocation).bind("trackingNumber", inventoryLine.getTrackingNumber()).fetchStream().map(it -> it.getCurrentQty()).reduce(BigDecimal.ZERO, (a, b) -> a.add(b)));
}
} else {
inventoryLine.setCurrentQty(null);
inventoryLine.setRack(null);
}
}
return inventoryLine;
}
Aggregations