Program: 58725
Project: 58725
Buggy source:
@Transactional(rollbackOn={AxelorException.class,Exception.class}) public Move ventilate(Expense expense) throws AxelorException {
  LocalDate moveDate=generalService.getTodayDate();
  if (expense.getMoveDate() != null) {
    moveDate=expense.getMoveDate();
  }
  Account account=null;
  AccountConfig accountConfig=accountConfigService.getAccountConfig(expense.getCompany());
  if (expense.getUser().getPartner() == null) {
    throw new AxelorException(String.format(I18n.get(com.axelor.apps.account.exception.IExceptionMessage.USER_PARTNER),expense.getUser().getName()),IException.CONFIGURATION_ERROR);
  }
  Move move=moveService.getMoveCreateService().createMove(accountConfigService.getExpenseJournal(accountConfig),accountConfig.getCompany(),null,expense.getUser().getPartner(),moveDate,expense.getUser().getPartner().getPaymentMode(),MoveRepository.AUTOMATIC);
  List<MoveLine> moveLines=new ArrayList<MoveLine>();
  AccountManagement accountManagement=null;
  Set<AnalyticAccount> analyticAccounts=new HashSet<AnalyticAccount>();
  BigDecimal exTaxTotal=null;
  int moveLineId=1;
  int expenseLineId=1;
  moveLines.add(moveLineService.createMoveLine(move,expense.getUser().getPartner(),accountConfigService.getExpenseEmployeeAccount(accountConfig),expense.getInTaxTotal(),false,moveDate,moveDate,moveLineId++,"String_Node_Str"));
  for (  ExpenseLine expenseLine : expense.getExpenseLineList()) {
    analyticAccounts.clear();
    Product product=expenseLine.getExpenseProduct();
    accountManagement=accountManagementService.getAccountManagement(product,expense.getCompany());
    account=accountManagementService.getProductAccount(accountManagement,true);
    if (account == null) {
      throw new AxelorException(String.format(I18n.get(com.axelor.apps.account.exception.IExceptionMessage.MOVE_LINE_4),expenseLineId,expense.getCompany().getName()),IException.CONFIGURATION_ERROR);
    }
    exTaxTotal=expenseLine.getUntaxedAmount();
    MoveLine moveLine=moveLineService.createMoveLine(move,expense.getUser().getPartner(),account,exTaxTotal,true,moveDate,moveDate,moveLineId++,"String_Node_Str");
    for (    AnalyticDistributionLine analyticDistributionLineIt : expenseLine.getAnalyticDistributionLineList()) {
      AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
      analyticDistributionLine.setExpenseLine(null);
      moveLine.addAnalyticDistributionLineListItem(analyticDistributionLine);
    }
    moveLines.add(moveLine);
    expenseLineId++;
  }
  moveLineService.consolidateMoveLines(moveLines);
  account=accountConfigService.getExpenseTaxAccount(accountConfig);
  BigDecimal taxTotal=BigDecimal.ZERO;
  for (  ExpenseLine expenseLine : expense.getExpenseLineList()) {
    exTaxTotal=expenseLine.getTotalTax();
    taxTotal=taxTotal.add(exTaxTotal);
  }
  MoveLine moveLine=moveLineService.createMoveLine(move,expense.getUser().getPartner(),account,taxTotal,true,moveDate,moveDate,moveLineId++,"String_Node_Str");
  moveLines.add(moveLine);
  move.getMoveLineList().addAll(moveLines);
  moveService.getMoveValidateService().validateMove(move);
  expense.setMove(move);
  expense.setVentilated(true);
  expenseRepository.save(expense);
  return move;
}

Fixed version (ground truth):
@Transactional(rollbackOn={AxelorException.class,Exception.class}) public Move ventilate(Expense expense) throws AxelorException {
  LocalDate moveDate=expense.getMoveDate();
  if (moveDate == null) {
    moveDate=generalService.getTodayDate();
  }
  Account account=null;
  AccountConfig accountConfig=accountConfigService.getAccountConfig(expense.getCompany());
  if (expense.getUser().getPartner() == null) {
    throw new AxelorException(String.format(I18n.get(com.axelor.apps.account.exception.IExceptionMessage.USER_PARTNER),expense.getUser().getName()),IException.CONFIGURATION_ERROR);
  }
  Move move=moveService.getMoveCreateService().createMove(accountConfigService.getExpenseJournal(accountConfig),accountConfig.getCompany(),null,expense.getUser().getPartner(),moveDate,expense.getUser().getPartner().getPaymentMode(),MoveRepository.AUTOMATIC);
  List<MoveLine> moveLines=new ArrayList<MoveLine>();
  AccountManagement accountManagement=null;
  Set<AnalyticAccount> analyticAccounts=new HashSet<AnalyticAccount>();
  BigDecimal exTaxTotal=null;
  int moveLineId=1;
  int expenseLineId=1;
  moveLines.add(moveLineService.createMoveLine(move,expense.getUser().getPartner(),accountConfigService.getExpenseEmployeeAccount(accountConfig),expense.getInTaxTotal(),false,moveDate,moveDate,moveLineId++,"String_Node_Str"));
  for (  ExpenseLine expenseLine : expense.getExpenseLineList()) {
    analyticAccounts.clear();
    Product product=expenseLine.getExpenseProduct();
    accountManagement=accountManagementService.getAccountManagement(product,expense.getCompany());
    account=accountManagementService.getProductAccount(accountManagement,true);
    if (account == null) {
      throw new AxelorException(String.format(I18n.get(com.axelor.apps.account.exception.IExceptionMessage.MOVE_LINE_4),expenseLineId,expense.getCompany().getName()),IException.CONFIGURATION_ERROR);
    }
    exTaxTotal=expenseLine.getUntaxedAmount();
    MoveLine moveLine=moveLineService.createMoveLine(move,expense.getUser().getPartner(),account,exTaxTotal,true,moveDate,moveDate,moveLineId++,"String_Node_Str");
    for (    AnalyticDistributionLine analyticDistributionLineIt : expenseLine.getAnalyticDistributionLineList()) {
      AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
      analyticDistributionLine.setExpenseLine(null);
      moveLine.addAnalyticDistributionLineListItem(analyticDistributionLine);
    }
    moveLines.add(moveLine);
    expenseLineId++;
  }
  moveLineService.consolidateMoveLines(moveLines);
  account=accountConfigService.getExpenseTaxAccount(accountConfig);
  BigDecimal taxTotal=BigDecimal.ZERO;
  for (  ExpenseLine expenseLine : expense.getExpenseLineList()) {
    exTaxTotal=expenseLine.getTotalTax();
    taxTotal=taxTotal.add(exTaxTotal);
  }
  MoveLine moveLine=moveLineService.createMoveLine(move,expense.getUser().getPartner(),account,taxTotal,true,moveDate,moveDate,moveLineId++,"String_Node_Str");
  moveLines.add(moveLine);
  move.getMoveLineList().addAll(moveLines);
  moveService.getMoveValidateService().validateMove(move);
  expense.setMove(move);
  expense.setVentilated(true);
  expenseRepository.save(expense);
  return move;
}