use of com.axelor.apps.stock.db.StockLocationLine 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;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class InventoryService method exportInventoryAsCSV.
@Transactional(rollbackOn = { Exception.class })
public MetaFile exportInventoryAsCSV(Inventory inventory) throws IOException {
List<String[]> list = new ArrayList<>();
for (InventoryLine inventoryLine : inventory.getInventoryLineList()) {
String[] item = new String[9];
String realQty = "";
item[0] = (inventoryLine.getProduct() == null) ? "" : inventoryLine.getProduct().getName();
item[1] = (inventoryLine.getProduct() == null) ? "" : inventoryLine.getProduct().getCode();
item[2] = (inventoryLine.getProduct() == null) ? "" : ((inventoryLine.getProduct().getProductCategory() == null) ? "" : inventoryLine.getProduct().getProductCategory().getName());
item[3] = (inventoryLine.getRack() == null) ? "" : inventoryLine.getRack();
item[4] = (inventoryLine.getTrackingNumber() == null) ? "" : inventoryLine.getTrackingNumber().getTrackingNumberSeq();
item[5] = inventoryLine.getCurrentQty().toString();
if (inventoryLine.getRealQty() != null && inventory.getStatusSelect() != InventoryRepository.STATUS_DRAFT && inventory.getStatusSelect() != InventoryRepository.STATUS_PLANNED) {
realQty = inventoryLine.getRealQty().toString();
}
item[6] = realQty;
item[7] = (inventoryLine.getDescription() == null) ? "" : inventoryLine.getDescription();
String lastInventoryDateTString = "";
StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(inventory.getStockLocation(), inventoryLine.getProduct());
if (stockLocationLine != null) {
ZonedDateTime lastInventoryDateT = stockLocationLine.getLastInventoryDateT();
lastInventoryDateTString = lastInventoryDateT == null ? "" : lastInventoryDateT.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
}
item[8] = lastInventoryDateTString;
list.add(item);
}
Collections.sort(list, new // sort the list by code product
Comparator<String[]>() {
@Override
public int compare(String[] strings, String[] otherStrings) {
return strings[1].compareTo(otherStrings[1]);
}
});
String fileName = computeExportFileName(inventory);
File file = MetaFiles.createTempFile(fileName, ".csv").toFile();
log.debug("File Located at: {}", file.getPath());
String[] headers = { PRODUCT_NAME, PRODUCT_CODE, PRODUCT_CATEGORY, RACK, TRACKING_NUMBER, CURRENT_QUANTITY, REAL_QUANTITY, DESCRIPTION, LAST_INVENTORY_DATE };
CsvTool.csvWriter(file.getParent(), file.getName(), ';', '"', headers, list);
try (InputStream is = new FileInputStream(file)) {
return Beans.get(MetaFiles.class).upload(is, fileName + ".csv");
}
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class InventoryService method generateStockMoveLines.
/**
* Generate lines for the given stock move. Depending if we are creating an incoming or outgoing
* stock move, we only create stock move line with positive quantity.
*
* @param inventoryLine an inventory line
* @param stockMove a stock move being created
* @param isEnteringStock whether we are creating an incoming or outgoing stock move.
* @throws AxelorException
*/
protected void generateStockMoveLines(InventoryLine inventoryLine, StockMove stockMove, boolean isEnteringStock) throws AxelorException {
Product product = inventoryLine.getProduct();
TrackingNumber trackingNumber = inventoryLine.getTrackingNumber();
BigDecimal diff = inventoryLine.getRealQty().subtract(inventoryLine.getCurrentQty());
if (!isEnteringStock) {
diff = diff.negate();
}
if (diff.signum() > 0) {
BigDecimal avgPrice;
StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockMove.getToStockLocation(), product);
if (stockLocationLine != null) {
avgPrice = stockLocationLine.getAvgPrice();
} else {
avgPrice = BigDecimal.ZERO;
}
StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff, avgPrice, avgPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
if (stockMoveLine == null) {
throw new AxelorException(inventoryLine.getInventory(), TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVENTORY_7) + " " + inventoryLine.getInventory().getInventorySeq());
}
if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
stockMoveLine.setTrackingNumber(trackingNumber);
}
}
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockLocationLineServiceImpl method getTrackingNumberAvailableQty.
@Override
public BigDecimal getTrackingNumberAvailableQty(StockLocation stockLocation, TrackingNumber trackingNumber) {
StockLocationLine detailStockLocationLine = getDetailLocationLine(stockLocation, trackingNumber.getProduct(), trackingNumber);
BigDecimal availableQty = BigDecimal.ZERO;
if (detailStockLocationLine != null) {
availableQty = detailStockLocationLine.getCurrentQty();
}
return availableQty;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockLocationLineServiceImpl method getAvailableQty.
@Override
public BigDecimal getAvailableQty(StockLocation stockLocation, Product product) {
StockLocationLine stockLocationLine = getStockLocationLine(stockLocation, product);
BigDecimal availableQty = BigDecimal.ZERO;
if (stockLocationLine != null) {
availableQty = stockLocationLine.getCurrentQty();
}
return availableQty;
}
Aggregations