Program: 59082
Project: 59082
Buggy source:
/** 
 * Allows to load the moveLine selected in header (invoice, schedule or rejected moveLine) directly in the 2nd O2M
 * @param paymentVoucher
 * @param moveLine
 * @param lineSeq
 * @param paymentVoucherContext
 * @return
 * @throws AxelorException 
 */
public List<PaymentInvoiceToPay> loadOneLine(PaymentVoucher paymentVoucher,MoveLine moveLine,int lineSeq) throws AxelorException {
  LOG.debug("String_Node_Str");
  List<PaymentInvoiceToPay> piToPayLine=new ArrayList<PaymentInvoiceToPay>();
  PaymentInvoiceToPay piToPay=new PaymentInvoiceToPay();
  if (paymentVoucher.getPaidAmount() == null) {
    throw new AxelorException(String.format("String_Node_Str",GeneralService.getExceptionAccountingMsg()),IException.MISSING_FIELD);
  }
  if (moveLine != null) {
    Move move=moveLine.getMove();
    BigDecimal paidAmount=null;
    if (move.getInvoice() != null && move.getInvoice().getCurrency() != move.getCurrency()) {
      LOG.debug("String_Node_Str");
      piToPay.setCurrency(move.getInvoice().getCurrency());
      piToPay.setTotalAmount(move.getInvoice().getInvoiceInTaxTotal());
      piToPay.setRemainingAmount(move.getInvoice().getInvoiceInTaxTotal().subtract(move.getInvoice().getInvoiceAmountPaid()));
      paidAmount=currencyService.getAmountCurrencyConverted(move.getInvoice().getCurrency(),paymentVoucher.getCurrency(),piToPay.getRemainingAmount(),paymentVoucher.getPaymentDateTime().toLocalDate());
    }
 else {
      LOG.debug("String_Node_Str");
      piToPay.setCurrency(move.getCurrency());
      if (moveLine.getDebit().compareTo(moveLine.getCredit()) == 1) {
        piToPay.setTotalAmount(moveLine.getDebit());
      }
 else {
        piToPay.setTotalAmount(moveLine.getCredit());
      }
      piToPay.setRemainingAmount(moveLine.getAmountRemaining());
      paidAmount=currencyService.getAmountCurrencyConverted(move.getCurrency(),paymentVoucher.getCurrency(),moveLine.getAmountRemaining(),paymentVoucher.getPaymentDateTime().toLocalDate());
    }
    LOG.debug("String_Node_Str",paidAmount);
    LOG.debug("String_Node_Str",paymentVoucher.getPaidAmount());
    BigDecimal amountToPay=paidAmount.min(paymentVoucher.getPaidAmount());
    piToPay.setSequence(lineSeq);
    piToPay.setMoveLine(moveLine);
    piToPay.setAmountToPay(amountToPay);
    piToPay.setPaymentVoucher(paymentVoucher);
    piToPayLine.add(piToPay);
    LOG.debug("String_Node_Str");
    return piToPayLine;
  }
  return piToPayLine;
}

Fixed version (ground truth):
/** 
 * Allows to load the moveLine selected in header (invoice, schedule or rejected moveLine) directly in the 2nd O2M
 * @param paymentVoucher
 * @param moveLine
 * @param lineSeq
 * @param paymentVoucherContext
 * @return
 * @throws AxelorException 
 */
public List<PaymentInvoiceToPay> loadOneLine(PaymentVoucher paymentVoucher,MoveLine moveLine,int lineSeq) throws AxelorException {
  LOG.debug("String_Node_Str");
  List<PaymentInvoiceToPay> paymentInvoiceToPayList=new ArrayList<PaymentInvoiceToPay>();
  PaymentInvoiceToPay paymentInvoiceToPay=new PaymentInvoiceToPay();
  if (paymentVoucher.getPaidAmount() == null) {
    throw new AxelorException(String.format("String_Node_Str",GeneralService.getExceptionAccountingMsg()),IException.MISSING_FIELD);
  }
  if (moveLine == null) {
    return paymentInvoiceToPayList;
  }
  Move move=moveLine.getMove();
  BigDecimal paidAmount=null;
  if (move.getInvoice() != null && move.getInvoice().getCurrency() != move.getCurrency()) {
    LOG.debug("String_Node_Str");
    paymentInvoiceToPay.setCurrency(move.getInvoice().getCurrency());
    paymentInvoiceToPay.setTotalAmount(move.getInvoice().getInvoiceInTaxTotal());
    paymentInvoiceToPay.setRemainingAmount(move.getInvoice().getInvoiceInTaxTotal().subtract(move.getInvoice().getInvoiceAmountPaid()));
    paidAmount=currencyService.getAmountCurrencyConverted(move.getInvoice().getCurrency(),paymentVoucher.getCurrency(),paymentInvoiceToPay.getRemainingAmount(),paymentVoucher.getPaymentDateTime().toLocalDate());
  }
 else {
    LOG.debug("String_Node_Str");
    paymentInvoiceToPay.setCurrency(move.getCurrency());
    if (moveLine.getDebit().compareTo(moveLine.getCredit()) == 1) {
      paymentInvoiceToPay.setTotalAmount(moveLine.getDebit());
    }
 else {
      paymentInvoiceToPay.setTotalAmount(moveLine.getCredit());
    }
    paymentInvoiceToPay.setRemainingAmount(moveLine.getAmountRemaining());
    paidAmount=currencyService.getAmountCurrencyConverted(move.getCurrency(),paymentVoucher.getCurrency(),moveLine.getAmountRemaining(),paymentVoucher.getPaymentDateTime().toLocalDate());
  }
  LOG.debug("String_Node_Str",paidAmount);
  LOG.debug("String_Node_Str",paymentVoucher.getPaidAmount());
  BigDecimal amountToPay=paidAmount.min(paymentVoucher.getPaidAmount());
  paymentInvoiceToPay.setSequence(lineSeq);
  paymentInvoiceToPay.setMoveLine(moveLine);
  paymentInvoiceToPay.setAmountToPay(amountToPay);
  paymentInvoiceToPay.setPaymentVoucher(paymentVoucher);
  paymentInvoiceToPayList.add(paymentInvoiceToPay);
  LOG.debug("String_Node_Str");
  return paymentInvoiceToPayList;
}