klydekushy commited on
Commit
018a533
·
verified ·
1 Parent(s): 8e24fe8

Update src/modules/loans_engine.py

Browse files
Files changed (1) hide show
  1. src/modules/loans_engine.py +20 -1
src/modules/loans_engine.py CHANGED
@@ -720,7 +720,26 @@ def show_loans_engine(client, sheet_name):
720
 
721
  # Calcul de l'ID sous forme PRT-2026-xxxx
722
  current_year = datetime.now().year
723
- new_id = f"PRT-{current_year}-{len(ws_prets.get_all_values()):04d}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
724
 
725
  # ORDRE STRICT DEMANDÉ POUR Prets_Master
726
  row_data = [
 
720
 
721
  # Calcul de l'ID sous forme PRT-2026-xxxx
722
  current_year = datetime.now().year
723
+ # Récupère tous les ID existants
724
+ all_rows = ws_prets.get_all_values()
725
+
726
+ if len(all_rows) <= 1:
727
+ next_number = 1
728
+ else:
729
+ # Extrait tous les numéros existants pour l'année en cours
730
+ existing_numbers = []
731
+ for row in all_rows[1:]: # Ignore l'en-tête
732
+ if row[0].startswith(f"PRT-{current_year}-"):
733
+ try:
734
+ num = int(row[0].split('-')[-1])
735
+ existing_numbers.append(num)
736
+ except:
737
+ continue
738
+
739
+ # Prend le max + 1, ou 1 si aucun prêt cette année
740
+ next_number = max(existing_numbers) + 1 if existing_numbers else 1
741
+
742
+ new_id = f"PRT-{current_year}-{next_number:04d}"
743
 
744
  # ORDRE STRICT DEMANDÉ POUR Prets_Master
745
  row_data = [