Program: 59185
Project: 59185
Buggy source:
/** 
 * Il crée des écritures de trop percu avec des montants exacts pour chaque débitMoveLines  avec le compte du débitMoveLines. A la fin, si il reste un trop-percu alors créer un trop-perçu classique.
 * @param debitMoveLines Les lignes d'écriture à payer
 * @param remainingPaidAmount Le montant restant à payer
 * @param move	Une écriture
 * @param moveLineNo Un numéro de ligne d'écriture
 * @return 
 * @throws AxelorException
 */
public int createExcessPaymentWithAmount(List<MoveLine> debitMoveLines,BigDecimal remainingPaidAmount,Move move,int moveLineNo,Partner partner,Company company,PaymentInvoiceToPay paymentInvoiceToPay,Account account,LocalDate paymentDate,boolean updateCustomerAccount) throws AxelorException {
  LOG.debug("String_Node_Str");
  int moveLineNo2=moveLineNo;
  BigDecimal remainingPaidAmount2=remainingPaidAmount;
  List<Reconcile> reconcileList=new ArrayList<Reconcile>();
  int i=debitMoveLines.size();
  for (  MoveLine debitMoveLine : debitMoveLines) {
    i--;
    BigDecimal amountRemaining=debitMoveLine.getAmountRemaining();
    if (remainingPaidAmount2.compareTo(BigDecimal.ZERO) < 0) {
      break;
    }
    BigDecimal amountToPay=remainingPaidAmount2.min(amountRemaining);
    String invoiceName="String_Node_Str";
    if (debitMoveLine.getMove().getInvoice() != null) {
      invoiceName=debitMoveLine.getMove().getInvoice().getInvoiceId();
    }
 else {
      invoiceName=paymentInvoiceToPay.getPaymentVoucher().getRef();
    }
    MoveLine creditMoveLine=mls.createMoveLine(move,debitMoveLine.getPartner(),debitMoveLine.getAccount(),amountToPay,false,false,this.date,moveLineNo2,false,false,false,invoiceName);
    move.getMoveLineList().add(creditMoveLine);
    if (paymentInvoiceToPay != null) {
      creditMoveLine.setPaymentScheduleLine(paymentInvoiceToPay.getMoveLine().getPaymentScheduleLine());
      paymentInvoiceToPay.setMoveLineGenerated(creditMoveLine);
    }
    moveLineNo2++;
    Reconcile reconcile=null;
    if (i == 0) {
      LOG.debug("String_Node_Str");
      if (creditMoveLine.getPaymentScheduleLine() != null && !pss.isLastSchedule(creditMoveLine.getPaymentScheduleLine())) {
        reconcile=rcs.createGenericReconcile(debitMoveLine,creditMoveLine,amountToPay,false,false,false);
      }
 else {
        reconcile=rcs.createGenericReconcile(debitMoveLine,creditMoveLine,amountToPay,true,false,false);
      }
    }
 else {
      reconcile=rcs.createGenericReconcile(debitMoveLine,creditMoveLine,amountToPay,false,false,false);
    }
    reconcileList.add(reconcile);
    remainingPaidAmount2=remainingPaidAmount2.subtract(amountRemaining);
  }
  for (  Reconcile reconcile : reconcileList) {
    rs.confirmReconcile(reconcile,updateCustomerAccount);
  }
  if (remainingPaidAmount2.compareTo(BigDecimal.ZERO) > 0) {
    MoveLine moveLine=mls.createMoveLine(move,partner,account,remainingPaidAmount2,false,false,this.date,moveLineNo2,false,false,false,null);
    move.getMoveLineList().add(moveLine);
    moveLineNo2++;
    rs.balanceCredit(moveLine,company,updateCustomerAccount);
  }
  LOG.debug("String_Node_Str");
  return moveLineNo2;
}

Fixed version (ground truth):
/** 
 * Il crée des écritures de trop percu avec des montants exacts pour chaque débitMoveLines  avec le compte du débitMoveLines. A la fin, si il reste un trop-percu alors créer un trop-perçu classique.
 * @param debitMoveLines Les lignes d'écriture à payer
 * @param remainingPaidAmount Le montant restant à payer
 * @param move	Une écriture
 * @param moveLineNo Un numéro de ligne d'écriture
 * @return 
 * @throws AxelorException
 */
public int createExcessPaymentWithAmount(List<MoveLine> debitMoveLines,BigDecimal remainingPaidAmount,Move move,int moveLineNo,Partner partner,Company company,PaymentInvoiceToPay paymentInvoiceToPay,Account account,LocalDate paymentDate,boolean updateCustomerAccount) throws AxelorException {
  LOG.debug("String_Node_Str");
  int moveLineNo2=moveLineNo;
  BigDecimal remainingPaidAmount2=remainingPaidAmount;
  List<Reconcile> reconcileList=new ArrayList<Reconcile>();
  int i=debitMoveLines.size();
  for (  MoveLine debitMoveLine : debitMoveLines) {
    i--;
    BigDecimal amountRemaining=debitMoveLine.getAmountRemaining();
    if (remainingPaidAmount2.compareTo(BigDecimal.ZERO) <= 0) {
      break;
    }
    BigDecimal amountToPay=remainingPaidAmount2.min(amountRemaining);
    String invoiceName="String_Node_Str";
    if (debitMoveLine.getMove().getInvoice() != null) {
      invoiceName=debitMoveLine.getMove().getInvoice().getInvoiceId();
    }
 else {
      invoiceName=paymentInvoiceToPay.getPaymentVoucher().getRef();
    }
    MoveLine creditMoveLine=mls.createMoveLine(move,debitMoveLine.getPartner(),debitMoveLine.getAccount(),amountToPay,false,false,this.date,moveLineNo2,false,false,false,invoiceName);
    move.getMoveLineList().add(creditMoveLine);
    if (paymentInvoiceToPay != null) {
      creditMoveLine.setPaymentScheduleLine(paymentInvoiceToPay.getMoveLine().getPaymentScheduleLine());
      paymentInvoiceToPay.setMoveLineGenerated(creditMoveLine);
    }
    moveLineNo2++;
    Reconcile reconcile=null;
    if (i == 0) {
      LOG.debug("String_Node_Str");
      if (creditMoveLine.getPaymentScheduleLine() != null && !pss.isLastSchedule(creditMoveLine.getPaymentScheduleLine())) {
        reconcile=rcs.createGenericReconcile(debitMoveLine,creditMoveLine,amountToPay,false,false,false);
      }
 else {
        reconcile=rcs.createGenericReconcile(debitMoveLine,creditMoveLine,amountToPay,true,false,false);
      }
    }
 else {
      reconcile=rcs.createGenericReconcile(debitMoveLine,creditMoveLine,amountToPay,false,false,false);
    }
    reconcileList.add(reconcile);
    remainingPaidAmount2=remainingPaidAmount2.subtract(amountRemaining);
  }
  for (  Reconcile reconcile : reconcileList) {
    rs.confirmReconcile(reconcile,updateCustomerAccount);
  }
  if (remainingPaidAmount2.compareTo(BigDecimal.ZERO) > 0) {
    MoveLine moveLine=mls.createMoveLine(move,partner,account,remainingPaidAmount2,false,false,this.date,moveLineNo2,false,false,false,null);
    move.getMoveLineList().add(moveLine);
    moveLineNo2++;
    rs.balanceCredit(moveLine,company,updateCustomerAccount);
  }
  LOG.debug("String_Node_Str");
  return moveLineNo2;
}