From eca3bda91094ef99f9e10ca292ba55ceea9aed2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ch=C3=A9rifBALDE?= Date: Mon, 22 Aug 2022 23:55:15 +0200 Subject: [PATCH] 22/08/22 - 23h30 --- class_mgt.py | 137 +++++++++++++++++++++++++++++++++++++++++--- ela_factures_mgt.py | 9 ++- email_mgt.py | 130 ++++++++++++++++++++++++++++++++++++++++- main.py | 24 +++++--- partners.py | 2 +- prj_common.py | 16 ++++++ 6 files changed, 296 insertions(+), 22 deletions(-) diff --git a/class_mgt.py b/class_mgt.py index 48c1baa..1306dfa 100644 --- a/class_mgt.py +++ b/class_mgt.py @@ -49,7 +49,7 @@ def add_class(diction): ''' field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', 'presentiel', 'price', 'url','duration', 'duration_unit', 'token', 'plus_produit', 'mots_cle','domaine', - 'internal_url', 'zone_diffusion', 'metier'] + 'internal_url', 'zone_diffusion', 'metier', 'date_lieu'] incom_keys = diction.keys() for val in incom_keys: if val not in field_list: @@ -200,7 +200,7 @@ def add_class(diction): if ("zone_diffusion" in diction.keys()): if diction['zone_diffusion']: - tmp_str2 = str(diction['zone_diffusion']).lower().replace(",", ";") + tmp_str2 = str(diction['zone_diffusion']).lower().replace(",", ";").replace("\r\n", "") if (not tmp_str2.endswith(";")): tmp_str2 = tmp_str2 + ";" @@ -247,6 +247,63 @@ def add_class(diction): mydata['zone_diffusion'] = {'country':tab_country, 'city':tab_city} + ''' + Traitement date_lieu + ''' + mydata['datelieu'] = "" + if ("date_lieu" in diction.keys()): + if diction['date_lieu']: + tmp_str2 = str(diction['date_lieu']).lower().replace(",", ";").replace("\r\n", "") + + if (not tmp_str2.endswith(";")): + tmp_str2 = tmp_str2 + ";" + + print("tmp_str2 = " + tmp_str2) + + if (";" not in tmp_str2): + mycommon.myprint(str(inspect.stack()[0][3]) + " - les dates et lieux de la formation : A" + str( + diction['external_code']) + " sont incorrectes") + return False, "Les Dates et Lieux de la formation " + str( + diction['external_code']) + " sont incorrectes. Le format attendu : " \ + "jj/mm/aaaa-ville;jj/mm/aaaa-ville2" + + tmp_str = tmp_str2.split( + ";") # ==> ce qui va donner un tableau de : Country_Code-City : ['11/02/2012-paris', '24/04/2022-marseille',] + + dl_cpt = 0 + tab_dl = [] + for tmp_dl in tmp_str: + if(len(str(tmp_dl)) > 0 and ("-" in tmp_dl) ): + #print(" ###### DATE LIEU = "+tmp_dl) + tab_date_lieu = tmp_dl.split('-') + if (len(tab_date_lieu) != 2): + return False, "Les Dates et Lieux de la formation " + str( + diction['external_code']) + " sont incorrectes. Le format attendu : " \ + "jj/mm/aaaa-ville;jj/mm/aaaa-ville2 1" + + isdate = mycommon.CheckidDate( str(tab_date_lieu[0])) + if( isdate is False ): + mycommon.myprint( + str(inspect.stack()[0][3]) + " - les dates et lieux de la formation : A" + str( + diction['external_code']) + " sont incorrectes") + return False, "Les Dates et Lieux de la formation " + str( + diction['external_code']) + " sont incorrectes. Le format attendu : " \ + "jj/mm/aaaa-ville;jj/mm/aaaa-ville2" + + val_dl = {'date':str(tab_date_lieu[0]), 'ville':str(tab_date_lieu[1])} + tab_dl.append(val_dl) + #mydata['date_lieu'][dl_cpt] = {'date': str(tab_date_lieu[0]), 'ville': str(tab_date_lieu[1])} + #print(str(mydata['date_lieu'] )) + #print(" ######### date_lieu = " + str(tab_date_lieu[0]) + " ----- " + str(tab_date_lieu[1])) + + dl_cpt = dl_cpt +1 + + elif (len(str(tmp_dl)) > 0 and ("-" not in tmp_dl)): + return False, "Les Dates et Lieux de la formation " + str( + diction['external_code']) + " sont incorrectes. Le format attendu : " \ + "jj/mm/aaaa-ville;jj/mm/aaaa-ville2" + + mydata['datelieu'] = tab_dl mydata['valide'] = '1' mydata['locked'] = '0' @@ -311,7 +368,7 @@ def update_class(diction): ''' field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', 'presentiel','price', 'url', 'duration', 'token','plus_produit', 'mots_cle', - 'domaine', 'internal_code', 'internal_url','zone_diffusion', 'metier'] + 'domaine', 'internal_code', 'internal_url','zone_diffusion', 'metier', 'date_lieu'] incom_keys = diction.keys() for val in incom_keys: @@ -422,9 +479,7 @@ def update_class(diction): mydata['domaine'] = diction['domaine'] if ("zone_diffusion" in diction.keys()): - tmp_str2 = str(diction['zone_diffusion']).lower().replace(",", ";") - - + tmp_str2 = str(diction['zone_diffusion']).lower().replace(",", ";").replace("\r\n", "") if( not tmp_str2.endswith(";")): tmp_str2 = tmp_str2+";" @@ -472,6 +527,64 @@ def update_class(diction): mydata['zone_diffusion'] = {'country':tab_country, 'city':tab_city} + ''' + Traitement date_lieu + ''' + mydata['datelieu'] = "" + if ("date_lieu" in diction.keys()): + if diction['date_lieu']: + tmp_str2 = str(diction['date_lieu']).lower().replace(",", ";").replace("\r\n", "") + + if (not tmp_str2.endswith(";")): + tmp_str2 = tmp_str2 + ";" + + print("tmp_str2 = " + tmp_str2) + + if (";" not in tmp_str2): + mycommon.myprint(str(inspect.stack()[0][3]) + " - les dates et lieux de la formation : A" + str( + diction['external_code']) + " sont incorrectes") + return False, "Les Dates et Lieux de la formation " + str( + diction['external_code']) + " sont incorrectes. Le format attendu : " \ + "jj/mm/aaaa-ville;jj/mm/aaaa-ville21" + + tmp_str = tmp_str2.split( + ";") # ==> ce qui va donner un tableau de : Country_Code-City : ['11/02/2012-paris', '24/04/2022-marseille',] + + + dl_cpt = 0 + tab_dl = [] + for tmp_dl in tmp_str: + if(len(str(tmp_dl)) > 0 and ("-" in tmp_dl) ): + #print(" ###### DATE LIEU = "+tmp_dl) + tab_date_lieu = tmp_dl.split('-') + if( len(tab_date_lieu) != 2): + return False, "Les Dates et Lieux de la formation " + str( + diction['external_code']) + " sont incorrectes. Le format attendu : " \ + "jj/mm/aaaa-ville;jj/mm/aaaa-ville23" + + isdate = mycommon.CheckisDate( str(tab_date_lieu[0])) + if( isdate is False ): + mycommon.myprint( + str(inspect.stack()[0][3]) + " - les dates et lieux de la formation : A" + str( + diction['external_code']) + " sont incorrectes") + return False, "Les Dates et Lieux de la formation " + str( + diction['external_code']) + " sont incorrectes. Le format attendu : " \ + "jj/mm/aaaa-ville;jj/mm/aaaa-ville24" + + val_dl = {'date':str(tab_date_lieu[0]), 'ville':str(tab_date_lieu[1])} + tab_dl.append(val_dl) + #mydata['date_lieu'][dl_cpt] = {'date': str(tab_date_lieu[0]), 'ville': str(tab_date_lieu[1])} + #print(str(mydata['date_lieu'] )) + #print(" ######### date_lieu = " + str(tab_date_lieu[0]) + " ----- " + str(tab_date_lieu[1])) + + dl_cpt = dl_cpt +1 + + elif ( len(str(tmp_dl)) > 0 and ("-" not in tmp_dl) ): + return False, "Les Dates et Lieux de la formation " + str( + diction['external_code']) + " sont incorrectes. Le format attendu : " \ + "jj/mm/aaaa-ville;jj/mm/aaaa-ville25" + + mydata['datelieu'] = tab_dl @@ -1433,8 +1546,9 @@ def add_class_mass(file=None, Folder=None, diction=None): ''' # Verification que les noms des colonne sont bien corrects" ''' - field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', 'presentiel', - 'price', 'domaine', 'url','duration', 'plus_produit', 'mots_cle', 'zone_diffusion', 'metier'] + field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', + 'distantiel', 'presentiel', 'price', 'domaine', 'url','duration', 'plus_produit', + 'mots_cle', 'zone_diffusion', 'metier', 'date_lieu'] total_rows = len(df) @@ -1467,7 +1581,6 @@ def add_class_mass(file=None, Folder=None, diction=None): mydata['price'] = str(df['price'].values[n]) mydata['metier'] = str(df['metier'].values[n]) - ''' Verification du nombre de mots clée : limite MAX_KEYWORD (3) ''' @@ -1485,6 +1598,12 @@ def add_class_mass(file=None, Folder=None, diction=None): if(str(df['zone_diffusion'].values[n])): mydata['zone_diffusion'] =str(df['zone_diffusion'].values[n]) + ''' + Traitement des date et lieu de la formation + ''' + if ("date_lieu" in df.keys()): + if(str(df['date_lieu'].values[n])): + mydata['date_lieu'] =str(df['date_lieu'].values[n]) if ("token" in diction.keys()): if diction['token']: diff --git a/ela_factures_mgt.py b/ela_factures_mgt.py index 6deae44..0af4c19 100644 --- a/ela_factures_mgt.py +++ b/ela_factures_mgt.py @@ -16,6 +16,7 @@ import pandas as pd from pymongo import ReturnDocument from math import isnan import GlobalVariable as MYSY_GV +import email_mgt as email class JSONEncoder(json.JSONEncoder): def default(self, o): @@ -417,7 +418,7 @@ def createOrder(diction): if (part_account.count() <= 0): mycommon.myprint( str(inspect.stack()[0][3]) + "Aucune donnée client, Impossible de créer la commande ") - return False, "Aucune donnée client,, Impossible de créer la commande ", None + return False, "Aucune donnée client, Impossible de créer la commande ", None if ("invoice_nom" in part_account[0].keys()): @@ -497,7 +498,7 @@ def createOrder(diction): if part_account[0]['num_carte']: new_data['num_carte_payment'] = part_account[0]['num_carte'] - + new_data['nb_product'] = str(nb_line) i = 0 while (i < nb_line): print("PRODUIT N° " + str((i + 1)) + " : " ) @@ -526,6 +527,8 @@ def createOrder(diction): ret_val = coll_order.insert_one(new_data) if ret_val and ret_val.inserted_id: + print( "str(new_data['invoice_email']) = "+str(new_data['invoice_email'])) + email.SalesOrderConfirmationEmail(str(new_data['invoice_email']), new_data ) return True, "la commande été correctement créee", str(new_data['order_id']) else: mycommon.myprint( @@ -536,3 +539,5 @@ def createOrder(diction): exc_type, exc_obj, exc_tb = sys.exc_info() mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno)) return False, " Impossible de créer la facture" + + diff --git a/email_mgt.py b/email_mgt.py index 326e542..a5a5438 100644 --- a/email_mgt.py +++ b/email_mgt.py @@ -52,7 +52,7 @@ def send_user_account_mail(message, account_mail): my_url = "" if (MYSY_GV.MYSY_ENV == "PROD"): - my_url = "https://www.mysy-training.com/myclass/api/valide_user_account/"+str(message) + my_url = "https://apimysy.iexercice.com/myclass/api/valide_user_account/"+str(message) elif (MYSY_GV.MYSY_ENV == "DEV"): my_url = "http://localhost:5000/myclass/api/valide_user_account/"+str(message) @@ -98,7 +98,7 @@ def send_user_thks_mail(message, account_mail): my_url = "" if (MYSY_GV.MYSY_ENV == "PROD"): - my_url = "https://www.mysy-training.com/myclass/api/valide_user_account/" + str(message) + my_url = "https://apimysy.iexercice.com/myclass/api/valide_user_account/" + str(message) elif (MYSY_GV.MYSY_ENV == "DEV"): my_url = "http://localhost:5000/myclass/api/valide_user_account/" + str(message) @@ -129,7 +129,7 @@ def send_partner_account_mail(message, account_mail): my_url = "" if (MYSY_GV.MYSY_ENV == "PROD"): - my_url = "https://www.mysy-training.com/myclass/api/valide_partnair_account/" + str(message) + my_url = "https://apimysy.iexercice.com/myclass/api/valide_partnair_account/" + str(message) elif (MYSY_GV.MYSY_ENV == "DEV"): my_url = "http://localhost:5000/myclass/api/valide_partnair_account/"+str(message) @@ -354,6 +354,130 @@ def Pro_Account_Token_Pass(account_mail, my_token): print(api_response) return True + 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 + + +''' +Cette fonction envoie l'email de confirmation de la commande de vente +''' +def SalesOrderConfirmationEmail(account_mail, 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 + ''' + field_list_obligatoire = ['invoice_nom', 'invoice_adr_city', 'invoice_adr_country', 'invoice_adr_street', + 'invoice_adr_zip', 'periodicite', 'prix_ht', 'prix_ttc', 'order_id', + 'date_update', 'nb_product'] + + 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 liste ") + return False, " Impossible d'envoyer l'email de confirmation" + + total_ht = diction['prix_ht'] + tva = "20%%ch" + total_ttc = diction['prix_ttc'] + client_name = diction['invoice_nom'] + client_address = diction['invoice_adr_street'] + client_zip_ville = diction['invoice_adr_zip']+" "+diction['invoice_adr_city'] + client_pays = diction['invoice_adr_country'] + order_id = diction['order_id'] + date_order = diction['date_update'] + nb_line = mycommon.tryInt(diction['nb_product']) + + if( nb_line == 0 ): + mycommon.myprint(str(inspect.stack()[0][3]) + " - nb_line = '" + nb_line + "' : Aucun produit à facturer") + return False, " Impossible d'envoyer l'email de confirmation" + + print("client_name = "+str(client_name)) + print("client_address = " + str(client_address)) + print("client_zip_ville = " + str(client_zip_ville)) + print("client_pays = " + str(client_pays)) + print("order_id = " + str(order_id)) + print("date_order = " + str(date_order)) + print("nb_line = " + str(nb_line)) + + # Recuperation des produits (max 3 produits) + # produit 1 + if ("item_0" in diction.keys()): + if( diction["item_0"] ): + packs = diction["item_0"]['code'] + qty = "1" + unit_price = diction["item_0"]['prix'] + montant = diction["item_0"]['prix'] + + # produit 2 + if ("item_1" in diction.keys()): + if (diction["item_1"]): + packs1 = diction["item_1"]['code'] + qty1 = "1" + unit_price1 = diction["item_1"]['prix'] + montant1 = diction["item_1"]['prix'] + + # produit 3 + if ("item_2" in diction.keys()): + if (diction["item_2"]): + packs2 = diction["item_2"]['code'] + qty2 = "1" + unit_price2 = diction["item_2"]['prix'] + montant2 = diction["item_2"]['prix'] + + + i = 0 + while (i < nb_line): + row = "item_" + str(i) + print(" product = "+ str(diction[str(row)])) + i = i + 1 + + receiver = [str(account_mail)] + toaddrs = ", ".join(receiver) + + print(" mail enoye à toaddrs : " + toaddrs) + print("debut envoi mail de test ") + # on rentre les renseignements pris sur le site du fournisseur + + msg = MIMEMultipart("alternative") + + msg['Subject'] = '[MySy Training]: votre compte PRO est pret' + msg['From'] = 'contact@mysy-training.com' + msg['To'] = str(toaddrs) + msg['Cc'] = 'contact@mysy-training.com' + + to = [{"email": str(account_mail)}] + + print(" ############# to = "+str(to)) + bcc = [{"email": "contact@mysy-training.com"}] + + + send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(template_id=22, params={"order_id": order_id, + "date_order": date_order, + "packs": packs, + "qty": qty, + "unit_price": unit_price, + "total_ht": total_ht, + "tva": tva, + "total_ttc": total_ttc, + "client_name": client_name, + "client_address": client_address, + "client_zip_ville": client_zip_ville, + "client_pays": client_pays, + + }, to=to, bcc=bcc) + api_response = api_instance.send_transac_email(send_smtp_email) + print(api_response) + return True + + + + + 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)) diff --git a/main.py b/main.py index cf23ac3..d1757f8 100644 --- a/main.py +++ b/main.py @@ -218,11 +218,16 @@ def valide_user_account(value): url = "" if( status ): - url = 'https://www.mysy-training.com/mysy-account-activated/' - url = 'http://localhost:3009/mysy-account-activated/' + if (MYSY_GV.MYSY_ENV == "PROD"): + url = 'https://www.mysy-training.com/mysy-account-activated/' + elif (MYSY_GV.MYSY_ENV == "DEV"): + url = 'http://localhost:3009/mysy-account-activated/' else: - url = 'https://www.mysy-training.com/erreur' - url = 'http://localhost:3009/erreur/' + if (MYSY_GV.MYSY_ENV == "PROD"): + url = 'https://www.mysy-training.com/erreur' + + elif (MYSY_GV.MYSY_ENV == "DEV"): + url = 'http://localhost:3009/erreur/' return redirect(url) @@ -505,10 +510,15 @@ def valide_partnair_account(value): result, token = pa.valide_partnair_account(value) if (result): - url = 'https://www.mysy-training.com/PartnerLogin0/' - url = 'http://localhost:3009/PartnerLogin0' + if (MYSY_GV.MYSY_ENV == "PROD"): + url = 'https://www.mysy-training.com/PartnerLogin0/' + elif (MYSY_GV.MYSY_ENV == "DEV"): + url = 'http://localhost:3009/PartnerLogin0' else: - url = 'https://www.mysy-training.com/erreur' + if (MYSY_GV.MYSY_ENV == "PROD"): + url = 'https://www.mysy-training.com/erreur' + elif (MYSY_GV.MYSY_ENV == "DEV"): + url = 'https://www.mysy-training.com/erreur' return redirect(url) diff --git a/partners.py b/partners.py index 6acccca..f6e001d 100644 --- a/partners.py +++ b/partners.py @@ -539,7 +539,7 @@ def update_partner_account(diction): if ("invoice_email" in diction.keys()): if diction['invoice_email']: - mydata['invoice_email'] = diction['invoice_adr_zip'] + mydata['invoice_email'] = diction['invoice_email'] if ("invoice_telephone" in diction.keys()): if diction['invoice_telephone']: diff --git a/prj_common.py b/prj_common.py index e80560c..1785bab 100644 --- a/prj_common.py +++ b/prj_common.py @@ -400,6 +400,22 @@ def tryInt(val): return 0 +''' +Cette fonction verifie si une chaine est de type date jj/mm/aaaa +''' +def CheckisDate(mydate): + # mydate doit etre au format : jj/mm/aaaa + try: + print(" analyse de "+mydate) + val = datetime.strptime(mydate, '%d/%m/%Y') + + return True + except Exception as e: + exc_type, exc_obj, exc_tb = sys.exc_info() + myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno)) + return False + + ''' Verification que le mot n'est pas stemisable à traver la tabla "word_not_stem