Program: 58870
Project: 58870
Buggy source:
/** 
 * Créer les lignes d'écritures comptables d'une facture.
 * @param invoice
 * @param move
 * @param consolidate
 * @return
 */
public List<MoveLine> createMoveLines(Invoice invoice,Move move,Company company,Partner partner,Account account,boolean consolidate,boolean isPurchase,boolean isDebitCustomer) throws AxelorException {
  LOG.debug("String_Node_Str",invoice.getInvoiceId());
  Account account2=account;
  List<MoveLine> moveLines=new ArrayList<MoveLine>();
  AccountManagement accountManagement=null;
  Set<AnalyticAccount> analyticAccounts=new HashSet<AnalyticAccount>();
  BigDecimal exTaxTotal=null;
  int moveLineId=1;
  if (partner == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_1),invoice.getInvoiceId()),IException.MISSING_FIELD);
  }
  if (account2 == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_2),invoice.getInvoiceId()),IException.MISSING_FIELD);
  }
  moveLines.add(this.createMoveLine(move,partner,account2,invoice.getCompanyInTaxTotal(),isDebitCustomer,invoice.getInvoiceDate(),invoice.getDueDate(),moveLineId++,invoice.getInvoiceId()));
  for (  InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
    analyticAccounts.clear();
    Product product=invoiceLine.getProduct();
    if (product == null) {
      throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_3),invoice.getInvoiceId(),company.getName()),IException.CONFIGURATION_ERROR);
    }
    accountManagement=accountManagementService.getAccountManagement(product,company);
    account2=accountManagementService.getProductAccount(accountManagement,isPurchase);
    if (account2 == null) {
      throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_4),invoiceLine.getName(),company.getName()),IException.CONFIGURATION_ERROR);
    }
    for (    AnalyticAccountManagement analyticAccountManagement : accountManagement.getAnalyticAccountManagementList()) {
      if (analyticAccountManagement.getAnalyticAccount() == null) {
        throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_5),analyticAccountManagement.getAnalyticAxis().getName(),invoiceLine.getProductName(),company.getName()),IException.CONFIGURATION_ERROR);
      }
      analyticAccounts.add(analyticAccountManagement.getAnalyticAccount());
    }
    exTaxTotal=invoiceLine.getCompanyExTaxTotal();
    LOG.debug("String_Node_Str",new Object[]{account2.getName(),exTaxTotal});
    if (exTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
      MoveLine moveLine=this.createMoveLine(move,partner,account2,exTaxTotal,!isDebitCustomer,invoice.getInvoiceDate(),null,moveLineId++,invoice.getInvoiceId());
      moveLine.setAnalyticAccountSet(analyticAccounts);
      moveLine.setTaxLine(invoiceLine.getTaxLine());
      moveLines.add(moveLine);
    }
  }
  for (  InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
    Tax tax=invoiceLineTax.getTaxLine().getTax();
    account2=taxAccountService.getAccount(tax,company);
    exTaxTotal=invoiceLineTax.getCompanyTaxTotal();
    if (account2 == null) {
      throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_6),tax.getName(),company.getName()),IException.CONFIGURATION_ERROR);
    }
    if (exTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
      MoveLine moveLine=this.createMoveLine(move,partner,account2,exTaxTotal,!isDebitCustomer,invoice.getInvoiceDate(),null,moveLineId++,invoice.getInvoiceId());
      moveLine.setTaxLine(invoiceLineTax.getTaxLine());
      moveLines.add(moveLine);
    }
  }
  if (consolidate) {
    this.consolidateMoveLines(moveLines);
  }
  return moveLines;
}

Fixed version (ground truth):
/** 
 * Créer les lignes d'écritures comptables d'une facture.
 * @param invoice
 * @param move
 * @param consolidate
 * @return
 */
public List<MoveLine> createMoveLines(Invoice invoice,Move move,Company company,Partner partner,Account account,boolean consolidate,boolean isPurchase,boolean isDebitCustomer) throws AxelorException {
  LOG.debug("String_Node_Str",invoice.getInvoiceId());
  Account account2=account;
  List<MoveLine> moveLines=new ArrayList<MoveLine>();
  AccountManagement accountManagement=null;
  Set<AnalyticAccount> analyticAccounts=new HashSet<AnalyticAccount>();
  int moveLineId=1;
  if (partner == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_1),invoice.getInvoiceId()),IException.MISSING_FIELD);
  }
  if (account2 == null) {
    throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_2),invoice.getInvoiceId()),IException.MISSING_FIELD);
  }
  moveLines.add(this.createMoveLine(move,partner,account2,invoice.getCompanyInTaxTotal(),isDebitCustomer,invoice.getInvoiceDate(),invoice.getDueDate(),moveLineId++,invoice.getInvoiceId()));
  for (  InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
    BigDecimal exTaxTotal=invoiceLine.getCompanyExTaxTotal();
    if (exTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
      analyticAccounts.clear();
      Product product=invoiceLine.getProduct();
      if (product == null) {
        throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_3),invoice.getInvoiceId(),company.getName()),IException.CONFIGURATION_ERROR);
      }
      accountManagement=accountManagementService.getAccountManagement(product,company);
      account2=accountManagementService.getProductAccount(accountManagement,isPurchase);
      if (account2 == null) {
        throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_4),invoiceLine.getName(),company.getName()),IException.CONFIGURATION_ERROR);
      }
      for (      AnalyticAccountManagement analyticAccountManagement : accountManagement.getAnalyticAccountManagementList()) {
        if (analyticAccountManagement.getAnalyticAccount() == null) {
          throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_5),analyticAccountManagement.getAnalyticAxis().getName(),invoiceLine.getProductName(),company.getName()),IException.CONFIGURATION_ERROR);
        }
        analyticAccounts.add(analyticAccountManagement.getAnalyticAccount());
      }
      exTaxTotal=invoiceLine.getCompanyExTaxTotal();
      LOG.debug("String_Node_Str",new Object[]{account2.getName(),exTaxTotal});
      MoveLine moveLine=this.createMoveLine(move,partner,account2,exTaxTotal,!isDebitCustomer,invoice.getInvoiceDate(),null,moveLineId++,invoice.getInvoiceId());
      moveLine.setAnalyticAccountSet(analyticAccounts);
      moveLine.setTaxLine(invoiceLine.getTaxLine());
      moveLines.add(moveLine);
    }
  }
  for (  InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
    BigDecimal exTaxTotal=invoiceLineTax.getCompanyTaxTotal();
    if (exTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
      Tax tax=invoiceLineTax.getTaxLine().getTax();
      account2=taxAccountService.getAccount(tax,company);
      if (account2 == null) {
        throw new AxelorException(String.format(I18n.get(IExceptionMessage.MOVE_LINE_6),tax.getName(),company.getName()),IException.CONFIGURATION_ERROR);
      }
      MoveLine moveLine=this.createMoveLine(move,partner,account2,exTaxTotal,!isDebitCustomer,invoice.getInvoiceDate(),null,moveLineId++,invoice.getInvoiceId());
      moveLine.setTaxLine(invoiceLineTax.getTaxLine());
      moveLines.add(moveLine);
    }
  }
  if (consolidate) {
    this.consolidateMoveLines(moveLines);
  }
  return moveLines;
}