Search in sources :

Example 16 with StockMoveLine

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

the class StockLocationLineServiceImpl method computeFutureQty.

@Override
public BigDecimal computeFutureQty(StockLocationLine stockLocationLine) throws AxelorException {
    // future quantity is current quantity minus planned outgoing stock move lines plus planned
    // incoming stock move lines.
    Product product = stockLocationLine.getProduct();
    BigDecimal futureQty = stockLocationLine.getCurrentQty();
    List<StockMoveLine> incomingStockMoveLineList = findIncomingPlannedStockMoveLines(stockLocationLine);
    List<StockMoveLine> outgoingStockMoveLineList = findOutgoingPlannedStockMoveLines(stockLocationLine);
    if (stockLocationLine.getUnit() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOCATION_LINE_MISSING_UNIT), stockLocationLine.getStockLocation().getName(), product.getFullName());
    }
    for (StockMoveLine incomingStockMoveLine : incomingStockMoveLineList) {
        BigDecimal qtyToAdd = unitConversionService.convert(incomingStockMoveLine.getUnit(), stockLocationLine.getUnit(), incomingStockMoveLine.getRealQty(), incomingStockMoveLine.getRealQty().scale(), product);
        futureQty = futureQty.add(qtyToAdd);
    }
    for (StockMoveLine outgoingStockMoveLine : outgoingStockMoveLineList) {
        BigDecimal qtyToSubtract = unitConversionService.convert(outgoingStockMoveLine.getUnit(), stockLocationLine.getUnit(), outgoingStockMoveLine.getRealQty(), outgoingStockMoveLine.getRealQty().scale(), product);
        futureQty = futureQty.subtract(qtyToSubtract);
    }
    return futureQty;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 17 with StockMoveLine

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

the class StockMoveServiceImpl method updateStocks.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateStocks(StockMove stockMove) throws AxelorException {
    if (stockMove.getStatusSelect() != StockMoveRepository.STATUS_PLANNED) {
        return;
    }
    List<StockMoveLine> savedStockMoveLineList = Optional.ofNullable(stockMove.getPlannedStockMoveLineList()).orElse(new ArrayList<>());
    List<StockMoveLine> stockMoveLineList = Optional.ofNullable(stockMove.getStockMoveLineList()).orElse(new ArrayList<>());
    stockMoveLineService.updateLocations(stockMove.getFromStockLocation(), stockMove.getToStockLocation(), StockMoveRepository.STATUS_PLANNED, StockMoveRepository.STATUS_CANCELED, savedStockMoveLineList, stockMove.getEstimatedDate(), false);
    stockMoveLineService.updateLocations(stockMove.getFromStockLocation(), stockMove.getToStockLocation(), StockMoveRepository.STATUS_DRAFT, StockMoveRepository.STATUS_PLANNED, stockMoveLineList, stockMove.getEstimatedDate(), true);
    stockMove.clearPlannedStockMoveLineList();
    stockMoveLineList.forEach(stockMoveLine -> {
        StockMoveLine stockMoveLineCopy = stockMoveLineRepo.copy(stockMoveLine, false);
        stockMoveLineCopy.setArchived(true);
        stockMove.addPlannedStockMoveLineListItem(stockMoveLineCopy);
    });
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Example 18 with StockMoveLine

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

the class StockMoveServiceImpl method changeConformityStockMoveLine.

@Override
public Integer changeConformityStockMoveLine(StockMove stockMove) {
    Integer stockMoveConformitySelect;
    List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
    if (stockMoveLineList != null) {
        stockMoveConformitySelect = StockMoveRepository.CONFORMITY_COMPLIANT;
        for (StockMoveLine stockMoveLine : stockMoveLineList) {
            Integer conformitySelect = stockMoveLine.getConformitySelect();
            if (!conformitySelect.equals(StockMoveRepository.CONFORMITY_COMPLIANT)) {
                stockMoveConformitySelect = conformitySelect;
                if (conformitySelect.equals(StockMoveRepository.CONFORMITY_NON_COMPLIANT)) {
                    break;
                }
            }
        }
    } else {
        stockMoveConformitySelect = StockMoveRepository.CONFORMITY_NONE;
    }
    stockMove.setConformitySelect(stockMoveConformitySelect);
    return stockMoveConformitySelect;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 19 with StockMoveLine

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

the class StockMoveServiceImpl method splitStockMoveLines.

@Override
@Transactional
public boolean splitStockMoveLines(StockMove stockMove, List<StockMoveLine> stockMoveLines, BigDecimal splitQty) {
    boolean selected = false;
    for (StockMoveLine moveLine : stockMoveLines) {
        if (moveLine.isSelected()) {
            selected = true;
            StockMoveLine line = stockMoveLineRepo.find(moveLine.getId());
            BigDecimal totalQty = line.getQty();
            LOG.debug("Move Line selected: {}, Qty: {}", line, totalQty);
            while (splitQty.compareTo(totalQty) < 0) {
                totalQty = totalQty.subtract(splitQty);
                StockMoveLine newLine = stockMoveLineRepo.copy(line, false);
                newLine.setQty(splitQty);
                newLine.setRealQty(splitQty);
                newLine.setStockMove(line.getStockMove());
                stockMoveLineRepo.save(newLine);
            }
            LOG.debug("Qty remains: {}", totalQty);
            if (totalQty.compareTo(BigDecimal.ZERO) > 0) {
                StockMoveLine newLine = stockMoveLineRepo.copy(line, false);
                newLine.setQty(totalQty);
                newLine.setRealQty(totalQty);
                newLine.setStockMove(line.getStockMove());
                stockMoveLineRepo.save(newLine);
                LOG.debug("New line created: {}", newLine);
            }
            stockMove.removeStockMoveLineListItem(line);
            stockMoveLineRepo.remove(line);
        }
    }
    return selected;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 20 with StockMoveLine

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

the class StockMoveServiceImpl method computeMasses.

private void computeMasses(StockMove stockMove) throws AxelorException {
    StockConfig stockConfig = stockMove.getCompany().getStockConfig();
    Unit endUnit = stockConfig != null ? stockConfig.getCustomsMassUnit() : null;
    boolean massesRequiredForStockMove = false;
    List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
    if (stockMoveLineList == null) {
        return;
    }
    UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        Product product = stockMoveLine.getProduct();
        boolean massesRequiredForStockMoveLine = stockMoveLineService.checkMassesRequired(stockMove, stockMoveLine);
        if (product == null || !ProductRepository.PRODUCT_TYPE_STORABLE.equals(product.getProductTypeSelect())) {
            continue;
        }
        BigDecimal netMass = stockMoveLine.getNetMass();
        if (netMass.signum() == 0) {
            Unit startUnit = product.getMassUnit();
            if (startUnit != null && endUnit != null) {
                netMass = unitConversionService.convert(startUnit, endUnit, product.getNetMass(), product.getNetMass().scale(), null);
                stockMoveLine.setNetMass(netMass);
            }
        }
        if (netMass.signum() != 0) {
            BigDecimal totalNetMass = netMass.multiply(stockMoveLine.getRealQty());
            stockMoveLine.setTotalNetMass(totalNetMass);
        } else if (massesRequiredForStockMoveLine) {
            throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_18));
        }
        if (!massesRequiredForStockMove && massesRequiredForStockMoveLine) {
            massesRequiredForStockMove = true;
        }
    }
    if (massesRequiredForStockMove && endUnit == null) {
        throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_17));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

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