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;
}
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);
});
}
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;
}
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;
}
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));
}
}
Aggregations