Search in sources :

Example 41 with Unit

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

the class ProductionProductStockLocationServiceImpl method getMissingManufOrderQty.

protected BigDecimal getMissingManufOrderQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
    if (product == null || product.getUnit() == null) {
        return BigDecimal.ZERO;
    }
    Long companyId = 0L;
    Long stockLocationId = 0L;
    if (company != null) {
        companyId = company.getId();
        if (stockLocation != null) {
            stockLocationId = stockLocation.getId();
        }
    }
    String query = manufOrderService.getConsumeAndMissingQtyForAProduct(product.getId(), companyId, stockLocationId);
    List<StockMoveLine> stockMoveLineList = stockMoveLineRepository.all().filter(query).fetch();
    BigDecimal sumMissingManufOrderQty = BigDecimal.ZERO;
    if (!stockMoveLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (StockMoveLine stockMoveLine : stockMoveLineList) {
            BigDecimal productMissingManufOrderQty = getMissingQtyOfStockMoveLine(stockMoveLine);
            unitConversionService.convert(stockMoveLine.getUnit(), unitConversion, productMissingManufOrderQty, productMissingManufOrderQty.scale(), product);
            sumMissingManufOrderQty = sumMissingManufOrderQty.add(productMissingManufOrderQty);
        }
    }
    return sumMissingManufOrderQty;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 42 with Unit

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

the class ProductionProductStockLocationServiceImpl method getConsumeManufOrderQty.

protected BigDecimal getConsumeManufOrderQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
    if (product == null || product.getUnit() == null) {
        return BigDecimal.ZERO;
    }
    Long companyId = 0L;
    Long stockLocationId = 0L;
    if (company != null) {
        companyId = company.getId();
        if (stockLocation != null) {
            stockLocationId = stockLocation.getId();
        }
    }
    String query = manufOrderService.getConsumeAndMissingQtyForAProduct(product.getId(), companyId, stockLocationId);
    List<StockMoveLine> stockMoveLineList = stockMoveLineRepository.all().filter(query).fetch();
    BigDecimal sumConsumeManufOrderQty = BigDecimal.ZERO;
    if (!stockMoveLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (StockMoveLine stockMoveLine : stockMoveLineList) {
            BigDecimal productConsumeManufOrderQty = stockMoveLine.getRealQty();
            unitConversionService.convert(stockMoveLine.getUnit(), unitConversion, productConsumeManufOrderQty, productConsumeManufOrderQty.scale(), product);
            sumConsumeManufOrderQty = sumConsumeManufOrderQty.add(productConsumeManufOrderQty);
        }
    }
    return sumConsumeManufOrderQty;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 43 with Unit

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

the class StockMoveLineServiceImpl method updateLocations.

@Override
public void updateLocations(StockMoveLine stockMoveLine, StockLocation fromStockLocation, StockLocation toStockLocation, Product product, BigDecimal qty, int fromStatus, int toStatus, LocalDate lastFutureStockMoveDate, TrackingNumber trackingNumber) throws AxelorException {
    Unit stockMoveLineUnit = stockMoveLine.getUnit();
    switch(fromStatus) {
        case StockMoveRepository.STATUS_PLANNED:
            stockLocationLineService.updateLocation(fromStockLocation, product, stockMoveLineUnit, qty, false, true, true, null, trackingNumber);
            stockLocationLineService.updateLocation(toStockLocation, product, stockMoveLineUnit, qty, false, true, false, null, trackingNumber);
            break;
        case StockMoveRepository.STATUS_REALIZED:
            stockLocationLineService.updateLocation(fromStockLocation, product, stockMoveLineUnit, qty, true, true, true, null, trackingNumber);
            stockLocationLineService.updateLocation(toStockLocation, product, stockMoveLineUnit, qty, true, true, false, null, trackingNumber);
            break;
        default:
            break;
    }
    switch(toStatus) {
        case StockMoveRepository.STATUS_PLANNED:
            stockLocationLineService.updateLocation(fromStockLocation, product, stockMoveLineUnit, qty, false, true, false, lastFutureStockMoveDate, trackingNumber);
            stockLocationLineService.updateLocation(toStockLocation, product, stockMoveLineUnit, qty, false, true, true, lastFutureStockMoveDate, trackingNumber);
            break;
        case StockMoveRepository.STATUS_REALIZED:
            stockLocationLineService.updateLocation(fromStockLocation, product, stockMoveLineUnit, qty, true, true, false, null, trackingNumber);
            stockLocationLineService.updateLocation(toStockLocation, product, stockMoveLineUnit, qty, true, true, true, null, trackingNumber);
            break;
        default:
            break;
    }
}
Also used : Unit(com.axelor.apps.base.db.Unit)

Example 44 with Unit

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

the class StockMoveLineServiceImpl method computeNetMass.

public BigDecimal computeNetMass(StockMove stockMove, StockMoveLine stockMoveLine, Company company) throws AxelorException {
    BigDecimal netMass;
    Product product = stockMoveLine.getProduct();
    Unit startUnit;
    Unit endUnit;
    if (product == null || !product.getProductTypeSelect().equals(ProductRepository.PRODUCT_TYPE_STORABLE)) {
        return null;
    }
    startUnit = product.getMassUnit();
    if (startUnit == null) {
        if (stockMove != null && !checkMassesRequired(stockMove, stockMoveLine)) {
            return product.getNetMass();
        }
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MISSING_PRODUCT_MASS_UNIT), product.getName());
    }
    if (company != null && company.getStockConfig() != null && company.getStockConfig().getCustomsMassUnit() != null) {
        endUnit = company.getStockConfig().getCustomsMassUnit();
    } else {
        endUnit = startUnit;
    }
    netMass = unitConversionService.convert(startUnit, endUnit, product.getNetMass(), 10, product);
    return netMass;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 45 with Unit

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

the class StockLocationServiceImpl method getQty.

@Override
public BigDecimal getQty(Long productId, Long locationId, Long companyId, String qtyType) throws AxelorException {
    if (productId != null) {
        Product product = productRepo.find(productId);
        Unit productUnit = product.getUnit();
        UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
        int scale = Beans.get(AppBaseService.class).getNbDecimalDigitForQty();
        if (locationId == null || locationId == 0L) {
            List<StockLocation> stockLocations = getNonVirtualStockLocations(companyId);
            if (!stockLocations.isEmpty()) {
                BigDecimal qty = BigDecimal.ZERO;
                for (StockLocation stockLocation : stockLocations) {
                    StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocationRepo.find(stockLocation.getId()), productRepo.find(productId));
                    if (stockLocationLine != null) {
                        Unit stockLocationLineUnit = stockLocationLine.getUnit();
                        qty = qty.add(qtyType.equals("real") ? stockLocationLine.getCurrentQty() : stockLocationLine.getFutureQty());
                        if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
                            qty = unitConversionService.convert(stockLocationLineUnit, productUnit, qty, qty.scale(), product);
                        }
                    }
                }
                return qty.setScale(scale, RoundingMode.HALF_UP);
            }
        } else {
            StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocationRepo.find(locationId), productRepo.find(productId));
            if (stockLocationLine != null) {
                Unit stockLocationLineUnit = stockLocationLine.getUnit();
                BigDecimal qty = BigDecimal.ZERO;
                qty = qtyType.equals("real") ? stockLocationLine.getCurrentQty() : stockLocationLine.getFutureQty();
                if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
                    qty = unitConversionService.convert(stockLocationLineUnit, productUnit, qty, qty.scale(), product);
                }
                return qty.setScale(scale, RoundingMode.HALF_UP);
            }
        }
    }
    return BigDecimal.ZERO;
}
Also used : UnitConversionService(com.axelor.apps.base.service.UnitConversionService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Aggregations

Unit (com.axelor.apps.base.db.Unit)45 BigDecimal (java.math.BigDecimal)38 Product (com.axelor.apps.base.db.Product)19 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)11 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)9 Company (com.axelor.apps.base.db.Company)8 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)8 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)6 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)6 StockLocation (com.axelor.apps.stock.db.StockLocation)6 StockMove (com.axelor.apps.stock.db.StockMove)6 LocalDate (java.time.LocalDate)6 List (java.util.List)6 ProdProduct (com.axelor.apps.production.db.ProdProduct)5 ProdResidualProduct (com.axelor.apps.production.db.ProdResidualProduct)5 ArrayList (java.util.ArrayList)5 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)4