From b53cc9d62243d963324aa7d7ee20f3a45a2be5fc Mon Sep 17 00:00:00 2001 From: Cherif Date: Sun, 10 Aug 2025 19:12:55 +0200 Subject: [PATCH] 10/08/2025 - 10h Signed-off-by: Cherif --- E_Sign_Document.py | 27 ++- GlobalVariable.py | 19 ++ Session_Formation_Sequence.py | 346 ++++++++++++++++++++++++++++++++-- crm_opportunite.py | 18 +- email_inscription_mgt.py | 184 +++++++++++++++--- email_mgt.py | 129 ++++++++++++- main.py | 44 +++++ partner_client.py | 15 +- partner_invoice.py | 42 ++++- partner_order.py | 109 ++++++++++- survey_mgt.py | 42 ++++- 11 files changed, 899 insertions(+), 76 deletions(-) diff --git a/E_Sign_Document.py b/E_Sign_Document.py index e3a0a62..e5ee7c4 100644 --- a/E_Sign_Document.py +++ b/E_Sign_Document.py @@ -591,6 +591,9 @@ def Get_Given_E_Document_Not_Signed_No_Token(diction): convention_dictionnary_data = local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data["secret_key_signature"] = str(secret_key_for_sign) body = { @@ -616,7 +619,11 @@ def Get_Given_E_Document_Not_Signed_No_Token(diction): else: msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = " Signature electronique : Clé de signature" # msg['to'] = "billardman01@hotmail.com" @@ -1106,6 +1113,9 @@ def Create_E_Signature_For_E_Document(file_img=None, Folder=None, diction=None): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data = local_retval @@ -1191,7 +1201,11 @@ def Create_E_Signature_For_E_Document(file_img=None, Folder=None, diction=None): else: msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com' if (str(e_docment_type).strip() != ""): msg['Subject'] = " Votre Document " + str(e_docment_type) + " Signé " @@ -2124,6 +2138,9 @@ def Sent_E_Document_Signature_Request(diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data = local_retval convention_dictionnary_data["e_document_open_code"] = str(e_document_data['secret_key_open']) @@ -2161,7 +2178,11 @@ def Sent_E_Document_Signature_Request(diction): else: msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = " Demande signature électronique document" # msg['to'] = "billardman01@hotmail.com" diff --git a/GlobalVariable.py b/GlobalVariable.py index b5c0974..c5c895f 100644 --- a/GlobalVariable.py +++ b/GlobalVariable.py @@ -348,6 +348,8 @@ if (MYSY_ENV == "DEV"): + + """ Repertoire temporaire de telechargement ou de creation de fichier """ @@ -373,6 +375,8 @@ MAX_EU_PLANIF_BY_CSV = 200 Stripe : Nom des produits et prix et la clé de config """ if (MYSY_ENV == "PROD"): + """ 06/08/2025 : exceptionnement on va rediriger la prod vers le stripe de dev """ + """ STRIPE_GOLD_PRICE_ID = "price_1NG2HdAbmaEugrFTMbzVRwj1" STRIPE_GOLD_PRICE_ID_50_OFF = "price_1NG2HsAbmaEugrFTAiHh2SzD" STRIPE_GOLD_PRICE_ID_95_OFF = "price_1NG2IJAbmaEugrFTMPdMIzNH" @@ -386,6 +390,21 @@ if (MYSY_ENV == "PROD"): STRIPE_TEST_PRICE_ID = "price_1MT0f0AbmaEugrFTJjdZZXG7" STRIPE_CONFIG_KEY_PUB = "pk_live_51LUUfAAbmaEugrFTyfNe4Dj0vbxc5qXQqNs0rztjAKy8oSlc5EEQyJGjA8Z5kXmP2gvUMcYLUBYCIyWWzLCw59RY00PtGInkVf" STRIPE_CONFIG_API_KEY = "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" + """ + + STRIPE_GOLD_PRICE_ID = "price_1MT3FmAbmaEugrFTZ5vyJRcZ" + STRIPE_GOLD_PRICE_ID_50_OFF = "price_1NEpALAbmaEugrFTCDhlJyo3" + STRIPE_GOLD_PRICE_ID_95_OFF = "price_1NFyUEAbmaEugrFT5sRXixeZ" + STRIPE_GOLD_PRICE_ID_100_OFF = "price_1NEpeJAbmaEugrFTXT5OFciX" + + STRIPE_STANDARD_PRICE_ID = "price_1MT3FLAbmaEugrFTDgw7MVgb" + STRIPE_STANDARD_PRICE_ID_50_OFF = "price_1NEpCOAbmaEugrFTcBnOf89X" + STRIPE_STANDARD_PRICE_ID_95_OFF = "price_1NFySwAbmaEugrFTxrQHhFN9" + STRIPE_STANDARD_PRICE_ID_100_OFF = "price_1NEpbrAbmaEugrFTgLABbIOF" + + STRIPE_TEST_PRICE_ID = "price_1MT3FLAbmaEugrFTDgw7MVgb" + STRIPE_CONFIG_KEY_PUB = "pk_test_51LUUfAAbmaEugrFTI25uZBD3IFjbtaL6jUfRV83diDf7nco8worna4NGKhMHbPP71WCwT5EHFRdDNatxPrJWwgZ300kgH5EO4p" + STRIPE_CONFIG_API_KEY = "sk_test_51LUUfAAbmaEugrFTrWsfcBWZtbBh9r3HCa2sgeyikG808LjSk3bAdFhV6KxgRZ3vFxooa6RE0c5zBkTuOUrKkyjy00BrsIXAPs" elif (MYSY_ENV == "DEV"): STRIPE_GOLD_PRICE_ID = "price_1MT3FmAbmaEugrFTZ5vyJRcZ" diff --git a/Session_Formation_Sequence.py b/Session_Formation_Sequence.py index 5515670..467c65e 100644 --- a/Session_Formation_Sequence.py +++ b/Session_Formation_Sequence.py @@ -57,7 +57,7 @@ def Add_Session_Sequence(diction): """ field_list = ['token', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', 'agenda', 'objectif', 'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_id', - 'mode_animation'] + 'mode_animation', 'volume_theorique'] incom_keys = diction.keys() for val in incom_keys: @@ -108,7 +108,12 @@ def Add_Session_Sequence(diction): 'partner_owner_recid': str(my_partner['recid']), 'valide': '1'}) - + if ("volume_theorique" in diction.keys() and diction['volume_theorique']): + Isfloat_status, Isfloat_retval = mycommon.tryFloat(str(diction['volume_theorique'])) + if (Isfloat_status is False): + mycommon.myprint( + str(inspect.stack()[0][3]) + " Le volume horaire est incorrecte ") + return False, " Le volume horaire est incorrecte" # Verifier qu'il n'y a pas de chevauchement de date avec une autre sequence de la meme session. date_debut_seq = "" @@ -152,9 +157,9 @@ def Add_Session_Sequence(diction): Par defaut on fait des controle de chevauchement, sauf si on decide de la desactiver """"" - check_chevauchement = 1 - if( "check_chevauchement" in diction.keys() and diction['check_chevauchement'] == "0"): - check_chevauchement = 0 + check_chevauchement = 0 + if( "check_chevauchement" in diction.keys() and diction['check_chevauchement'] == "1"): + check_chevauchement = 1 local_grp_apprenant_id = "" @@ -210,6 +215,9 @@ def Add_Session_Sequence(diction): if ("type" in diction.keys()): sequence_type = str(diction['type']) + volume_theorique = "" + if ("volume_theorique" in diction.keys()): + volume_theorique = str(diction['volume_theorique']) sequence_title = "" if( "sequence_title" in diction.keys() ): @@ -301,6 +309,8 @@ def Add_Session_Sequence(diction): my_data['sequence_end'] = date_fin_seq my_data['time_in_hour'] = str(delta_time_converted_in_hour) + my_data['volume_theorique'] = volume_theorique + my_data['agenda'] = agenda my_data['objectif'] = objectif my_data['commentaire'] = commentaire @@ -369,7 +379,7 @@ def Add_Session_Sequence_Return_New_Seq_Data(diction): """ field_list = ['token', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', 'agenda', 'objectif', 'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_id', - 'mode_animation'] + 'mode_animation', 'volume_theorique'] incom_keys = diction.keys() for val in incom_keys: @@ -419,6 +429,14 @@ def Add_Session_Sequence_Return_New_Seq_Data(diction): 'partner_owner_recid': str(my_partner['recid']), 'valide': '1'}) + if ("volume_theorique" in diction.keys() and diction['volume_theorique']): + Isfloat_status, Isfloat_retval = mycommon.IsFloat(str(diction['volume_theorique'])) + if (Isfloat_status is False): + mycommon.myprint( + str(inspect.stack()[0][3]) + " Le volume horaire est incorrecte ") + return False, " Le volume horaire est incorrecte" + + # Verifier qu'il n'y a pas de chevauchement de date avec une autre sequence de la meme session. date_debut_seq = "" if ("sequence_start" in diction.keys()): @@ -461,9 +479,9 @@ def Add_Session_Sequence_Return_New_Seq_Data(diction): Par defaut on fait des controle de chevauchement, sauf si on decide de la desactiver """"" - check_chevauchement = 1 - if ("check_chevauchement" in diction.keys() and diction['check_chevauchement'] == "0"): - check_chevauchement = 0 + check_chevauchement = 0 + if ("check_chevauchement" in diction.keys() and diction['check_chevauchement'] == "1"): + check_chevauchement = 1 local_grp_apprenant_id = "" if ("grp_apprenant_id" in diction.keys()): @@ -528,6 +546,11 @@ def Add_Session_Sequence_Return_New_Seq_Data(diction): if ("agenda" in diction.keys()): agenda = str(diction['agenda']) + volume_theorique = "" + if ("volume_theorique" in diction.keys()): + volume_theorique = str(diction['volume_theorique']) + + objectif = "" if ("objectif" in diction.keys()): objectif = str(diction['objectif']) @@ -612,6 +635,7 @@ def Add_Session_Sequence_Return_New_Seq_Data(diction): my_data['sequence_end'] = date_fin_seq my_data['time_in_hour'] = str(delta_time_converted_in_hour) + my_data['volume_theorique'] = volume_theorique my_data['agenda'] = agenda my_data['objectif'] = objectif my_data['commentaire'] = commentaire @@ -1331,7 +1355,7 @@ def Update_Session_Sequence(diction): """ field_list = ['token', '_id', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', 'agenda', 'objectif', 'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_id', - 'mode_animation'] + 'mode_animation', 'volume_theorique'] incom_keys = diction.keys() for val in incom_keys: @@ -1391,13 +1415,21 @@ def Update_Session_Sequence(diction): # Verification de l'existence et de la session is_existe_valide_session_id = MYSY_GV.dbname["session_formation"].count_documents({'_id':ObjectId(str(diction['session_id'])), 'partner_owner_recid':str(my_partner['recid']), - 'valide':'1'}) + 'valide':'1'}) if( is_existe_valide_session_id <= 0): mycommon.myprint( str(inspect.stack()[0][3]) + " - L'identifiant de la session n'est pas valide ") return False, "L'identifiant de la session n'est pas valide " + + if( "volume_theorique" in diction.keys() and diction['volume_theorique']): + Isfloat_status, Isfloat_retval = mycommon.IsFloat(str(diction['volume_theorique'])) + if (Isfloat_status is False): + mycommon.myprint( + str(inspect.stack()[0][3]) + " Le volume horaire est incorrecte ") + return False, " Le volume horaire est incorrecte" + # Verifier qu'il n'y a pas de chevauchement de date avec une autre sequence de la meme session. date_debut_seq = "" if ("sequence_start" in diction.keys()): @@ -1441,11 +1473,11 @@ def Update_Session_Sequence(diction): Par defaut on fait des controle de chevauchement, sauf si on decide de la desactiver """"" - check_chevauchement = 1 - if( "check_chevauchement" in diction.keys() and diction['check_chevauchement'] == "0"): - check_chevauchement = 0 + check_chevauchement = 0 + if( "check_chevauchement" in diction.keys() and diction['check_chevauchement'] == "1"): + check_chevauchement = 1 - if( check_chevauchement == 1 and str(diction['type']) == "planning"): + if( check_chevauchement == 1 and "type" in diction.keys() and str(diction['type']) == "planning"): for retVal in MYSY_GV.dbname['session_formation_sequence'].find({'session_id': str(diction['session_id']), 'partner_owner_recid': str( my_partner['recid']), @@ -1491,6 +1523,9 @@ def Update_Session_Sequence(diction): update_data = {} + if ("volume_theorique" in diction.keys()): + update_data['volume_theorique'] = str(diction['volume_theorique']) + if ("type" in diction.keys()): update_data['type'] = str(diction['type']) @@ -1684,6 +1719,11 @@ def Get_Session_Sequence_List(diction): if ("type" not in user.keys()): user['type'] = "" + + if ("volume_theorique" not in user.keys()): + user['volume_theorique'] = "" + + if( "grp_apprenant_id" not in user.keys() ): user['grp_apprenant_id'] = "" @@ -1778,6 +1818,9 @@ def Get_Given_Session_Sequence(diction): user['id'] = str(val_tmp) val_tmp = val_tmp + 1 + if ("volume_theorique" not in user.keys()): + user['volume_theorique'] = "0" + if ("mode_animation" not in user.keys()): user['mode_animation'] = "0" @@ -3803,3 +3846,276 @@ def Create_Automatic_Sequence_From_Month_Model(diction): return False, " Impossible de dupliquer le mois " + +""" +Cette fonction permet de decaller les sequences d'une liste de session formation de X jour +important : +seront aussi decaler les reservations de ressources, sans controle de disponibilié + +""" +def Decale_Session_Sequence_X_days(diction): + try: + diction = mycommon.strip_dictionary(diction) + + """ + Verification des input acceptés + """ + field_list = ['token', 'tab_session_ids', 'nb_jour_decalage'] + + incom_keys = diction.keys() + for val in incom_keys: + if val not in field_list and val.startswith('my_') is False: + mycommon.myprint(str( + inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé") + return False, " Les informations fournies sont incorrectes" + + """ + Verification des champs obligatoires + """ + field_list_obligatoire = ['token', 'tab_session_ids', 'nb_jour_decalage'] + + for val in field_list_obligatoire: + if val not in diction: + mycommon.myprint( + str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ") + return False, " Les informations fournies sont incorrectes" + + """ + Verification de l'identité et autorisation de l'entité qui + appelle cette API + """ + token = "" + if ("token" in diction.keys()): + if diction['token']: + token = diction['token'] + + + + local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction) + if (local_status is not True): + return local_status, my_partner + + nb_jour_decalage = str(diction['nb_jour_decalage']).strip() + local_status, local_val = mycommon.IsInt(nb_jour_decalage) + + if (local_status is False): + mycommon.myprint(" Le nombre de jour de décalage "+str(nb_jour_decalage)+ " est invalide ") + return False, " Le nombre de jour de décalage "+str(nb_jour_decalage)+ " est invalide " + + nb_jour_decalage_integer = local_val + + tab_session_ids = [] + tab_session_ids_ObjectId = [] + tab_session_ids_split = str(diction['tab_session_ids']).split(",") + for tmp in tab_session_ids_split: + if( tmp ): + tab_session_ids.append(tmp) + tab_session_ids_ObjectId.append(ObjectId(tmp)) + + """ + Verifier la valididé de la session + """ + is_session_valide_count = MYSY_GV.dbname['session_formation'].count_documents( + {'_id': ObjectId(str(tmp)), + 'valide': '1', + 'partner_owner_recid': str(my_partner['recid'])}) + + if (is_session_valide_count != 1): + mycommon.myprint( + str(inspect.stack()[0][ + 3]) + " L'identifiant de la session "+str(tmp) +" est invalide ") + return False, " L'identifiant de la session "+str(tmp) +" est invalide " + + + + """ + Aller chercher le modele de journée pour gerer les jours off + """ + jounree_modele_id = "" + jounree_modele_data = MYSY_GV.dbname['base_config_modele_journee'].find_one( + {'partner_owner_recid': str(my_partner['recid']), + 'valide': '1', 'locked': '0'}) + + if (jounree_modele_data is None): + # On ne trouve pas de modele par defaut pour ce client. On va aller le chercher le modele par defaut de MySy + + jounree_modele_data = MYSY_GV.dbname['base_config_modele_journee'].find_one( + {'partner_owner_recid': "default", 'valide': '1', 'locked': '0'}) + + if (jounree_modele_data is None): + mycommon.myprint( + str(inspect.stack()[0][3]) + " - Aucun modèle de journée n'est configuré dans le système ") + return False, " Aucun modèle de journée n'est configuré dans le système " + + jounree_modele_id = str(jounree_modele_data['_id']) + + + else: + jounree_modele_id = str(jounree_modele_data['_id']) + + + + nb_sequence = 0 + for local_session_id in tab_session_ids : + + # Aller chercher les sequences de la session à decaller + for local_sequence in MYSY_GV.dbname['session_formation_sequence'].find({'session_id':str(local_session_id), + 'valide': '1', + 'locked':'0', + 'partner_owner_recid': str(my_partner['recid']) + }).sort([("_id", pymongo.ASCENDING), ]): + + current_start = datetime.strptime(str(local_sequence['sequence_start'])[0:16], '%d/%m/%Y %H:%M') + current_end = datetime.strptime(str(local_sequence['sequence_end'])[0:16], '%d/%m/%Y %H:%M') + + nb_jour_decalage_done = 0 + nb_jour_decalage_integer = local_val + + if( nb_jour_decalage_integer > 0 ): + while( nb_jour_decalage_done <= nb_jour_decalage_integer): + new_current_start = current_start + timedelta(days=nb_jour_decalage_done) + new_current_end = current_end + timedelta(days=nb_jour_decalage_done) + + + date_jour = str(new_current_start.strftime("%Y-%m-%d")) + jour_name = new_current_start.strftime("%A") + + # Recuperation des sequences associées à jour_name + is_jour_name_off = jounree_modele_data[jour_name]["is_off_day"] + + if (date_jour not in jounree_modele_data['date_off'] and is_jour_name_off != "1"): + nb_jour_decalage_done = nb_jour_decalage_done + 1 + else: + #print(" ### "+str(date_jour)+ " -- "+str(jour_name)+" EST UN JOUR OFF, NO INCREMENT ") + nb_jour_decalage_integer = nb_jour_decalage_integer + 1 + nb_jour_decalage_done = nb_jour_decalage_done + 1 + + #print(" ### nb_jour_decalage_integer passe de "+str(nb_jour_decalage_integer-1)+" à "+str(nb_jour_decalage_integer)) + + print(" ### "+str(current_start)+ " ==( "+str(nb_jour_decalage_integer)+"J )=== >> "+str(new_current_start)) + new_data = {} + new_data['sequence_start'] = str(new_current_start.strftime("%d/%m/%Y %H:%M")) + new_data['sequence_end'] = str(new_current_end.strftime("%d/%m/%Y %H:%M")) + new_data['date_update'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S") + new_data['update_by'] = str(my_partner['recid']) + + #print(" ### new_data = ", new_data) + + MYSY_GV.dbname['session_formation_sequence'].find_one_and_update( + {'_id': ObjectId(str(local_sequence['_id'])), + 'partner_owner_recid': str(my_partner['recid'])}, + {'$set': new_data}) + + """ + Après la mise à jour de la sequence, + il faut mettre à jour le planning des ressources associée + """ + for local_sequence_ressource_affectation in MYSY_GV.dbname[ + 'session_formation_sequence_affectation'].find({ + 'sequence_session_id': str(local_sequence['_id']), + 'valide': '1', + 'locked': '0', + 'partner_owner_recid': str(my_partner['recid']) + }): + # Aller cherche l'agenda de la ressource + for local_ressource_agenda in MYSY_GV.dbname['agenda'].find({ + 'session_formation_sequence_affectation_id': str( + local_sequence_ressource_affectation[ + '_id']), + 'valide': '1', + 'locked': '0', + 'partner_owner_recid': str( + my_partner['recid']) + }): + new_data_agenda = {} + new_data_agenda['event_start'] = str(new_current_start.strftime("%Y-%m-%dT%H:%M")) + new_data_agenda['event_end'] = str(new_current_end.strftime("%Y-%m-%dT%H:%M")) + new_data_agenda['date_update'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S") + new_data_agenda['update_by'] = str(my_partner['recid']) + + print(" ### new_data_agenda = ", new_data_agenda) + print(" ### QRY = ", {'_id': ObjectId(str(local_ressource_agenda['_id'])), + 'partner_owner_recid': str(my_partner['recid'])}) + + MYSY_GV.dbname['agenda'].find_one_and_update( + {'_id': ObjectId(str(local_ressource_agenda['_id'])), + 'partner_owner_recid': str(my_partner['recid'])}, + {'$set': new_data_agenda}) + + + + elif (nb_jour_decalage_integer < 0): + while (nb_jour_decalage_done >= nb_jour_decalage_integer): + new_current_start = current_start + timedelta(days=nb_jour_decalage_done) + new_current_end = current_end + timedelta(days=nb_jour_decalage_done) + + #print(" ### new_current_start = ", new_current_start) + + date_jour = str(new_current_start.strftime("%Y-%m-%d")) + jour_name = new_current_start.strftime("%A") + + # Recuperation des sequences associées à jour_name + is_jour_name_off = jounree_modele_data[jour_name]["is_off_day"] + + if (date_jour not in jounree_modele_data['date_off'] and is_jour_name_off != "1"): + nb_jour_decalage_done = nb_jour_decalage_done - 1 + else: + print(" ### "+str(date_jour)+ " -- "+str(jour_name)+" EST UN JOUR OFF, NO INCREMENT ") + nb_jour_decalage_integer = nb_jour_decalage_integer - 1 + nb_jour_decalage_done = nb_jour_decalage_done - 1 + + #print(" ### nb_jour_decalage_integer passe de "+str(nb_jour_decalage_integer+1)+" à "+str(nb_jour_decalage_integer)) + + print(" ### " + str(current_start) + " ==( " + str(nb_jour_decalage_integer) + "J )=== >> " + str(new_current_start)) + new_data = {} + new_data['sequence_start'] = str(new_current_start.strftime("%d/%m/%Y %H:%M")) + new_data['sequence_end'] = str(new_current_end.strftime("%d/%m/%Y %H:%M")) + new_data['date_update'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S") + new_data['update_by'] = str(my_partner['recid']) + + print(" ### new_data = ", new_data) + + MYSY_GV.dbname['session_formation_sequence'].find_one_and_update( + {'_id': ObjectId(str(local_sequence['_id'])), + 'partner_owner_recid': str(my_partner['recid'])}, + {'$set': new_data}) + + """ + Après la mise à jour de la sequence, + il faut mettre à jour le planning des ressources associée + """ + for local_sequence_ressource_affectation in MYSY_GV.dbname['session_formation_sequence_affectation'].find({ + 'sequence_session_id': str(local_sequence['_id']), + 'valide': '1', + 'locked': '0', + 'partner_owner_recid': str(my_partner['recid']) + }): + # Aller cherche l'agenda de la ressource + for local_ressource_agenda in MYSY_GV.dbname['agenda'].find({'session_formation_sequence_affectation_id':str(local_sequence_ressource_affectation['_id']), + 'valide': '1', + 'locked': '0', + 'partner_owner_recid': str( + my_partner['recid']) + }): + new_data_agenda = {} + new_data_agenda['event_start'] = str(new_current_start.strftime("%Y-%m-%dT%H:%M")) + new_data_agenda['event_end'] = str(new_current_end.strftime("%Y-%m-%dT%H:%M")) + new_data_agenda['date_update'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S") + new_data_agenda['update_by'] = str(my_partner['recid']) + + print(" ### new_data_agenda = ", new_data_agenda) + print(" ### QRY = ", {'_id': ObjectId(str(local_ressource_agenda['_id'])), + 'partner_owner_recid': str(my_partner['recid'])}) + + MYSY_GV.dbname['agenda'].find_one_and_update( + {'_id': ObjectId(str(local_ressource_agenda['_id'])), + 'partner_owner_recid': str(my_partner['recid'])}, + {'$set': new_data_agenda}) + + + return True, str(nb_sequence)+" mise(s) à jour" + + except Exception as e: + exc_type, exc_obj, exc_tb = sys.exc_info() + mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno)) + return False, " Impossible dedécaler les séquences " \ No newline at end of file diff --git a/crm_opportunite.py b/crm_opportunite.py index 49daaf3..9cfdfe9 100644 --- a/crm_opportunite.py +++ b/crm_opportunite.py @@ -217,6 +217,9 @@ def Add_CRM_Opportunite(diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + new_status_id_data = MYSY_GV.dbname['base_partner_opportunite_step'].find_one( {'_id': ObjectId(str(diction['statut_id'])), 'valide': '1', @@ -295,7 +298,11 @@ def Add_CRM_Opportunite(diction): else: msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = sujetHtml @@ -510,6 +517,9 @@ def Update_CRM_Opportunite(diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + new_status_id_data = MYSY_GV.dbname['base_partner_opportunite_step'].find_one({'_id':ObjectId(str(new_status_id)), 'valide':'1', 'locked':'0', @@ -592,7 +602,11 @@ def Update_CRM_Opportunite(diction): else: msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = sujetHtml diff --git a/email_inscription_mgt.py b/email_inscription_mgt.py index 99612d7..48ce9d2 100644 --- a/email_inscription_mgt.py +++ b/email_inscription_mgt.py @@ -59,7 +59,7 @@ def incription_training_confirmation_mail(diction): if val not in diction: mycommon.myprint( str(inspect.stack()[0][3]) + " - : La valeur '" + val + "' n'est pas presente dans la liste des arguments ") - return False, "Impossible d'envoyer l'email de confirmation de l'inscritpion" + return False, "Impossible d'envoyer l'email de confirmation de l'inscription" @@ -285,7 +285,20 @@ def incription_training_confirmation_mail(diction): val = smtpserver.send_message(msg) smtpserver.close() else: - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_owner_recid']), 'is_partner_admin_account': '1', 'active': '1', + 'locked': '0'}, + {'_id': 1, 'nom': 1}) + + if (my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = '[MySy Training]: Confirmation inscription formation' msg['To'] = str(diction['email']) @@ -467,6 +480,9 @@ def incription_training_refused_mail(diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + dictionnary_data = local_retval dictionnary_data['refus_data'] = refus_data @@ -549,7 +565,12 @@ def incription_training_refused_mail(diction): else: smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User msg['Bcc'] = 'contact@mysy-training.com,' + str(diction['email']) msg['Subject'] = sujetHtml msg['To'] = str(diction['email']) @@ -753,9 +774,6 @@ def incription_training_cancelled_mail(diction): adresse_session = my_adress - - - # JINJA2 templateLoader = jinja2.FileSystemLoader(searchpath="./") templateEnv = jinja2.Environment(loader=templateLoader) @@ -875,7 +893,6 @@ def incription_training_cancelled_mail(diction): - if (str(partner_own_smtp_value) == "1"): smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port) msg = EmailMessage() @@ -896,7 +913,20 @@ def incription_training_cancelled_mail(diction): msg = EmailMessage() msg.set_content(sourceHtml, subtype='html') - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_owner_recid']), 'is_partner_admin_account': '1', 'active': '1', + 'locked': '0'}, + {'_id': 1, 'nom': 1}) + + if (my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = '[MySy Training]: Inscription formation annulée' msg['To'] = str(diction['email']) @@ -927,9 +957,10 @@ def Pre_incription_training_confirmation_mail(diction): print(" ### Preincription_training_confirmation_mail = "+str(diction)) """ - Verification de la liste des champs obligatoires + Verification de la liste des champs obligatoires """ - field_list_obligatoire = ['nom', 'prenom', 'email', 'date_du', 'code_session', 'date_au', 'title', 'distantiel', 'presentiel', 'partner_owner_recid'] + field_list_obligatoire = ['nom', 'prenom', 'email', 'date_du', 'code_session', 'date_au', 'title', + 'distantiel', 'presentiel', 'partner_owner_recid', 'token'] for val in field_list_obligatoire: if val not in diction: mycommon.myprint( @@ -1096,8 +1127,21 @@ def Pre_incription_training_confirmation_mail(diction): else: + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_owner_recid']), 'is_partner_admin_account': '1', 'active': '1', 'locked': '0'}, + {'_id':1, 'nom':1}) + + if( my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] + smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = '[MySy Training] : pre-inscription formation' msg['To'] = str(diction['email']) @@ -1129,7 +1173,7 @@ def Notification_partner_Pre_incription_mail(diction): Verification de la liste des champs obligatoires """ field_list_obligatoire = ['nom', 'prenom', 'email', 'date_du', 'date_au', 'title', - 'partner_mail', 'telephone'] + 'partner_mail', 'telephone', 'token', 'partner_owner_recid'] for val in field_list_obligatoire: if val not in diction: mycommon.myprint( @@ -1168,11 +1212,23 @@ def Notification_partner_Pre_incription_mail(diction): print("debut envoi mail de test ") # on rentre les renseignements pris sur le site du fournisseur + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_owner_recid']), 'is_partner_admin_account': '1', 'active': '1', + 'locked': '0'}, + {'_id': 1, 'nom': 1}) + + if (my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] + msg = MIMEMultipart("alternative") msg['Subject'] = 'MySy Training : pre-inscription formation' - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['To'] = str(diction['email']) @@ -1271,7 +1327,11 @@ def Notification_partner_Pre_incription_mail(diction): msg = EmailMessage() smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) msg.set_content(sourceHtml, subtype='html') - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User msg['Cc'] = 'contact@mysy-training.com, billardman01@hotmail.com' msg['Subject'] = '[MySy Training] : pre-inscription à la formation '+str(diction['title']) msg['To'] = str(diction['partner_mail']) @@ -1369,7 +1429,7 @@ def Evaluation_training_confirmation_mail(diction): """ partner_own_smtp_value = "0" partner_own_smtp = MYSY_GV.dbname['base_partner_setup'].find_one( - {'partner_owner_recid': str(diction['partner_owner_recid']), + {'partner_owner_recid': str(my_partner['recid']), 'config_name': 'partner_smtp', 'valide': '1', 'locked': '0'}) @@ -1379,31 +1439,31 @@ def Evaluation_training_confirmation_mail(diction): if (str(partner_own_smtp_value) == "1"): partner_SMTP_COUNT_password = str(MYSY_GV.dbname['base_partner_setup'].find_one( - {'partner_owner_recid': str(diction['partner_owner_recid']), + {'partner_owner_recid': str(my_partner['recid']), 'config_name': 'smtp_user_pwd', 'valide': '1', 'locked': '0'}, {'config_value': 1})['config_value']) partner_SMTP_COUNT_smtpsrv = str(MYSY_GV.dbname['base_partner_setup'].find_one( - {'partner_owner_recid': str(diction['partner_owner_recid']), + {'partner_owner_recid': str(my_partner['recid']), 'config_name': 'smtp_server', 'valide': '1', 'locked': '0'}, {'config_value': 1})['config_value']) partner_SMTP_COUNT_user = str(MYSY_GV.dbname['base_partner_setup'].find_one( - {'partner_owner_recid': str(diction['partner_owner_recid']), + {'partner_owner_recid': str(my_partner['recid']), 'config_name': 'smtp_user', 'valide': '1', 'locked': '0'}, {'config_value': 1})['config_value']) partner_SMTP_COUNT_From_User = str(MYSY_GV.dbname['base_partner_setup'].find_one( - {'partner_owner_recid': str(diction['partner_owner_recid']), + {'partner_owner_recid': str(my_partner['recid']), 'config_name': 'smtp_count_from_name', 'valide': '1', 'locked': '0'}, {'config_value': 1})['config_value']) partner_SMTP_COUNT_port = str(MYSY_GV.dbname['base_partner_setup'].find_one( - {'partner_owner_recid': str(diction['partner_owner_recid']), + {'partner_owner_recid': str(my_partner['recid']), 'config_name': 'smtp_count_port', 'valide': '1', 'locked': '0'}, {'config_value': 1})['config_value']) @@ -1428,7 +1488,20 @@ def Evaluation_training_confirmation_mail(diction): msg = EmailMessage() smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) msg.set_content(sourceHtml, subtype='html') - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_owner_recid']), 'is_partner_admin_account': '1', 'active': '1', + 'locked': '0'}, + {'_id': 1, 'nom': 1}) + + if (my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = 'MySy Training : Evaluation formation : '+str(diction['title']) msg['To'] = str(diction['email']) @@ -1741,7 +1814,20 @@ def SendAttestion_to_attendee_by_email(diction): smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) msg.attach(html_mime) msg.attach(part) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_recid']), 'is_partner_admin_account': '1', 'active': '1', + 'locked': '0'}, + {'_id': 1, 'nom': 1}) + + if (my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = 'MySy Training : Votre attestation de formation : ' + str(diction['class_title']) msg['To'] = str(diction['email_participant']) @@ -1975,7 +2061,19 @@ def SendAttestion_to_attendee_by_email_standalone(diction): smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) msg.attach(part) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_recid']), 'is_partner_admin_account': '1', 'active': '1', + 'locked': '0'}, + {'_id': 1, 'nom': 1}) + + if (my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com, mysytraining@gmail.com' msg['Subject'] = 'MySy Training : Votre attestation de formation : ' + str(diction['title']) msg['To'] = str(diction['email']) @@ -2159,6 +2257,9 @@ def LMS_Credential_Sending_mail(diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + dictionnary_data = local_retval dictionnary_data['credential_data'] = diction @@ -2238,7 +2339,13 @@ def LMS_Credential_Sending_mail(diction): else: smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com,'+str(str(diction['course_owner_email'])) msg['Subject'] = sujetHtml msg['To'] = str(diction['email']) @@ -2431,7 +2538,19 @@ def Employee_Credential_Sending_mail(diction): smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) msg = EmailMessage() msg.set_content(sourceHtml, subtype='html') - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_owner_recid']), 'is_partner_admin_account': '1', 'active': '1', + 'locked': '0'}, + {'_id': 1, 'nom': 1}) + + if (my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) #msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = '[MySy Training]: Vos identifiants de connexion' msg['To'] = str(diction['email']) @@ -2605,7 +2724,20 @@ def Employee_Acces_LMS_Sending_mail(diction): smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) msg = EmailMessage() msg.set_content(sourceHtml, subtype='html') - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_owner_recid']), 'is_partner_admin_account': '1', 'active': '1', + 'locked': '0'}, + {'_id': 1, 'nom': 1}) + + if (my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] + + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + #msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = partner_document_EMPLOYEE_CREDENTIALS_data['sujet'] msg['To'] = str(diction['email']) diff --git a/email_mgt.py b/email_mgt.py index d533e6c..10703e1 100644 --- a/email_mgt.py +++ b/email_mgt.py @@ -1580,6 +1580,9 @@ def EmailDemandeInfoClass( diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data = local_retval new_node = {"nom": str(diction['nom']), @@ -1661,7 +1664,12 @@ def EmailDemandeInfoClass( diction): msg = MIMEMultipart("alternative") msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = sujetHtml @@ -1740,6 +1748,9 @@ def EmailDemandeInfoClass_For_Cpny_With_Quotation_Option( diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data = local_retval new_node = {"raison_sociale": str(diction['raison_sociale']), @@ -1823,7 +1834,12 @@ def EmailDemandeInfoClass_For_Cpny_With_Quotation_Option( diction): msg = MIMEMultipart("alternative") msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = sujetHtml @@ -2440,6 +2456,115 @@ def ManualSendInvoiceEmailRIB_PortCities(diction): +""" +Creation manuelle d'une facture avec RIB CIC pour JMJ_Formation - perso +""" +def ManualSendInvoiceEmailRIB_CIC_JMJFormation(diction): + try: + ''' + Verification des données obligatoires + ''' + ''' + Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente, + On controle que les champs obligatoires sont presents dans la liste + ''' + + tomorrow = datetime.date.today() + datetime.timedelta(days=1) + tomorrow_day = tomorrow.strftime("%A") + + print("debut envoi mail de test ") + # on rentre les renseignements pris sur le site du fournisseur + + #smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) + + # msg = MIMEMultipart("alternative") + #msg = EmailMessage() + + # JINJA2 + templateLoader = jinja2.FileSystemLoader(searchpath="./") + templateEnv = jinja2.Environment(loader=templateLoader) + TEMPLATE_FILE = "Template/MySy_Invoice_RIB_PortCities_Perso_tpl.html" + template = templateEnv.get_template(TEMPLATE_FILE) + body = { + "params": {"order_id": "MTT/2025_N°0012/JMJ FORMATION", + "date_order": ": 14/07/2025", + "periode":"14/07/2025 au 13/08/2025", + "total_ht": "130", + "tva": "11.05", + "total_ttc": "141,05 ", + "client_name": "JMJ FORMATION", + "client_address": "388 Chemin Long Pré", + "client_zip_ville": "97232 Le Lamentin", + "client_pays": "Martinique", + "packs": "ELYOS - Pack BASIQUE ", + "detail_packs": "Mise en place d’un site web (marketplace) - " + "Mise en place d’un outil de gestion administrative et de gestion de la relation client pour Organisme de formation ", + "qty": "1", + "unit_price": "130 €", + "montant": "130 €", + + + "invoice_id": "FACT_20250715", + "invoice_date": "14/07/2025", + "due_date": "14/07/2025", + "orign_order": "Contrat MTT/2025_N°0012/JMJ FORMATION", + } + } + + #print(" ### body 1 = ", body) + sourceHtml = template.render(params=body["params"]) + + """msg.set_content(sourceHtml, subtype='html') + msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + msg['Bcc'] = 'contact@mysy-training.com' + msg['Subject'] = "[MySy Training Technology] : Votre facture N° FACT_230500030" + msg['To'] = 'billardman1@gmail.com' + + smtpserver.ehlo() + smtpserver.starttls() + smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password) + val = smtpserver.send_message(msg) + smtpserver.close() + """ + #print(" Email envoyé " + str(val)) + + ### CREATION DE LA FACTION PDF + templateLoader = jinja2.FileSystemLoader(searchpath="./") + templateEnv = jinja2.Environment(loader=templateLoader) + #TEMPLATE_FILE = "Template/MySy_Invoice_RIB_tpl.html" + TEMPLATE_FILE = "Template/invoice_RIB_PortCities_perso_tpl.html" + + template = templateEnv.get_template(TEMPLATE_FILE) + # This data can come from database query + + #print(" ### body 22 = ", body) + + sourceHtml = template.render(json_data=body["params"]) + orig_file_name = "invoice_FACT_20250715.pdf" + outputFilename = str(MYSY_GV.INVOICE_DIRECTORY) + str(orig_file_name) + + # open output file for writing (truncated binary) + resultFile = open(outputFilename, "w+b") + + # convert HTML to PDF + pisaStatus = pisa.CreatePDF( + src=sourceHtml, # the HTML to convert + dest=resultFile) # file handle to receive result + + # close output file + resultFile.close() + + return True, " facture envoyée" + + + 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 d'envoyer la facure" + + + + """ Cette fonction envoie un email pour notifier a un partenaire l'arrete d'un abonnement """ diff --git a/main.py b/main.py index 5df8401..4bbd8dd 100644 --- a/main.py +++ b/main.py @@ -3060,6 +3060,22 @@ def ManualSendInvoiceEmailRIB_PortCities(): + +""" +API Creation manuelle d'une facture avec RIB CIC pour JMJ_Formation - perso +""" +@app.route('/myclass/api/ManualSendInvoiceEmailRIB_CIC_JMJFormation/', methods=['POST','GET']) +@crossdomain(origin='*') +def ManualSendInvoiceEmailRIB_CIC_JMJFormation(): + # On recupere le corps (payload) de la requete + payload = mycommon.strip_dictionary (request.form.to_dict()) + print(" ### ManualSendInvoiceEmailRIB_CIC_JMJFormation : payload = ",str(payload)) + localStatus, message= emails.ManualSendInvoiceEmailRIB_CIC_JMJFormation(payload) + return jsonify(status=localStatus, message=message ) + + + + """ API de recuperation au formation CSV de la liste des inscrits à une formation avec les statuts (validé ou pas) @@ -10331,6 +10347,23 @@ def Create_Automatic_Sequence_From_Month_Model(): +""" +API pour decaller les sequences d'une liste de sessions de formation +""" +@app.route('/myclass/api/Decale_Session_Sequence_X_days/', methods=['POST','GET']) +@crossdomain(origin='*') +def Decale_Session_Sequence_X_days(): + # On recupere le corps (payload) de la requete + payload = mycommon.strip_dictionary (request.form.to_dict()) + print(" ### Decale_Session_Sequence_X_days payload = ",payload) + status, retval = Session_Formation_Sequence.Decale_Session_Sequence_X_days(payload) + return jsonify(status=status, message=retval) + + + + + + """ API Pour ajouter une categorie de formation """ @@ -13787,6 +13820,17 @@ def Get_List_Message_To_Mail_Queue(): return jsonify(status=status, message=retval) +""" +Test reprise facture JMJ +""" +@app.route('/myclass/api/JMJ_Repise_Factures/', methods=['POST','GET']) +@crossdomain(origin='*') +def JMJ_Repise_Factures(): + # On recupere le corps (payload) de la requete + payload = mycommon.strip_dictionary (request.form.to_dict()) + print(" ### JMJ_Repise_Factures : payload = ",payload) + localStatus, message= tools_cherif.JMJ_Repise_Factures(payload) + return jsonify(status=localStatus, message=message ) if __name__ == '__main__': diff --git a/partner_client.py b/partner_client.py index 7ea18ca..cef4014 100644 --- a/partner_client.py +++ b/partner_client.py @@ -2430,14 +2430,14 @@ def Controle_Add_Partner_Client_mass(saved_file=None, Folder=None, diction=None) important : verifier s'il y a deja un client avec la meme adresse email """ is_existe_client_count = MYSY_GV.dbname['partner_client'].count_documents( - {"email": str(str(df['email'].values[n]).strip()), + {"email": str(df['email'].values[n]).strip(), 'partner_owner_recid': str(my_partner['recid'])}) if (is_existe_client_count != 0): mycommon.myprint( str(inspect.stack()[0][ - 3]) + " Ligne " + str(n + 2) + " Il a déjà un client avec le même adresse email.") - return False, " Ligne " + str(n + 2) + " Il a déjà un client avec le même adresse email." + 3]) + " Ligne " + str(n + 2) + " Il a déjà un client avec le même adresse email : "+str(df['email'].values[n])) + return False, " Ligne " + str(n + 2) + " Il a déjà un client avec le même adresse email : "+str(df['email'].values[n]) # Controler la civilité du contact principale @@ -3540,6 +3540,9 @@ def Create_Partner_Client_Intranet_Account(diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + """ Recuperation du partnair_account.subdomaine_catalog_pub """ @@ -3604,7 +3607,11 @@ def Create_Partner_Client_Intranet_Account(diction): else: msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = sujetHtml diff --git a/partner_invoice.py b/partner_invoice.py index 289a72d..6d1d4e3 100644 --- a/partner_invoice.py +++ b/partner_invoice.py @@ -823,7 +823,7 @@ def Get_Given_Partner_Invoice_Lines(diction): } }, ] - print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) + #print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) for retval in MYSY_GV.dbname['partner_invoice_line'].aggregate(query): if ('collection_partner_produit_service' in retval.keys() and len(retval['collection_partner_produit_service']) > 0): @@ -908,7 +908,7 @@ def Get_Given_Partner_Invoice_Lines(diction): RetObject.append(mycommon.JSONEncoder().encode(user)) - print(" ### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : RetObject = ", RetObject) + #print(" ### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : RetObject = ", RetObject) return True, RetObject @@ -1140,7 +1140,7 @@ def Get_Given_Partner_Invoice_Lines_From_Invoice_ref_interne(diction): } }, ] - print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) + #print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) for retval in MYSY_GV.dbname['partner_invoice_line'].aggregate(query): if ('collection_partner_produit_service' in retval.keys() and len(retval['collection_partner_produit_service']) > 0): @@ -1310,6 +1310,8 @@ def Get_List_Partner_Invoice_no_filter(diction): user['id'] = str(val_tmp) val_tmp = val_tmp + 1 + + """ recuperer le CA globale et le nombre de factures """ @@ -1361,6 +1363,7 @@ def Get_List_Partner_Invoice_no_filter(diction): user['order_header_vendeur_nom_prenom'] = str(order_header_vendeur_nom_prenom) + ''' """ Recuperer le solde (montant restant à payer) """ @@ -1373,6 +1376,8 @@ def Get_List_Partner_Invoice_no_filter(diction): reste_to_paye = sold_data['remaining_amount'] user['reste_to_paye'] = reste_to_paye + + ''' if( "credit_note_ref" not in New_retVal.keys() ): user['credit_note_ref'] = "" @@ -1380,6 +1385,9 @@ def Get_List_Partner_Invoice_no_filter(diction): if ("invoice_header_origin" not in New_retVal.keys()): user['invoice_header_origin'] = "" + if ("reste_to_paye" not in New_retVal.keys()): + user['reste_to_paye'] = str(user['total_header_toutes_taxes']) + RetObject.append(mycommon.JSONEncoder().encode(user)) @@ -1897,7 +1905,7 @@ def Get_Given_Line_Of_Partner_Invoice_Lines(diction): } }, ] - print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) + #print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) for retval in MYSY_GV.dbname['partner_invoice_line'].aggregate(query): if ('collection_partner_produit_service' in retval.keys() and len(retval['collection_partner_produit_service']) > 0): @@ -2110,7 +2118,7 @@ def GerneratePDF_Partner_Invoice(diction): partner_document_INVOICE_data_qry = {'partner_owner_recid': str(my_partner['recid']), 'valide': '1', 'locked': '0', 'ref_interne': 'PART_INVOICE', 'type_doc':'pdf'} - print(" ### partner_document_INVOICE_data_qry = ", partner_document_INVOICE_data_qry) + #print(" ### partner_document_INVOICE_data_qry = ", partner_document_INVOICE_data_qry) partner_document_INVOICE_data = MYSY_GV.dbname['courrier_template'].find_one( {'partner_owner_recid': str(my_partner['recid']), 'valide': '1', 'locked': '0', 'ref_interne': 'PART_INVOICE', 'type_doc':'pdf'}) @@ -2333,7 +2341,7 @@ def GerneratePDF_Partner_Invoice(diction): } }, ] - print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) + #print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) for retval in MYSY_GV.dbname['partner_invoice_line'].aggregate(query): if ('collection_partner_produit_service' in retval.keys() and len(retval['collection_partner_produit_service']) > 0): @@ -2462,6 +2470,13 @@ def GerneratePDF_Partner_Invoice(diction): convention_dictionnary_data['order_header'] = Order_header_data convention_dictionnary_data['order_lines'] = Order_header_lines_data + # read css file + css_file = "./css_document/elyos_css.css" + from xhtml2pdf.default import DEFAULT_CSS + if css_file is not None: + with open(css_file) as f: + DEFAULT_CSS += f.read() + #sourceHtml = contenu_doc_Template.render(params=Order_header_data, param_order_lines=Order_header_lines_data, company_data=company_data) #sourceHtml = contenu_doc_Template.render(params_order_header=Order_header_data, params_order_lines=Order_header_lines_data, params=company_data['params']) @@ -2477,7 +2492,8 @@ def GerneratePDF_Partner_Invoice(diction): # convert HTML to PDF pisaStatus = pisa.CreatePDF( src=sourceHtml, # the HTML to convert - dest=resultFile) # file handle to receive result + dest=resultFile, + default_css=DEFAULT_CSS) # file handle to receive result # close output file resultFile.close() @@ -2779,7 +2795,7 @@ def Send_Partner_Invoice_By_Email(tab_files, Folder, diction): } }, ] - print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) + #print("#### Get_Given_Partner_Invoice_Lines for PRODUCT & SERVICES : query pip= ", query) for retval in MYSY_GV.dbname['partner_invoice_line'].aggregate(query): if ('collection_partner_produit_service' in retval.keys() and len(retval['collection_partner_produit_service']) > 0): @@ -2925,6 +2941,9 @@ def Send_Partner_Invoice_By_Email(tab_files, Folder, diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data = local_retval company_data = { "params": convention_dictionnary_data, @@ -3202,7 +3221,12 @@ def Send_Partner_Invoice_By_Email(tab_files, Folder, diction): return False, " Aucune adresse email sur la commande " - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = sujetHtml diff --git a/partner_order.py b/partner_order.py index b53e30e..b2fd15a 100644 --- a/partner_order.py +++ b/partner_order.py @@ -68,7 +68,7 @@ def Add_Partner_Order(diction): 'order_header_location_type', 'order_header_origin', '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', - 'order_header_inclus_bpf'] + 'order_header_inclus_bpf', 'order_header_lieu_formation'] """ Important : A noter que "order_lines" est tableau [] qui peut contenir les keys suivantes : 'order_line_formation', 'order_line_qty', 'order_line_prix_unitaire', 'order_line_tax', 'order_line_type_reduction', 'order_line_type_valeur', 'order_line_montant_reduction' @@ -156,6 +156,20 @@ def Add_Partner_Order(diction): return False, " - Le champ 'Commentaire' fait plus de 500 caractères ", False data['order_header_comment'] = diction['order_header_comment'] + order_header_lieu_formation = "" + if ("order_header_lieu_formation" in diction.keys()): + if diction['order_header_lieu_formation']: + order_header_lieu_formation = diction['order_header_lieu_formation'] + if (len(str(order_header_lieu_formation)) > 1000): + mycommon.myprint( + str(inspect.stack()[0][ + 3]) + " - Le champ 'order_header_lieu_formation' fait plus de 500 caractères ") + + return False, " - Le champ 'Lieu de formation' fait plus de 1000 caractères ", False + data['order_header_lieu_formation'] = diction['order_header_lieu_formation'] + + + order_header_condition_paiement_id = "" if ("order_header_condition_paiement_id" in diction.keys()): if diction['order_header_condition_paiement_id']: @@ -616,7 +630,8 @@ def Add_Partner_Quotation(diction): 'order_header_type', 'order_header_location_type', 'order_header_tax', 'order_header_origin', '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', 'order_header_inclus_bpf'] + 'total_lines_hors_taxe_before_lines_reduction', 'total_lines_montant_reduction', 'order_header_inclus_bpf', + 'order_header_lieu_formation'] """ Important : A noter que "order_lines" est tableau [] qui peut contenir les keys suivantes : 'order_line_formation', 'order_line_qty', 'order_line_prix_unitaire', 'order_line_tax', 'order_line_type_reduction', 'order_line_type_valeur', 'order_line_montant_reduction' @@ -745,6 +760,19 @@ def Add_Partner_Quotation(diction): return False, " - Le champ 'Commentaire' fait plus de 500 caractères ", False data['order_header_comment'] = diction['order_header_comment'] + order_header_lieu_formation = "" + if ("order_header_lieu_formation" in diction.keys()): + if diction['order_header_lieu_formation']: + order_header_lieu_formation = diction['order_header_lieu_formation'] + if (len(str(order_header_lieu_formation)) > 1000): + mycommon.myprint( + str(inspect.stack()[0][ + 3]) + " - Le champ 'order_header_lieu_formation' fait plus de 1000 caractères ") + + return False, " - Le champ 'Commentaire' fait plus de 1000 caractères ", False + data['order_header_lieu_formation'] = diction['order_header_lieu_formation'] + + order_header_condition_paiement_id = "" if ("order_header_condition_paiement_id" in diction.keys()): if diction['order_header_condition_paiement_id']: @@ -1161,7 +1189,7 @@ def Update_Partner_Order_Header(diction): 'order_header_total_ttc', 'order_header_status', 'order_header_type_reduction', 'order_header_type_reduction_valeur', 'order_header_montant_reduction', 'order_header_id', 'order_header_type', 'order_header_location_type', 'order_header_origin', - 'order_header_inclus_bpf'] + 'order_header_inclus_bpf', 'order_header_lieu_formation'] @@ -1303,6 +1331,19 @@ def Update_Partner_Order_Header(diction): return False, " - Le champ 'Commentaire' fait plus de 500 caractères " data['order_header_comment'] = diction['order_header_comment'] + + order_header_lieu_formation = "" + if ("order_header_lieu_formation" in diction.keys()): + order_header_lieu_formation = diction['order_header_lieu_formation'] + if (len(str(order_header_lieu_formation)) > 1000): + mycommon.myprint( + str(inspect.stack()[0][ + 3]) + " - Le champ 'order_header_lieu_formation' fait plus de 1000 caractères ") + + return False, " - Le champ 'Lieu de formation' fait plus de 1000 caractères " + data['order_header_lieu_formation'] = diction['order_header_lieu_formation'] + + order_header_condition_paiement_id = "" if ("order_header_condition_paiement_id" in diction.keys() and diction['order_header_condition_paiement_id']): order_header_condition_paiement_id = diction['order_header_condition_paiement_id'] @@ -1658,7 +1699,7 @@ def Update_Partner_Quotation_Header(diction): 'order_header_total_ttc', 'order_header_status', 'order_header_type_reduction', 'order_header_type_reduction_valeur', 'order_header_montant_reduction', 'order_header_id', 'order_header_type', 'order_header_location_type', - 'order_header_origin', 'order_header_inclus_bpf'] + 'order_header_origin', 'order_header_inclus_bpf', 'order_header_lieu_formation'] incom_keys = diction.keys() for val in incom_keys: @@ -1808,6 +1849,19 @@ def Update_Partner_Quotation_Header(diction): return False, " - Le champ 'Commentaire' fait plus de 500 caractères " data['order_header_comment'] = diction['order_header_comment'] + order_header_lieu_formation = "" + if ("order_header_lieu_formation" in diction.keys()): + order_header_lieu_formation = diction['order_header_lieu_formation'] + if (len(str(order_header_lieu_formation)) > 1000): + mycommon.myprint( + str(inspect.stack()[0][ + 3]) + " - Le champ 'order_header_lieu_formation' fait plus de 1000 caractères ") + + return False, " - Le champ 'Lieu de formation' fait plus de 1000 caractères " + data['order_header_lieu_formation'] = diction['order_header_lieu_formation'] + + + order_header_condition_paiement_id = "" if ("order_header_condition_paiement_id" in diction.keys() and diction['order_header_condition_paiement_id']): order_header_condition_paiement_id = diction['order_header_condition_paiement_id'] @@ -3518,6 +3572,9 @@ def Get_Given_Partner_Order(diction): if( "order_header_inclus_bpf" not in retval.keys() ): user['order_header_inclus_bpf'] = "" + if ("order_header_lieu_formation" not in retval.keys()): + user['order_header_lieu_formation'] = "" + # Si le champ 'order_header_condition_paiement_id' alors on va chercher le code de la condition de paiement paiement_ction_code = "" if ('order_header_condition_paiement_id' in retval.keys() and retval['order_header_condition_paiement_id'] ): @@ -3713,6 +3770,7 @@ def Get_Given_Partner_Order_Lines(diction): else: user['order_line_tax'] = "" + if ("order_line_tax_amount" in retval.keys()): user['order_line_tax_amount'] = retval['order_line_tax_amount'] else: @@ -5568,6 +5626,9 @@ def GerneratePDF_Partner_Order(diction): ] #print("#### Get_Given_Partner_Order_Lines_From_order_ref_interne : query pip= ", query) + tab_session_ids = [] + tab_class_ids = [] + for retval in MYSY_GV.dbname['partner_order_line'].aggregate(query): if ('myclass_collection' in retval.keys() and len(retval['myclass_collection']) > 0): user = {} @@ -5590,6 +5651,8 @@ def GerneratePDF_Partner_Order(diction): if (local_session_data): + tab_session_ids.append(str(local_session_data['_id'])) + if ("code_session" in local_session_data.keys()): user['code_session'] = local_session_data['code_session'] else: @@ -5660,6 +5723,8 @@ def GerneratePDF_Partner_Order(diction): user['title'] = retval['myclass_collection'][0]['title'] user['order_line_formation_external_code'] = retval['myclass_collection'][0]['external_code'] user['class_id'] = str(retval['myclass_collection'][0]['_id']) + tab_class_ids.append(str(retval['myclass_collection'][0]['_id'])) + if( "domaine" in retval['myclass_collection'][0].keys() ): user['domaine'] = retval['myclass_collection'][0]['domaine'] @@ -5856,12 +5921,23 @@ def GerneratePDF_Partner_Order(diction): tab_client = [] tab_client.append(ObjectId(str(Order_header_data['order_header_client_id']))) + tab_session_ids_ObjectId = [] + for tmp in tab_session_ids: + if( tmp ): + tab_session_ids_ObjectId.append(ObjectId(str(tmp))) + + + tab_class_ids_ObjectId = [] + for tmp in tab_class_ids: + if (tmp): + tab_class_ids_ObjectId.append(ObjectId(str(tmp))) + convention_dictionnary_data = {} new_diction = {} new_diction['token'] = diction['token'] new_diction['list_stagiaire_id'] = [] - new_diction['list_session_id'] = [] - new_diction['list_class_id'] = [] + new_diction['list_session_id'] = tab_session_ids_ObjectId + new_diction['list_class_id'] = tab_class_ids_ObjectId new_diction['list_client_id'] = tab_client new_diction['list_apprenant_id'] = [] @@ -5879,6 +5955,8 @@ def GerneratePDF_Partner_Order(diction): "params": convention_dictionnary_data, } + print(" ### bodybody = ", body) + contenu_doc_Template = jinja2.Template(str(partner_document_CONF_ORDER_data['contenu_doc'])) #print(" #### Order_header_data = ", Order_header_data) @@ -6894,6 +6972,9 @@ def Send_Partner_Order_By_Email(tab_files, Folder, diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data = local_retval convention_dictionnary_data['order_header'] = Order_header_data @@ -7124,7 +7205,11 @@ def Send_Partner_Order_By_Email(tab_files, Folder, diction): return False, " Aucune adresse email sur la commande " - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = sujetHtml @@ -8422,6 +8507,9 @@ def Send_Quotation_Remind_Level1(diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data = local_retval @@ -8985,7 +9073,12 @@ def Send_Quotation_Remind_Level1(diction): msg.attach(html_mime) smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = sujetHtml toaddrs = ",".join(tab_emails_destinataire) diff --git a/survey_mgt.py b/survey_mgt.py index 8f98a68..a6f91a5 100644 --- a/survey_mgt.py +++ b/survey_mgt.py @@ -547,6 +547,13 @@ def Send_Survey_Alert_Notif(diction): if (courrier_data_status is False): return courrier_data_status, courrier_data_retval + my_company_data = MYSY_GV.dbname['partnair_account'].find_one( + {'recid': str(diction['partner_owner_recid']), 'is_partner_admin_account': '1', 'active': '1', + 'locked': '0'}, + {'_id': 1, 'nom': 1}) + + if (my_company_data and "nom" in my_company_data.keys() and my_company_data['nom']): + company_name = my_company_data['nom'] if ("contenu_doc" not in courrier_data_retval.keys() or str(courrier_data_retval['contenu_doc']) == ""): mycommon.myprint( @@ -564,12 +571,14 @@ def Send_Survey_Alert_Notif(diction): if (str(partner_own_smtp_value) == "1"): smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port) + smtpserver.ehlo() + smtpserver.starttls() + smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password) else: smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port) - - smtpserver.ehlo() - smtpserver.starttls() - smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password) + smtpserver.ehlo() + smtpserver.starttls() + smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password) # Traitement du sujet du mail sujet_mail_Template = jinja2.Template(str(courrier_data_retval['sujet'])) @@ -611,7 +620,12 @@ def Send_Survey_Alert_Notif(diction): else: msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) + msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = sujetHtml @@ -1666,6 +1680,9 @@ def Send_Survey_TabIds(diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data = local_retval servey_url = MYSY_GV.CLIENT_URL_BASE + "Survey/" + str(local_survey_retval['_id']) @@ -1739,7 +1756,11 @@ def Send_Survey_TabIds(diction): else: msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = str(subject) # msg['to'] = "billardman01@hotmail.com" @@ -2094,6 +2115,9 @@ def Automatic_Send_Survey_TabIds(diction): if (local_status is False): return local_status, local_retval + if ("company_data" in local_retval.keys() and "societe_nom" in local_retval['company_data'].keys()): + company_name = local_retval['company_data']['societe_nom'] + convention_dictionnary_data = local_retval servey_url = MYSY_GV.CLIENT_URL_BASE + "Survey/" + str(local_survey_retval['_id']) @@ -2142,7 +2166,11 @@ def Automatic_Send_Survey_TabIds(diction): else: msg.attach(html_mime) - msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + #msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User + if (company_name): + msg['From'] = str(company_name) + " <" + str(MYSY_GV.O365_SMTP_COUNT_From_User) + ">" + else: + msg['From'] = str(MYSY_GV.O365_SMTP_COUNT_From_User) msg['Bcc'] = 'contact@mysy-training.com' msg['Subject'] = str(subject) # msg['to'] = "billardman01@hotmail.com"