Spaces:
Running
Running
Update src/modules/Check_Up_Loans.py
Browse files
src/modules/Check_Up_Loans.py
CHANGED
|
@@ -38,7 +38,7 @@ def refresh_data():
|
|
| 38 |
|
| 39 |
|
| 40 |
# ============================================================================
|
| 41 |
-
#
|
| 42 |
# ============================================================================
|
| 43 |
|
| 44 |
def clean_currency_value(val):
|
|
@@ -57,6 +57,26 @@ def clean_currency_value(val):
|
|
| 57 |
return 0.0
|
| 58 |
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
# ============================================================================
|
| 61 |
# STYLES CSS SPÉCIFIQUES AU MODULE CHECK_UP_LOANS
|
| 62 |
# ============================================================================
|
|
@@ -452,10 +472,10 @@ def show_check_up_loans(client, sheet_name):
|
|
| 452 |
st.markdown('<div class="checkup-loan-card">', unsafe_allow_html=True)
|
| 453 |
st.markdown(f"### Prêt {loan_id}")
|
| 454 |
|
| 455 |
-
#
|
| 456 |
montant_capital_actuel = clean_currency_value(selected_loan['Montant_Capital'])
|
| 457 |
taux_hebdo_actuel = clean_taux_value(selected_loan['Taux_Hebdo'])
|
| 458 |
-
taux_endettement_actuel =
|
| 459 |
duree_semaines_actuel = clean_currency_value(selected_loan['Duree_Semaines'])
|
| 460 |
montant_total_actuel = clean_currency_value(selected_loan['Montant_Total'])
|
| 461 |
cout_credit_actuel = clean_currency_value(selected_loan['Cout_Credit'])
|
|
@@ -470,7 +490,7 @@ def show_check_up_loans(client, sheet_name):
|
|
| 470 |
|
| 471 |
with col2:
|
| 472 |
st.metric("Taux hebdomadaire", f"{taux_hebdo_actuel}%")
|
| 473 |
-
st.metric("Taux d'endettement", f"{taux_endettement_actuel}%") # ✅ Maintenant
|
| 474 |
st.metric("Durée", f"{int(duree_semaines_actuel)} semaines")
|
| 475 |
st.metric("Moyen de transfert", selected_loan.get('Moyen_Transfert', 'N/A'))
|
| 476 |
|
|
@@ -770,15 +790,24 @@ def show_check_up_loans(client, sheet_name):
|
|
| 770 |
st.session_state.dates_perso_update.append(last_date + timedelta(weeks=1))
|
| 771 |
st.rerun()
|
| 772 |
|
| 773 |
-
#
|
| 774 |
nouvelles_dates_versements = []
|
| 775 |
for idx, dt in enumerate(st.session_state.dates_perso_update):
|
| 776 |
col_d, col_x = st.columns([4, 1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 777 |
new_date = col_d.date_input(
|
| 778 |
f"Echéance {idx+1}",
|
| 779 |
-
value=
|
| 780 |
key=f"d_update_{idx}",
|
| 781 |
-
min_value=
|
| 782 |
)
|
| 783 |
nouvelles_dates_versements.append(new_date)
|
| 784 |
if col_x.button("♦️", key=f"del_update_{idx}") and len(st.session_state.dates_perso_update) > 1:
|
|
@@ -867,7 +896,7 @@ def show_check_up_loans(client, sheet_name):
|
|
| 867 |
selected_loan['Type_Pret'],
|
| 868 |
f"{int(montant_capital_actuel):,} XOF".replace(",", " "),
|
| 869 |
f"{taux_hebdo_actuel}%",
|
| 870 |
-
f"{taux_endettement_actuel}%" if taux_endettement_actuel > 0 else "N/A", # ✅ Maintenant correct
|
| 871 |
f"{int(duree_semaines_actuel)} semaines",
|
| 872 |
f"{int(montant_total_actuel):,} XOF".replace(",", " "),
|
| 873 |
f"{int(cout_credit_actuel):,} XOF".replace(",", " "),
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
# ============================================================================
|
| 41 |
+
# ✅ CORRECTION 1 : FONCTIONS UTILITAIRES AVEC GESTION VIRGULE/POINT
|
| 42 |
# ============================================================================
|
| 43 |
|
| 44 |
def clean_currency_value(val):
|
|
|
|
| 57 |
return 0.0
|
| 58 |
|
| 59 |
|
| 60 |
+
def clean_percentage_value_local(val):
|
| 61 |
+
"""
|
| 62 |
+
✅ CORRECTION PROBLÈME 1 : Convertit un pourcentage avec virgule en float
|
| 63 |
+
Exemple : "54,94" → 54.94 (et non 5494.0)
|
| 64 |
+
"""
|
| 65 |
+
try:
|
| 66 |
+
if isinstance(val, (int, float)):
|
| 67 |
+
return float(val)
|
| 68 |
+
|
| 69 |
+
# Convertir en string et nettoyer
|
| 70 |
+
cleaned = str(val).strip().replace(" ", "").replace("%", "")
|
| 71 |
+
|
| 72 |
+
# ✅ CRUCIAL : Remplacer la virgule par un point (format Python)
|
| 73 |
+
cleaned = cleaned.replace(",", ".")
|
| 74 |
+
|
| 75 |
+
return float(cleaned) if cleaned else 0.0
|
| 76 |
+
except (ValueError, AttributeError):
|
| 77 |
+
return 0.0
|
| 78 |
+
|
| 79 |
+
|
| 80 |
# ============================================================================
|
| 81 |
# STYLES CSS SPÉCIFIQUES AU MODULE CHECK_UP_LOANS
|
| 82 |
# ============================================================================
|
|
|
|
| 472 |
st.markdown('<div class="checkup-loan-card">', unsafe_allow_html=True)
|
| 473 |
st.markdown(f"### Prêt {loan_id}")
|
| 474 |
|
| 475 |
+
# ✅ CORRECTION PROBLÈME 1 : Utiliser clean_percentage_value_local au lieu de clean_percentage_value
|
| 476 |
montant_capital_actuel = clean_currency_value(selected_loan['Montant_Capital'])
|
| 477 |
taux_hebdo_actuel = clean_taux_value(selected_loan['Taux_Hebdo'])
|
| 478 |
+
taux_endettement_actuel = clean_percentage_value_local(selected_loan.get('Taux_Endettement', 0)) # ✅ CORRECTION ICI
|
| 479 |
duree_semaines_actuel = clean_currency_value(selected_loan['Duree_Semaines'])
|
| 480 |
montant_total_actuel = clean_currency_value(selected_loan['Montant_Total'])
|
| 481 |
cout_credit_actuel = clean_currency_value(selected_loan['Cout_Credit'])
|
|
|
|
| 490 |
|
| 491 |
with col2:
|
| 492 |
st.metric("Taux hebdomadaire", f"{taux_hebdo_actuel}%")
|
| 493 |
+
st.metric("Taux d'endettement", f"{taux_endettement_actuel:.2f}%") # ✅ Maintenant affiche 54.94%
|
| 494 |
st.metric("Durée", f"{int(duree_semaines_actuel)} semaines")
|
| 495 |
st.metric("Moyen de transfert", selected_loan.get('Moyen_Transfert', 'N/A'))
|
| 496 |
|
|
|
|
| 790 |
st.session_state.dates_perso_update.append(last_date + timedelta(weeks=1))
|
| 791 |
st.rerun()
|
| 792 |
|
| 793 |
+
# ✅ CORRECTION PROBLÈME 2 : Ajuster les dates passées
|
| 794 |
nouvelles_dates_versements = []
|
| 795 |
for idx, dt in enumerate(st.session_state.dates_perso_update):
|
| 796 |
col_d, col_x = st.columns([4, 1])
|
| 797 |
+
|
| 798 |
+
# ✅ CORRECTION : S'assurer que la date par défaut n'est jamais avant aujourd'hui
|
| 799 |
+
today = date.today()
|
| 800 |
+
safe_default_date = max(dt, today) # Prend la plus récente entre la date stockée et aujourd'hui
|
| 801 |
+
|
| 802 |
+
# Afficher un warning si la date a été ajustée
|
| 803 |
+
if dt < today and idx == 0:
|
| 804 |
+
st.warning(f"⚠️ La date originale ({dt.strftime('%d/%m/%Y')}) est passée. Ajustée à aujourd'hui ({today.strftime('%d/%m/%Y')}).")
|
| 805 |
+
|
| 806 |
new_date = col_d.date_input(
|
| 807 |
f"Echéance {idx+1}",
|
| 808 |
+
value=safe_default_date, # ✅ CORRECTION : Utiliser safe_default_date
|
| 809 |
key=f"d_update_{idx}",
|
| 810 |
+
min_value=today # min_value = aujourd'hui
|
| 811 |
)
|
| 812 |
nouvelles_dates_versements.append(new_date)
|
| 813 |
if col_x.button("♦️", key=f"del_update_{idx}") and len(st.session_state.dates_perso_update) > 1:
|
|
|
|
| 896 |
selected_loan['Type_Pret'],
|
| 897 |
f"{int(montant_capital_actuel):,} XOF".replace(",", " "),
|
| 898 |
f"{taux_hebdo_actuel}%",
|
| 899 |
+
f"{taux_endettement_actuel:.2f}%" if taux_endettement_actuel > 0 else "N/A", # ✅ Maintenant correct
|
| 900 |
f"{int(duree_semaines_actuel)} semaines",
|
| 901 |
f"{int(montant_total_actuel):,} XOF".replace(",", " "),
|
| 902 |
f"{int(cout_credit_actuel):,} XOF".replace(",", " "),
|