Search in sources :

Example 6 with Product

use of com.axelor.apps.base.db.Product 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 7 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class StockMoveLineServiceImpl method storeCustomsCodes.

@Override
public void storeCustomsCodes(List<StockMoveLine> stockMoveLineList) {
    if (stockMoveLineList == null) {
        return;
    }
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        Product product = stockMoveLine.getProduct();
        CustomsCodeNomenclature customsCodeNomenclature = product != null ? product.getCustomsCodeNomenclature() : null;
        stockMoveLine.setCustomsCodeNomenclature(customsCodeNomenclature);
        stockMoveLine.setCustomsCode(customsCodeNomenclature != null ? customsCodeNomenclature.getCode() : null);
    }
}
Also used : CustomsCodeNomenclature(com.axelor.apps.stock.db.CustomsCodeNomenclature) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product)

Example 8 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class StockMoveLineServiceImpl method checkExpirationDates.

@Override
public void checkExpirationDates(StockMove stockMove) throws AxelorException {
    List<String> errorList = new ArrayList<>();
    for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
        TrackingNumber trackingNumber = stockMoveLine.getTrackingNumber();
        if (trackingNumber == null) {
            continue;
        }
        Product product = trackingNumber.getProduct();
        if (product == null || !product.getCheckExpirationDateAtStockMoveRealization()) {
            continue;
        }
        if (product.getHasWarranty() && trackingNumber.getWarrantyExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany())) || product.getIsPerishable() && trackingNumber.getPerishableExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany()))) {
            errorList.add(product.getName());
        }
    }
    if (!errorList.isEmpty()) {
        String errorStr = errorList.stream().collect(Collectors.joining(", "));
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_LINE_EXPIRED_PRODUCTS), errorStr);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product)

Example 9 with Product

use of com.axelor.apps.base.db.Product 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 10 with Product

use of com.axelor.apps.base.db.Product 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

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16