Program: 59156
Project: 59156
Buggy source:
/** 
 * Méthode permettant d'employer les trop-perçus 2 cas :  - le compte des trop-perçus est le même que celui de la facture : alors on lettre directement - le compte n'est pas le même : on créée une O.D. de passage sur le bon compte
 * @param invoice
 * @return
 * @throws AxelorException
 */
public Move createMoveUseExcessPayment(Invoice invoice,boolean isDebitCustomer) throws AxelorException {
  Move move=null;
  if (invoice != null) {
    List<MoveLine> creditMoveLineList=pas.getExcessPayment(invoice,invoice.getCompany().getCustomerAccount());
    if (creditMoveLineList != null && creditMoveLineList.size() != 0) {
      Company company=invoice.getCompany();
      Partner partner=invoice.getClientPartner();
      Account account=invoice.getPartnerAccount();
      MoveLine invoiceCustomerMoveLine=mls.getCustomerMoveLine(invoice);
      if (company.getMiscOperationJournal() == null) {
        throw new AxelorException(String.format("String_Node_Str",company.getName()),IException.CONFIGURATION_ERROR);
      }
      Journal journal=company.getMiscOperationJournal();
      if (this.isSameAccount(creditMoveLineList,account)) {
        List<MoveLine> debitMoveLineList=new ArrayList<MoveLine>();
        debitMoveLineList.add(invoiceCustomerMoveLine);
        pas.useExcessPaymentOnMoveLines(debitMoveLineList,creditMoveLineList);
      }
 else {
        LOG.debug("String_Node_Str",new Object[]{invoice.getInvoiceId(),company.getName(),journal.getCode()});
        move=this.createMove(journal,company,null,partner,invoice.getInvoiceDate(),null,false);
        if (move != null) {
          BigDecimal totalCreditAmount=this.getTotalCreditAmount(creditMoveLineList);
          BigDecimal amount=totalCreditAmount.min(invoiceCustomerMoveLine.getDebit());
          MoveLine creditMoveLine=mls.createMoveLine(move,partner,account,amount,false,false,toDay,1,false,false,false,null);
          move.getMoveLineList().add(creditMoveLine);
          pas.useExcessPaymentWithAmountConsolidated(creditMoveLineList,amount,move,2,partner,company,account,invoice.getInvoiceDate(),invoice.getDueDate());
          this.validateMove(move);
          Reconcile reconcile=rs.createReconcile(invoiceCustomerMoveLine,creditMoveLine,amount);
          rs.confirmReconcile(reconcile);
        }
      }
      invoice.setInTaxTotalRemaining(this.getInTaxTotalRemaining(invoice,account));
    }
  }
  return move;
}

Fixed version (ground truth):
public Move createMoveUseExcessPayment(Invoice invoice) throws AxelorException {
  Move move=null;
  List<MoveLine> creditMoveLineList=pas.getExcessPayment(invoice,invoice.getCompany().getCustomerAccount());
  if (creditMoveLineList != null && creditMoveLineList.size() != 0) {
    Company company=invoice.getCompany();
    Partner partner=invoice.getClientPartner();
    Account account=invoice.getPartnerAccount();
    MoveLine invoiceCustomerMoveLine=this.getCustomerMoveLine(invoice);
    if (company.getMiscOperationJournal() == null) {
      throw new AxelorException(String.format("String_Node_Str",company.getName()),IException.CONFIGURATION_ERROR);
    }
    Journal journal=company.getMiscOperationJournal();
    if (this.isSameAccount(creditMoveLineList,account)) {
      List<MoveLine> debitMoveLineList=new ArrayList<MoveLine>();
      debitMoveLineList.add(invoiceCustomerMoveLine);
      pas.useExcessPaymentOnMoveLines(debitMoveLineList,creditMoveLineList);
    }
 else {
      LOG.debug("String_Node_Str",new Object[]{invoice.getInvoiceId(),company.getName(),journal.getCode()});
      move=this.createMove(journal,company,null,partner,invoice.getInvoiceDate(),null,false);
      if (move != null) {
        BigDecimal totalCreditAmount=this.getTotalCreditAmount(creditMoveLineList);
        BigDecimal amount=totalCreditAmount.min(invoiceCustomerMoveLine.getDebit());
        MoveLine creditMoveLine=mls.createMoveLine(move,partner,account,amount,false,false,toDay,1,false,false,false,null);
        move.getMoveLineList().add(creditMoveLine);
        pas.useExcessPaymentWithAmountConsolidated(creditMoveLineList,amount,move,2,partner,company,account,invoice.getInvoiceDate(),invoice.getDueDate());
        this.validateMove(move);
        Reconcile reconcile=rs.createReconcile(invoiceCustomerMoveLine,creditMoveLine,amount);
        rs.confirmReconcile(reconcile);
      }
    }
    invoice.setInTaxTotalRemaining(this.getInTaxTotalRemaining(invoice,account));
  }
  return move;
}