Search in sources :

Example 46 with StockMoveLine

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

the class MrpServiceProductionImpl method computeQtyLeftToConsume.

protected BigDecimal computeQtyLeftToConsume(List<StockMoveLine> consumedStockMoveLineList, ProdProduct prodProduct) {
    BigDecimal qtyToConsume = prodProduct.getQty();
    BigDecimal consumedQty = consumedStockMoveLineList.stream().filter(stockMoveLine -> stockMoveLine.getStockMove().getStatusSelect() == StockMoveRepository.STATUS_REALIZED && stockMoveLine.getProduct().equals(prodProduct.getProduct())).map(StockMoveLine::getQty).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
    return qtyToConsume.subtract(consumedQty);
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) MrpLineTypeRepository(com.axelor.apps.supplychain.db.repo.MrpLineTypeRepository) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) MrpLineOrigin(com.axelor.apps.supplychain.db.MrpLineOrigin) AppPurchaseService(com.axelor.apps.purchase.service.app.AppPurchaseService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) Transactional(com.google.inject.persist.Transactional) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) StockRulesRepository(com.axelor.apps.stock.db.repo.StockRulesRepository) StockRules(com.axelor.apps.stock.db.StockRules) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MrpLine(com.axelor.apps.supplychain.db.MrpLine) MethodHandles(java.lang.invoke.MethodHandles) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) List(java.util.List) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) Mrp(com.axelor.apps.supplychain.db.Mrp) LocalDate(java.time.LocalDate) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Company(com.axelor.apps.base.db.Company) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) MrpServiceImpl(com.axelor.apps.supplychain.service.MrpServiceImpl) MrpLineRepository(com.axelor.apps.supplychain.db.repo.MrpLineRepository) MrpRepository(com.axelor.apps.supplychain.db.repo.MrpRepository) AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) JPA(com.axelor.db.JPA) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MrpLineService(com.axelor.apps.supplychain.service.MrpLineService) MrpForecastRepository(com.axelor.apps.supplychain.db.repo.MrpForecastRepository) OperationOrder(com.axelor.apps.production.db.OperationOrder) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockRulesService(com.axelor.apps.stock.service.StockRulesService) Beans(com.axelor.inject.Beans) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 47 with StockMoveLine

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

the class ProductionProductStockLocationServiceImpl method getBuildingQty.

protected BigDecimal getBuildingQty(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.getBuildingQtyForAProduct(product.getId(), companyId, stockLocationId);
    List<StockMoveLine> stockMoveLineList = stockMoveLineRepository.all().filter(query).fetch();
    BigDecimal sumBuildingQty = BigDecimal.ZERO;
    if (!stockMoveLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (StockMoveLine stockMoveLine : stockMoveLineList) {
            BigDecimal productBuildingQty = stockMoveLine.getRealQty();
            unitConversionService.convert(stockMoveLine.getUnit(), unitConversion, productBuildingQty, productBuildingQty.scale(), product);
            sumBuildingQty = sumBuildingQty.add(productBuildingQty);
        }
    }
    return sumBuildingQty;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 48 with StockMoveLine

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

the class DeclarationOfExchangesExporterGoods method exportToCSV.

@Override
public String exportToCSV() throws AxelorException {
    Path path = getFilePath();
    Period period = declarationOfExchanges.getPeriod();
    List<StockMoveLine> stockMoveLines = Beans.get(StockMoveLineRepository.class).findForDeclarationOfExchanges(period.getFromDate(), period.getToDate(), declarationOfExchanges.getProductTypeSelect(), declarationOfExchanges.getStockMoveTypeSelect(), declarationOfExchanges.getCountry(), declarationOfExchanges.getCompany()).fetch();
    List<String[]> dataList = new ArrayList<>(stockMoveLines.size());
    int lineNum = 1;
    for (StockMoveLine stockMoveLine : stockMoveLines) {
        String[] data = exportLineToCsv(stockMoveLine, lineNum);
        if (data != null && data.length != 0) {
            dataList.add(data);
            lineNum++;
        }
    }
    try {
        MoreFiles.createParentDirectories(path);
        CsvTool.csvWriter(path.getParent().toString(), path.getFileName().toString(), ';', getTranslatedHeaders(), dataList);
    } catch (IOException e) {
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getLocalizedMessage());
    }
    return attach(path.toString());
}
Also used : Path(java.nio.file.Path) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) Period(com.axelor.apps.base.db.Period) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) IOException(java.io.IOException)

Example 49 with StockMoveLine

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

the class StockMoveLineServiceSupplychainImpl method createStockMoveLine.

@Override
public StockMoveLine createStockMoveLine(Product product, String productName, String description, BigDecimal quantity, BigDecimal requestedReservedQty, BigDecimal unitPrice, BigDecimal companyUnitPriceUntaxed, BigDecimal companyPurchasePrice, Unit unit, StockMove stockMove, int type, boolean taxed, BigDecimal taxRate, SaleOrderLine saleOrderLine, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
    if (product != null) {
        StockMoveLine stockMoveLine = generateStockMoveLineConvertingUnitPrice(product, productName, description, quantity, unitPrice, companyUnitPriceUntaxed, companyPurchasePrice, unit, stockMove, taxed, taxRate);
        stockMoveLine.setRequestedReservedQty(requestedReservedQty);
        stockMoveLine.setIsQtyRequested(requestedReservedQty != null && requestedReservedQty.signum() > 0);
        stockMoveLine.setSaleOrderLine(saleOrderLine);
        stockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
        TrackingNumberConfiguration trackingNumberConfiguration = product.getTrackingNumberConfiguration();
        return assignOrGenerateTrackingNumber(stockMoveLine, stockMove, product, trackingNumberConfiguration, type);
    } else {
        return this.createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, companyUnitPriceUntaxed, BigDecimal.ZERO, unit, stockMove, null);
    }
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) TrackingNumberConfiguration(com.axelor.apps.stock.db.TrackingNumberConfiguration)

Example 50 with StockMoveLine

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

the class StockLocationLineReservationServiceImpl method deallocateAll.

@Override
@Transactional(rollbackOn = { Exception.class })
public void deallocateAll(StockLocationLine stockLocationLine) throws AxelorException {
    List<StockMoveLine> stockMoveLineList = Beans.get(StockMoveLineRepository.class).all().filter("self.product = :product " + "AND self.stockMove.fromStockLocation = :stockLocation " + "AND self.stockMove.statusSelect = :planned " + "AND (self.stockMove.availabilityRequest IS FALSE " + "OR self.stockMove.availabilityRequest IS NULL) " + "AND self.reservedQty > 0").bind("product", stockLocationLine.getProduct()).bind("stockLocation", stockLocationLine.getStockLocation()).bind("planned", StockMoveRepository.STATUS_PLANNED).fetch();
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        stockMoveLine.setReservedQty(BigDecimal.ZERO);
        SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
        if (saleOrderLine != null) {
            saleOrderLine.setReservedQty(BigDecimal.ZERO);
        }
    }
    Beans.get(ReservedQtyService.class).updateReservedQty(stockLocationLine);
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Transactional(com.google.inject.persist.Transactional)

Aggregations

StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)121 BigDecimal (java.math.BigDecimal)59 StockMove (com.axelor.apps.stock.db.StockMove)44 AxelorException (com.axelor.exception.AxelorException)41 Product (com.axelor.apps.base.db.Product)33 Transactional (com.google.inject.persist.Transactional)31 ArrayList (java.util.ArrayList)28 List (java.util.List)18 Company (com.axelor.apps.base.db.Company)16 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)16 StockLocation (com.axelor.apps.stock.db.StockLocation)14 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)14 Unit (com.axelor.apps.base.db.Unit)13 Beans (com.axelor.inject.Beans)13 ProdProduct (com.axelor.apps.production.db.ProdProduct)12 StockMoveService (com.axelor.apps.stock.service.StockMoveService)12 I18n (com.axelor.i18n.I18n)12 Inject (com.google.inject.Inject)12 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)10