Search in sources :

Example 1 with StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine 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 StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.

the class StockCorrectionServiceImpl method fillDeafultQtys.

@Override
public Map<String, Object> fillDeafultQtys(StockCorrection stockCorrection) {
    Map<String, Object> stockCorrectionQtys = new HashMap<>();
    StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
    StockLocationLine stockLocationLine;
    if (stockCorrection.getTrackingNumber() == null) {
        stockLocationLine = stockLocationLineService.getStockLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct());
    } else {
        stockLocationLine = stockLocationLineService.getDetailLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct(), stockCorrection.getTrackingNumber());
    }
    if (stockLocationLine != null) {
        getDefaultQtys(stockLocationLine, stockCorrectionQtys);
    }
    return stockCorrectionQtys;
}
Also used : HashMap(java.util.HashMap) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Example 3 with StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.

the class StockLocationServiceImpl method getBadStockLocationLineId.

public List<Long> getBadStockLocationLineId() {
    List<StockLocationLine> stockLocationLineList = Beans.get(StockLocationLineRepository.class).all().filter("self.stockLocation.typeSelect = 1 OR self.stockLocation.typeSelect = 2").fetch();
    List<Long> idList = new ArrayList<>();
    StockRulesRepository stockRulesRepository = Beans.get(StockRulesRepository.class);
    for (StockLocationLine stockLocationLine : stockLocationLineList) {
        StockRules stockRules = stockRulesRepository.all().filter("self.stockLocation = ?1 AND self.product = ?2", stockLocationLine.getStockLocation(), stockLocationLine.getProduct()).fetchOne();
        if (stockRules != null && stockLocationLine.getFutureQty().compareTo(stockRules.getMinQty()) < 0) {
            idList.add(stockLocationLine.getId());
        }
    }
    if (idList.isEmpty()) {
        idList.add(0L);
    }
    return idList;
}
Also used : StockRulesRepository(com.axelor.apps.stock.db.repo.StockRulesRepository) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) ArrayList(java.util.ArrayList) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) StockRules(com.axelor.apps.stock.db.StockRules)

Example 4 with StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceImpl method computeFromStockLocation.

/**
 * Compute the price corresponding to the stock move line in the stock location. The price is the
 * average price in the stock location line with the same product as the stock move line, after
 * converting the unit.
 *
 * @param stockMoveLine a stock move line with a product.
 * @param stockLocation a stock location.
 * @return the computed price.
 * @throws AxelorException if the conversion fails.
 */
protected BigDecimal computeFromStockLocation(StockMoveLine stockMoveLine, StockLocation stockLocation) throws AxelorException {
    Optional<StockLocationLine> stockLocationLine = Optional.ofNullable(stockLocationLineService.getStockLocationLine(stockLocation, stockMoveLine.getProduct()));
    BigDecimal priceFromLocation = BigDecimal.ZERO;
    if (stockLocationLine.isPresent()) {
        priceFromLocation = stockLocationLine.get().getAvgPrice();
        priceFromLocation = unitConversionService.convert(stockMoveLine.getUnit(), getStockUnit(stockMoveLine), priceFromLocation, priceFromLocation.scale(), null);
    }
    return priceFromLocation;
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 5 with StockLocationLine

use of com.axelor.apps.stock.db.StockLocationLine 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)

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