Program: 59080
Project: 59080
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> 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;
}

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().equals(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(paymentVoucher.getCurrency(),move.getInvoice().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(paymentVoucher.getCurrency(),move.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;
}