Program: 58780
Project: 58780
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>();
  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()) {
    if (invoiceLine.getProduct() != null) {
      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);
        }
        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());
        for (        AnalyticDistributionLine analyticDistributionLineIt : invoiceLine.getAnalyticDistributionLineList()) {
          AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
          moveLine.addAnalyticDistributionLineListItem(analyticDistributionLine);
        }
        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;
}

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(I18n.get(IExceptionMessage.MOVE_LINE_1),IException.MISSING_FIELD,invoice.getInvoiceId());
  }
  if (account2 == null) {
    throw new AxelorException(I18n.get(IExceptionMessage.MOVE_LINE_2),IException.MISSING_FIELD,invoice.getInvoiceId());
  }
  moveLines.add(this.createMoveLine(move,partner,account2,invoice.getCompanyInTaxTotal(),isDebitCustomer,invoice.getInvoiceDate(),invoice.getDueDate(),moveLineId++,invoice.getInvoiceId()));
  for (  InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
    if (invoiceLine.getProduct() != null) {
      BigDecimal exTaxTotal=invoiceLine.getCompanyExTaxTotal();
      if (exTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
        analyticAccounts.clear();
        Product product=invoiceLine.getProduct();
        if (product == null) {
          throw new AxelorException(I18n.get(IExceptionMessage.MOVE_LINE_3),IException.CONFIGURATION_ERROR,invoice.getInvoiceId(),company.getName());
        }
        accountManagement=accountManagementService.getAccountManagement(product,company);
        account2=accountManagementService.getProductAccount(accountManagement,isPurchase);
        if (account2 == null) {
          throw new AxelorException(I18n.get(IExceptionMessage.MOVE_LINE_4),IException.CONFIGURATION_ERROR,invoiceLine.getName(),company.getName());
        }
        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());
        for (        AnalyticDistributionLine analyticDistributionLineIt : invoiceLine.getAnalyticDistributionLineList()) {
          AnalyticDistributionLine analyticDistributionLine=Beans.get(AnalyticDistributionLineRepository.class).copy(analyticDistributionLineIt,false);
          moveLine.addAnalyticDistributionLineListItem(analyticDistributionLine);
        }
        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(I18n.get(IExceptionMessage.MOVE_LINE_6),IException.CONFIGURATION_ERROR,tax.getName(),company.getName());
      }
      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;
}