diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1a99cbb..c478dff 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,27 +4,183 @@
-
+
-
-
-
+
-
+
-
+
+
+
+
-
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -467,7 +623,7 @@
1747251650255
-
+
@@ -509,7 +665,6 @@
-
@@ -534,6 +689,7 @@
-
+
+
\ No newline at end of file
diff --git a/tools_cherif/tools_cherif.py b/tools_cherif/tools_cherif.py
index a649346..db6a694 100644
--- a/tools_cherif/tools_cherif.py
+++ b/tools_cherif/tools_cherif.py
@@ -2003,3 +2003,230 @@ def Create_Bar_Chart_And_Save(diction):
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de Create_Bar_Chart_And_Save"
+
+"""
+JMJ reprise factures
+"""
+def JMJ_Repise_Factures(diction):
+ try:
+
+ saved_file = "./temp_direct/facture_exemple_fichier_v2_dev.csv"
+ df = pd.read_csv(saved_file, encoding='utf8', on_bad_lines='skip', sep=';', encoding_errors='ignore',
+ skipinitialspace=True)
+ df = df.fillna('')
+ df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
+
+ total_rows = len(df)
+ x = range(0, total_rows)
+ field_list = ['code_client', 'email_client', 'date_echeance', 'date_emission', 'montant_ht',
+ 'montant_ttc', 'num_facture', 'note', 'code_session',
+ 'tax_amount', 'tax_taux', 'annotation', 'facture_initiale', 'type']
+
+ list_client_ko = []
+ list_code_session_ko = []
+
+ list_code_session_kooo = []
+ list_client_kooo = []
+
+ for n in x:
+ client_mail = str(df['email_client'].values[n]).strip()
+ session_formation = str(df['code_session'].values[n]).strip()
+ if( client_mail != "" and session_formation != ""):
+ # Verifier si le client existe
+ is_client_exist = MYSY_GV.dbname['partner_client'].count_documents({"email":client_mail, 'partner_owner_recid':diction['partner_owner_recid']})
+
+ if(is_client_exist <= 0 ):
+ if( client_mail not in list_client_ko ):
+ list_client_ko.append( str(client_mail))
+
+ elif ( is_client_exist > 1 ):
+ print(" Client email : " + str(client_mail) + " == ", is_client_exist)
+
+ else:
+ list_client_kooo.append(str(client_mail))
+
+ # Verifier si la session existe
+ is_session_exist = MYSY_GV.dbname['session_formation'].count_documents({"code_session": session_formation, 'partner_owner_recid':diction['partner_owner_recid']})
+
+ if (is_session_exist <= 0):
+ if (client_mail not in list_code_session_ko):
+ list_code_session_ko.append(str(session_formation))
+
+ elif (is_session_exist > 1):
+ print(" Le code session : " + str(session_formation) + " == ", is_session_exist)
+
+ else:
+ list_code_session_kooo.append(str(session_formation))
+
+
+
+ print(" NB client KO = ", len(list_client_ko))
+ print(" List client KO = ", list_client_ko)
+
+ print(" NB code session KO = ", len(list_code_session_ko))
+ print(" List code session KO = ", list_code_session_ko)
+ tab_facture_traite = []
+
+ for n in x:
+ client_mail = str(df['email_client'].values[n]).strip()
+ session_formation = str(df['code_session'].values[n]).strip()
+ num_facture = str(df['num_facture'].values[n]).strip()
+
+
+ if(client_mail in list_client_kooo and session_formation in list_code_session_kooo ):
+ node_facture_traiter = {}
+ node_facture_traiter['num_facture'] = str(num_facture)
+ node_facture_traiter['session_formation'] = str(session_formation)
+ node_facture_traiter['client_mail'] = str(client_mail)
+ tab_facture_traite.append(node_facture_traiter)
+
+ print(" ### tab_facture_traite = ", str(tab_facture_traite))
+ print(" ### TOTAL NB FACTURE = ", str(len(tab_facture_traite)))
+
+
+ cpt_facture_imported = 0
+ for n in x:
+ client_mail = str(df['email_client'].values[n]).strip()
+ session_formation = str(df['code_session'].values[n]).strip()
+
+ if(client_mail in list_client_kooo and session_formation in list_code_session_kooo ):
+
+ date_echeance = str(df['date_echeance'].values[n]).strip()
+ date_emission = str(df['date_emission'].values[n]).strip()
+ montant_ht = str(df['montant_ht'].values[n]).strip()
+ montant_ttc = str(df['montant_ttc'].values[n]).strip()
+ num_facture = str(df['num_facture'].values[n]).strip()
+ code_session = str(df['code_session'].values[n]).strip()
+
+ tax_amount = str(df['tax_amount'].values[n]).strip()
+ tax_taux = str(df['tax_taux'].values[n]).strip()
+ annotation = str(df['annotation'].values[n]).strip()
+ facture_initiale = str(df['facture_initiale'].values[n]).strip()
+ type = str(df['type'].values[n]).strip()
+
+
+
+ client_data = MYSY_GV.dbname['partner_client'].find_one({"email": client_mail})
+ session_data = MYSY_GV.dbname['session_formation'].find_one({"code_session": session_formation})
+
+ class_data = MYSY_GV.dbname['myclass'].find_one({"partner_owner_recid":diction['partner_owner_recid'],
+ '_id':ObjectId(str(session_data['class_id']))})
+
+
+ if( client_data and session_data and class_data ):
+
+ ## Creer les factures de reprise
+ partner_invoice_header_data = {}
+
+ list_partner_invoice_header_champ = ['order_header_client_id', 'order_header_ref_interne',
+ 'order_header_email_client', 'order_header_origin',
+ 'order_header_ref_client', 'order_header_vendeur_id',
+ 'order_header_date_cmd', 'order_header_date_expiration',
+ 'order_header_adr_fact_adresse', 'order_header_adr_fact_code_postal',
+ 'order_header_adr_fact_ville', 'order_header_adr_fact_pays',
+ 'order_header_adr_liv_adresse', 'order_header_adr_liv_code_postal',
+ 'order_header_adr_liv_ville', 'order_header_adr_liv_pays', 'valide',
+ 'locked', 'date_update',
+ 'order_header_montant_reduction', 'order_header_tax',
+ 'order_header_tax_amount',
+ 'total_header_hors_taxe_after_header_reduction',
+ 'total_header_hors_taxe_before_header_reduction',
+ 'total_header_toutes_taxes',
+ 'total_lines_hors_taxe_after_lines_reduction',
+ 'total_lines_hors_taxe_before_lines_reduction',
+ 'total_lines_montant_reduction', 'invoice_header_ref_interne',
+ 'invoice_header_type', 'invoice_date', 'update_by']
+
+ # PreRemplir les champs
+ for val in list_partner_invoice_header_champ:
+ partner_invoice_header_data[str(val)] = ""
+
+
+ partner_invoice_header_data['order_header_client_id'] = str(client_data['_id'])
+ partner_invoice_header_data['invoice_date_echeance'] = str(date_echeance)
+ partner_invoice_header_data['order_header_condition_paiement_code'] = ""
+ partner_invoice_header_data['order_header_condition_paiement_description'] = ""
+
+ partner_invoice_header_data['order_header_ref_interne'] = str(code_session)
+ partner_invoice_header_data['order_header_email_client'] = str(client_mail)
+ partner_invoice_header_data['order_header_origin'] = "REPRISE"
+ partner_invoice_header_data['order_header_adr_fact_adresse'] = str(client_data['invoice_adresse'])
+ partner_invoice_header_data['order_header_adr_fact_ville'] = str(client_data['invoice_ville'])
+ partner_invoice_header_data['order_header_adr_fact_code_postal'] = str(client_data['invoice_code_postal'])
+ partner_invoice_header_data['order_header_adr_fact_pays'] = str(client_data['invoice_pays'])
+ order_header_montant_reduction = "0"
+ partner_invoice_header_data['order_header_montant_reduction'] = "0"
+ partner_invoice_header_data['total_header_hors_taxe_before_header_reduction'] = str(montant_ht)
+ partner_invoice_header_data['order_header_tax'] = str(tax_taux)
+ partner_invoice_header_data['order_header_tax_amount'] = str(tax_amount)
+ partner_invoice_header_data['total_header_toutes_taxes'] = str(montant_ttc)
+ partner_invoice_header_data['invoice_header_type'] = str(type)
+ partner_invoice_header_data['invoice_header_ref_interne'] = str(num_facture)
+ partner_invoice_header_data['credit_note_ref'] = ""
+ partner_invoice_header_data['invoice_date'] = str(date_emission)
+ partner_invoice_header_data['update_by'] = "SYSTEM"
+ partner_invoice_header_data['annotation'] = str(annotation)
+ partner_invoice_header_data['invoice_header_origin'] = str(facture_initiale)
+ partner_invoice_header_data['valide'] = "1"
+ partner_invoice_header_data['locked'] = "0"
+ partner_invoice_header_data['partner_owner_recid'] = str(diction['partner_owner_recid'])
+ partner_invoice_header_data['date_update'] = str(datetime.now())
+
+ print(" #### partner_invoice_header_data = ", partner_invoice_header_data)
+ inserted_invoice_id = MYSY_GV.dbname['partner_invoice_header'].insert_one(partner_invoice_header_data).inserted_id
+ if (not inserted_invoice_id):
+ mycommon.myprint(" Facture : Impossible de créer l'entête de la facture ")
+ return False, " Facture : Impossible de créer l'entête de la facture "
+
+ partner_invoice_line_data = {}
+ list_partner_invoice_line_champ = ['order_line_formation', 'order_line_qty', 'order_line_prix_unitaire',
+ 'order_line_tax', 'order_line_tax_amount',
+ 'order_line_montant_toutes_taxes',
+ 'order_line_montant_hors_taxes', 'order_line_type_reduction',
+ 'order_line_type_valeur', 'order_line_montant_reduction',
+ 'order_header_ref_interne',
+ 'order_line_comment', 'order_header_id', 'valide', 'locked',
+ 'date_update', 'partner_owner_recid', 'invoice_header_ref_interne',
+ 'invoice_line_type',
+ 'invoice_date', 'invoice_header_id', 'order_line_class_id']
+
+ # PreRemplir les champs
+ for val in list_partner_invoice_line_champ:
+ partner_invoice_line_data[str(val)] = ""
+
+ partner_invoice_line_data['order_line_formation'] = class_data['internal_url']
+ partner_invoice_line_data['order_line_class_id'] = str(class_data['_id'])
+
+ partner_invoice_line_data['order_line_qty'] = str("1")
+ partner_invoice_line_data['order_line_prix_unitaire'] = str(montant_ht)
+ partner_invoice_line_data['order_line_montant_hors_taxes'] = str(montant_ht)
+ partner_invoice_line_data['order_line_comment'] = "REPRISE"
+ partner_invoice_line_data['invoice_header_id'] = str(inserted_invoice_id)
+ partner_invoice_line_data['invoice_line_type'] = "facture"
+ partner_invoice_line_data['invoice_header_ref_interne'] = partner_invoice_header_data['invoice_header_ref_interne']
+ partner_invoice_line_data['update_by'] = ""
+ partner_invoice_line_data['valide'] = "1"
+ partner_invoice_line_data['locked'] = "0"
+ partner_invoice_line_data['partner_owner_recid'] = str(diction['partner_owner_recid'])
+
+ print(" #### partner_invoice_line_data = ", partner_invoice_line_data)
+ inserted_invoice_id = MYSY_GV.dbname['partner_invoice_line'].insert_one(
+ partner_invoice_line_data).inserted_id
+ if (not inserted_invoice_id):
+ mycommon.myprint(" Facture : Impossible de créer les lignes de la facture " + str(
+ partner_invoice_header_data['invoice_header_ref_interne']))
+ return False, " Facture : Impossible de créer les lignes de la facture " + str(
+ partner_invoice_header_data['invoice_header_ref_interne']), False
+
+
+ cpt_facture_imported = cpt_facture_imported + 1
+
+ print(" ### TOTAL NB FACTURE IMPORTEDDDD = ", str(cpt_facture_imported))
+
+ return True, "reprise factures ok"
+
+ except Exception as e:
+ exc_type, exc_obj, exc_tb = sys.exc_info()
+ print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
+ return False, " Impossible de faire la reprise de factures JMJ"
+
diff --git a/wrapper.py b/wrapper.py
index 26c735d..ac483bd 100644
--- a/wrapper.py
+++ b/wrapper.py
@@ -298,7 +298,7 @@ def get_all_class(diction):
tab_selected_business_prices = []
if ("business_prices" in x.keys()):
- print(" ### x['business_prices'] == ",x['business_prices'])
+ #print(" ### x['business_prices'] == ",x['business_prices'])
for local_business_prices in x['business_prices']: