Program: 58696
Project: 58696
Buggy source:
/** 
 * Method to cancel an invoice Payment Cancel the eventual Move and Reconcile Compute the total amount paid on the linked invoice Change the status to cancel
 * @param invoicePayment An invoice payment
 * @throws AxelorException
 */
@Transactional(rollbackOn={AxelorException.class,Exception.class}) public void cancel(InvoicePayment invoicePayment) throws AxelorException {
  Move paymentMove=invoicePayment.getMove();
  BankOrder paymentBankOrder=invoicePayment.getBankOrder();
  Reconcile reconcile=invoicePayment.getReconcile();
  if (paymentBankOrder != null) {
    if (paymentBankOrder.getStatusSelect() == BankOrderRepository.STATUS_CARRIED_OUT || paymentBankOrder.getStatusSelect() == BankOrderRepository.STATUS_REJECTED) {
      throw new AxelorException(I18n.get(IExceptionMessage.INVOICE_PAYMENT_CANCEL),IException.FUNCTIONNAL);
    }
 else {
      bankOrderService.cancelBankOrder(paymentBankOrder);
      this.updateCancelStatus(invoicePayment);
    }
  }
 else {
    log.debug("String_Node_Str",reconcile);
    if (reconcile != null && reconcile.getStatusSelect() == ReconcileRepository.STATUS_CONFIRMED) {
      reconcileService.unreconcile(reconcile);
      if (accountConfigService.getAccountConfig(invoicePayment.getInvoice().getCompany()).getAllowRemovalValidatedMove()) {
        invoicePayment.setReconcile(null);
        Beans.get(ReconcileRepository.class).remove(reconcile);
      }
    }
    if (paymentMove != null && invoicePayment.getTypeSelect() == InvoicePaymentRepository.TYPE_PAYMENT) {
      invoicePayment.setMove(null);
      moveCancelService.cancel(paymentMove);
    }
  }
}

Fixed version (ground truth):
/** 
 * Method to cancel an invoice Payment Cancel the eventual Move and Reconcile Compute the total amount paid on the linked invoice Change the status to cancel
 * @param invoicePayment An invoice payment
 * @throws AxelorException
 */
@Transactional(rollbackOn={AxelorException.class,Exception.class}) public void cancel(InvoicePayment invoicePayment) throws AxelorException {
  Move paymentMove=invoicePayment.getMove();
  BankOrder paymentBankOrder=invoicePayment.getBankOrder();
  Reconcile reconcile=invoicePayment.getReconcile();
  if (paymentBankOrder != null) {
    if (paymentBankOrder.getStatusSelect() == BankOrderRepository.STATUS_CARRIED_OUT || paymentBankOrder.getStatusSelect() == BankOrderRepository.STATUS_REJECTED) {
      throw new AxelorException(I18n.get(IExceptionMessage.INVOICE_PAYMENT_CANCEL),IException.FUNCTIONNAL);
    }
 else {
      bankOrderService.cancelBankOrder(paymentBankOrder);
      this.updateCancelStatus(invoicePayment);
    }
  }
 else {
    log.debug("String_Node_Str",reconcile);
    if (reconcile != null && reconcile.getStatusSelect() == ReconcileRepository.STATUS_CONFIRMED) {
      reconcileService.unreconcile(reconcile);
      if (accountConfigService.getAccountConfig(invoicePayment.getInvoice().getCompany()).getAllowRemovalValidatedMove()) {
        invoicePayment.setReconcile(null);
        Beans.get(ReconcileRepository.class).remove(reconcile);
      }
    }
    if (paymentMove != null && invoicePayment.getTypeSelect() == InvoicePaymentRepository.TYPE_PAYMENT) {
      invoicePayment.setMove(null);
      moveCancelService.cancel(paymentMove);
    }
 else {
      this.updateCancelStatus(invoicePayment);
    }
  }
}