Search in sources :

Example 6 with StockLocationLine

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;
}
Also used : BigDecimal(java.math.BigDecimal) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigRepository(com.axelor.apps.stock.db.repo.StockConfigRepository) Inventory(com.axelor.apps.stock.db.Inventory) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) InventoryLine(com.axelor.apps.stock.db.InventoryLine) RoundingMode(java.math.RoundingMode) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Example 7 with StockLocationLine

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");
    }
}
Also used : MetaFiles(com.axelor.meta.MetaFiles) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) ZonedDateTime(java.time.ZonedDateTime) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) InventoryLine(com.axelor.apps.stock.db.InventoryLine) Transactional(com.google.inject.persist.Transactional)

Example 8 with StockLocationLine

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);
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 9 with StockLocationLine

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;
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 10 with StockLocationLine

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;
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Aggregations

StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)42 BigDecimal (java.math.BigDecimal)25 Product (com.axelor.apps.base.db.Product)13 Transactional (com.google.inject.persist.Transactional)10 StockLocation (com.axelor.apps.stock.db.StockLocation)8 AxelorException (com.axelor.exception.AxelorException)8 Unit (com.axelor.apps.base.db.Unit)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)6 InventoryLine (com.axelor.apps.stock.db.InventoryLine)4 StockLocationLineRepository (com.axelor.apps.stock.db.repo.StockLocationLineRepository)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Company (com.axelor.apps.base.db.Company)3 StockMove (com.axelor.apps.stock.db.StockMove)3 Beans (com.axelor.inject.Beans)3 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)2 Inventory (com.axelor.apps.stock.db.Inventory)2