Search in sources :

Example 1 with StockLocation

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) StockLocation(com.axelor.apps.stock.db.StockLocation) 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 2 with StockLocation

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;
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList)

Example 3 with StockLocation

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

Example 4 with StockLocation

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

Example 5 with StockLocation

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

Aggregations

StockLocation (com.axelor.apps.stock.db.StockLocation)56 Company (com.axelor.apps.base.db.Company)19 BigDecimal (java.math.BigDecimal)18 Product (com.axelor.apps.base.db.Product)15 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockLocationRepository (com.axelor.apps.stock.db.repo.StockLocationRepository)12 ArrayList (java.util.ArrayList)12 StockConfig (com.axelor.apps.stock.db.StockConfig)10 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)9 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 StockLocationService (com.axelor.apps.stock.service.StockLocationService)8 List (java.util.List)8 Partner (com.axelor.apps.base.db.Partner)6 Unit (com.axelor.apps.base.db.Unit)6 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)6 LocalDate (java.time.LocalDate)6 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)5 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)5