#!/usr/bin/env python3
"""
Fix duplicate repayment issue by disabling the duplicate receipt creation signal.

ROOT CAUSE:
-----------
When adding a repayment, TWO pieces of code were both creating receipts:
1. loans/signals.py - create_receipt_for_repayment signal
2. loans/models.py - Repayment.save() method calling create_or_update_receipt()

This caused duplicate receipts/repayments to be created every time.

SOLUTION:
---------
Disabled the signal in loans/signals.py since the Repayment.save() method
already handles receipt creation properly with update logic and error handling.

This script just documents the fix - the actual change is in loans/signals.py
"""

print("""
✓ FIX APPLIED: Disabled duplicate receipt creation signal

The duplicate repayment issue was caused by:
  - loans/signals.py create_receipt_for_repayment signal
  - loans/models.py Repayment.save() -> create_or_update_receipt()
  
Both were firing on new repayments, creating duplicates.

The signal has been commented out. Only Repayment.save() will create receipts now.

TESTING:
--------
1. Restart Django server: systemctl restart phingrazuri (or equivalent)
2. Add a test repayment through the UI
3. Verify only ONE repayment is created (check repayments table)
4. Verify only ONE receipt is created (check receipts table)

If duplicates still occur, check:
  - Database triggers (SHOW TRIGGERS)
  - Other post_save signals for Repayment
  - JavaScript double-submit issues
""")
