12/05/2024 - 21h30

master
cherif 2024-05-12 21:17:30 +02:00
parent 64ead66d7c
commit 3ce781ec1b
6 changed files with 3663 additions and 123 deletions

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="dd">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="ddsdfsd">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Job_Cron.py" beforeDir="false" afterPath="$PROJECT_DIR$/Job_Cron.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/partner_order.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_order.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -76,13 +77,6 @@
<option name="presentableId" value="Default" />
<updated>1680804787304</updated>
</task>
<task id="LOCAL-00246" summary="20/03/2024 - 22h30d">
<created>1711130098363</created>
<option name="number" value="00246" />
<option name="presentableId" value="LOCAL-00246" />
<option name="project" value="LOCAL" />
<updated>1711130098364</updated>
</task>
<task id="LOCAL-00247" summary="20/03/2024 - 22h30dss">
<created>1711148467159</created>
<option name="number" value="00247" />
@ -419,7 +413,14 @@
<option name="project" value="LOCAL" />
<updated>1715448610313</updated>
</task>
<option name="localTasksCounter" value="295" />
<task id="LOCAL-00295" summary="ddsdfsd">
<created>1715528112769</created>
<option name="number" value="00295" />
<option name="presentableId" value="LOCAL-00295" />
<option name="project" value="LOCAL" />
<updated>1715528112770</updated>
</task>
<option name="localTasksCounter" value="296" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -461,7 +462,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="14/04/2024 - 23h05" />
<MESSAGE value="17/04/2024 - 21h04" />
<MESSAGE value="18/04/2024 - 21h50" />
<MESSAGE value="19/04/2024 - 22h22" />
@ -486,6 +486,7 @@
<MESSAGE value="10/05/2024 - 18h30" />
<MESSAGE value="gdf" />
<MESSAGE value="dd" />
<option name="LAST_COMMIT_MESSAGE" value="dd" />
<MESSAGE value="ddsdfsd" />
<option name="LAST_COMMIT_MESSAGE" value="ddsdfsd" />
</component>
</project>

View File

@ -280,7 +280,7 @@ def Cron_Quotation_Relance():
{'$match': devis_qery_match},
])
print(" ## pipe_qry Cron_Quotation_Relance = ", pipe_qry)
#print(" ## pipe_qry Cron_Quotation_Relance = ", pipe_qry)
for local_devis in MYSY_GV.dbname['partner_order_header'].aggregate(pipe_qry):
is_quotation_validated = 0
@ -315,25 +315,23 @@ def Cron_Quotation_Relance():
new_relance_date_ISODATE = date_derniere_relance_auto_ISODATE + timedelta(days=frequence_relance_auto)
"""
print(" ### LA frequence_relance_auto ", frequence_relance_auto)
print(" ### LA dernière relance date de ", date_derniere_relance_auto)
print(" ### LA PROCHAINE RELANCE EST ", new_relance_date_ISODATE)
"""
new_relance_date_no_ISODATE = str(new_relance_date_ISODATE.strftime("%d/%m/%Y"))
print(" ### LA PROCHAINE RELANCE EST (new_relance_date_no_ISODATE) ", new_relance_date_no_ISODATE)
#print(" ### LA PROCHAINE RELANCE EST (new_relance_date_no_ISODATE) ", new_relance_date_no_ISODATE)
datetime.strptime(str(todays_date), '%d/%m/%Y')
if( datetime.strptime(str(todays_date), '%d/%m/%Y') >= datetime.strptime( str(new_relance_date_no_ISODATE).strip(), '%d/%m/%Y') ):
print(" ### todays_date est SUPERIEUR = new_relance_date_ISODATE")
else:
print(" ### todays_date est INFERIEUR new_relance_date_ISODATE")
if( is_quotation_validated == 0 and relance_done <= nb_limite_relance and datetime.strptime(str(todays_date), '%d/%m/%Y') >= datetime.strptime( str(new_relance_date_no_ISODATE).strip(), '%d/%m/%Y') ):
print(" ### OUIIII on fait la relanceeeeeeeeeeeee")
"""
On fait le traitement, on envoie le mail
1 - recuperation des data
@ -400,11 +398,13 @@ def Cron_Quotation_Relance():
return_document=ReturnDocument.AFTER
)
"""
else:
print(" ### NoNNNNNNNNNN on NEEEE fait la relanceeeeeeeeeeeee")
print(" limite relance atteint : ")
print(" limite relance_done : ", relance_done)
print(" limite nb_limite_relance : ", nb_limite_relance)
"""
return True, ""

File diff suppressed because it is too large Load Diff

View File

@ -9164,7 +9164,8 @@ def Global_MySy_Cron_Traitement():
def Internal_Global_MySy_Cron_Traitement():
print(" ### CRONNN Internal_Global_MySy_Cron_Traitement : payload = ")
#localStatus, message = Stripe.Cron_Strip_Get_Customer_Abonnement_Data()
status, retval = Job_Cron.Global_MySy_Cron_Traitement()
print(" FIN traitement Internal_Global_MySy_Cron_Traitement localStatus = ", status)
return True

View File

@ -23,6 +23,7 @@ from datetime import datetime, date
import E_Sign_Document
import Inscription_mgt
import partner_client
import prj_common as mycommon
import secrets
import inspect
@ -6467,32 +6468,68 @@ def Send_Quotation_Remind_Level1(diction):
'partner_owner_recid': str(
my_partner['recid'])})
partner_document_CONF_ORDER_data_qry = {'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER',
'type_doc': 'email'}
# Creation du dictionnaire d'information à utiliser pour la creation du doc
tab_client = []
tab_client.append(ObjectId(str(Order_header_data['order_header_client_id'])))
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_client_id'] = tab_client
new_diction['list_apprenant_id'] = []
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
if (local_status is False):
return local_status, local_retval
convention_dictionnary_data = local_retval
body = {
"params": convention_dictionnary_data,
}
"""
# Recuperer le modele de courrier pour la relance niveau 1 des devis :
ref_interne = 'QUOTATION_REMINDER_LEVEL_1'
"""
# print(" ### partner_document_CONF_ORDER_data_qry = ", partner_document_CONF_ORDER_data_qry)
partner_document_CONF_ORDER_data = MYSY_GV.dbname['courrier_template'].find_one(
partner_document_QUOTATION_REMIND_data = MYSY_GV.dbname['courrier_template'].find_one(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER', 'type_doc': 'email'})
'valide': '1', 'locked': '0', 'ref_interne': 'QUOTATION_REMINDER_LEVEL_1',
'type_doc': 'email'})
if (partner_document_CONF_ORDER_data is None):
if (partner_document_QUOTATION_REMIND_data is None):
# Il n'existe pas de personnalisation de la preinscription pour ce partenaire, on va aller récupérer la presinscription pa defaut
partner_document_CONF_ORDER_data = MYSY_GV.dbname['courrier_template'].find_one(
partner_document_QUOTATION_REMIND_data = MYSY_GV.dbname['courrier_template'].find_one(
{'partner_owner_recid': 'default',
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER', 'type_doc': 'email'})
'valide': '1', 'locked': '0', 'ref_interne': 'QUOTATION_REMINDER_LEVEL_1',
'type_doc': 'email'})
if (partner_document_CONF_ORDER_data is None):
if (partner_document_QUOTATION_REMIND_data is None):
mycommon.myprint(
str(inspect.stack()[0][
3]) + "Aucun document parametré ")
return False, "Aucun document parametré "
3]) + " Aucun document de type 'partner_document_QUOTATION_REMIND_data' paramétrer ")
return False, " Aucun document de type 'partner_document_QUOTATION_REMIND_data' paramétrer "
if ("contenu_doc" not in partner_document_CONF_ORDER_data or len(
str(partner_document_CONF_ORDER_data['contenu_doc'])) <= 0):
if ("contenu_doc" not in partner_document_QUOTATION_REMIND_data or len(
str(partner_document_QUOTATION_REMIND_data['contenu_doc'])) <= 0):
mycommon.myprint(str(inspect.stack()[0][
3]) + " - Le parametrage du document est invalide")
return False, " Le parametrage du document est invalide "
3]) + " - Le paramétrage du document est invalide -contenu_doc- ")
return False, " Le paramétrage du document est invalide -contenu_doc- "
if ("corps_mail" not in partner_document_QUOTATION_REMIND_data or len(
str(partner_document_QUOTATION_REMIND_data['corps_mail'])) <= 0):
mycommon.myprint(str(inspect.stack()[0][
3]) + " - Le paramétrage du document est invalide -corps_mail- ")
return False, " Le paramétrage du document est invalide -corps_mail- "
# Recuperation des données du client
if ("order_header_client_id" in Order_header_data.keys()):
@ -6505,6 +6542,25 @@ def Send_Quotation_Remind_Level1(diction):
3]) + " - Le client est invalide")
return False, " Le client est invalide"
# Recuperation des contacts de communication du client
tab_emails_destinataire = []
local_diction = {}
local_diction['token'] = diction['token']
local_diction['_id'] = str(Order_header_data['order_header_client_id'])
local_status, partner_client_contact_communication = partner_client.Get_Partner_Client_Communication_Contact(
local_diction)
if (local_status is True):
# print(" partner_client_contact_communication = ", partner_client_contact_communication)
for contact_communication_str in partner_client_contact_communication:
contact_communication = ast.literal_eval(contact_communication_str)
if( "email" in contact_communication.keys() and contact_communication['email']):
tab_emails_destinataire.append(str(contact_communication['email']))
# Recuperation des details de lignes de : partner_order_line
filt_class_partner_recid = {'partner_owner_recid': str(my_partner['recid'])}
filt_order_header_order_id = {'order_header_id': str(diction['order_id'])}
@ -6628,37 +6684,77 @@ def Send_Quotation_Remind_Level1(diction):
# print(" ### Order_header_lines_data = ", Order_header_lines_data)
contenu_doc_Template = jinja2.Template(str(partner_document_CONF_ORDER_data['contenu_doc']))
# Traitement de l'eventuel fichier joint
tab_files_to_attache_to_mail = []
contenu_doc_Template_subject = jinja2.Template(str(partner_document_CONF_ORDER_data['sujet']))
#######
# Verifier s'il s'agit d'un document à envoyer avec une version de pièce jointe.
if ("joint_pdf" in partner_document_QUOTATION_REMIND_data.keys() and str(partner_document_QUOTATION_REMIND_data['joint_pdf']) == "1"):
# Il s'agit bien d'un envoie avec 'contenu_doc' en pièce jointe PDF
"""
1 - Creation du PDF
"""
# print(" #### Order_header_data = ", Order_header_data)
Order_header_data['order_header_type'] = str(Order_header_data['order_header_type']).capitalize()
sourceHtml = contenu_doc_Template.render(params=Order_header_data, param_order_lines=Order_header_lines_data)
sujetHtml = str(Order_header_data['order_header_type']) + " : " + str(
Order_header_data['order_header_ref_interne'])
new_model_courrier_with_code_tag = str(
sourceHtml) + " <p style='width: 300px; text-align: right;'> Signature Client <br/> <img style='height:150px; width:150px' src='{{ params.mysy_manual_signature_img }}'>&nbsp;</p> <br/> " \
" <p style='width: 300px; text-align: center;'> <img style='height:150px; width:150px;' src='{{ params.mysy_qrcode_securite }}'>&nbsp;</p> "
contenu_doc_Template = jinja2.Template(str(partner_document_QUOTATION_REMIND_data['contenu_doc']))
todays_date = str(date.today().strftime("%d_%m_%Y"))
ts = datetime.now().timestamp()
ts = str(ts).replace(".", "").replace(",", "")[-2:]
#sourceHtml = contenu_doc_Template.render(params=body["params"])
orig_file_name = "Devis_" + str(my_partner['recid'])[0:5] + "_" + str(todays_date) + "_" + str(ts) + ".pdf"
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
###
# print(" #### Order_header_data = ", Order_header_data)
Order_header_data['order_header_type'] = str(Order_header_data['order_header_type']).capitalize()
sourceHtml = contenu_doc_Template.render(params=Order_header_data,
param_order_lines=Order_header_lines_data)
sujet_doc_Template = jinja2.Template(str(partner_document_QUOTATION_REMIND_data['sujet']))
sujetHtml = sujet_doc_Template.render(params=Order_header_data)
###
todays_date = str(date.today().strftime("%d/%m/%Y"))
ts = datetime.now().timestamp()
ts = str(ts).replace(".", "").replace(",", "")[-5:]
orig_file_name = "Devis_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
outputFilename = str(MYSY_GV.TEMPORARY_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()
# Attachement du fichier joint
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
file_to_attache_to_mail.set_payload(open(outputFilename, "rb").read())
encoders.encode_base64(file_to_attache_to_mail)
file_to_attache_to_mail.add_header('Content-Disposition',
'attachment; filename="{0}"'.format(
os.path.basename(outputFilename)))
new_node = {"attached_file": file_to_attache_to_mail}
tab_files_to_attache_to_mail.append(new_node)
## Creation du mail au format email
corps_mail_Template = jinja2.Template(str(partner_document_QUOTATION_REMIND_data['corps_mail']))
sourceHtml = corps_mail_Template.render(params=body["params"])
html_mime = MIMEText(sourceHtml, 'html')
# Creation de l'email à enoyer
msg = MIMEMultipart("alternative")
# 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()
"""
Recuperation des parametre SMTP du partner si le client a decidé d'utiliser son propre smpt
@ -6706,8 +6802,9 @@ def Send_Quotation_Remind_Level1(diction):
if (str(partner_own_smtp_value) == "1"):
print("debut envoi mail de test ")
msg = EmailMessage()
msg.set_content(sourceHtml, subtype='html')
#msg = EmailMessage()
msg = MIMEMultipart("alternative")
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
"""
@ -6715,28 +6812,18 @@ def Send_Quotation_Remind_Level1(diction):
Si ce champ est vide alors on regarde si il y a un email sur la fiche client.
"""
client_main_mail_tmp = ""
if ("order_header_email_client" in Order_header_data.keys() and Order_header_data[
'order_header_email_client']):
client_main_mail_tmp = str(Order_header_data['order_header_email_client'])
if (mycommon.isEmailValide(client_main_mail_tmp) is True):
msg['To'] = client_main_mail_tmp
else:
mycommon.myprint(str(inspect.stack()[0][
3]) + " - L'adresse email sur la commande n'est pas valide ")
return False, " L'adresse email sur la commande n'est pas valide "
else:
mycommon.myprint(str(inspect.stack()[0][
3]) + " - Aucune adresse email sur la commande ")
return False, " Aucune adresse email sur la commande "
msg.attach(html_mime)
msg['From'] = partner_SMTP_COUNT_From_User
msg['Bcc'] = 'contact@mysy-training.com'
msg['Subject'] = sujetHtml
toaddrs = ", ".join(tab_emails_destinataire)
msg['to'] = str(toaddrs)
# Attacher l'eventuelle pièces jointes
for myfile in tab_files_to_attache_to_mail:
msg.attach(myfile['attached_file'])
smtpserver.ehlo()
smtpserver.starttls()
@ -6750,37 +6837,22 @@ def Send_Quotation_Remind_Level1(diction):
else:
print("debut envoi mail de test ")
msg = EmailMessage()
msg.set_content(sourceHtml, subtype='html')
#msg = EmailMessage()
msg = MIMEMultipart("alternative")
msg.attach(html_mime)
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
"""
La commande est envoyée à l'adresse email qui se trouve sur la commande, le champ : 'order_header_email_client'.
Si ce champ est vide alors on regarde si il y a un email sur la fiche client.
"""
client_main_mail_tmp = ""
if ("order_header_email_client" in Order_header_data.keys() and Order_header_data[
'order_header_email_client']):
client_main_mail_tmp = str(Order_header_data['order_header_email_client'])
if (mycommon.isEmailValide(client_main_mail_tmp) is True):
msg['To'] = client_main_mail_tmp
else:
mycommon.myprint(str(inspect.stack()[0][
3]) + " - L'adresse email sur la commande n'est pas valide ")
return False, " L'adresse email sur la commande n'est pas valide "
else:
mycommon.myprint(str(inspect.stack()[0][
3]) + " - Aucune adresse email sur la commande ")
return False, " Aucune adresse email sur la commande "
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
msg['Bcc'] = 'contact@mysy-training.com'
msg['Subject'] = sujetHtml
toaddrs = ", ".join(tab_emails_destinataire)
msg['to'] = str(toaddrs)
# Attacher l'eventuelle pièces jointes
for myfile in tab_files_to_attache_to_mail:
msg.attach(myfile['attached_file'])
smtpserver.ehlo()
smtpserver.starttls()
@ -6790,25 +6862,7 @@ def Send_Quotation_Remind_Level1(diction):
print(" Email envoyé " + str(val))
"""
Mettre à jour la commande /devis pour dire que quand le document a été envoyé
"""
updata_data = {}
updata_data['date_update'] = str(datetime.now())
updata_data['update_by'] = str(my_partner['recid'])
updata_data['date_envoi_quotation'] = str(datetime.now())
todays_date = str(date.today().strftime("%d/%m/%Y"))
updata_data['date_dernier_relance_auto'] = str(todays_date)
MYSY_GV.dbname['partner_order_header'].find_one_and_update(
{'_id': ObjectId(str(Order_header_data['_id'])),
'partner_owner_recid': str(Order_header_data['partner_owner_recid'])},
{'$set': updata_data})
return True, " Relance envoyé à : '" + str(client_main_mail_tmp) + "' "
return True, " Relance envoyé à : '" + str(toaddrs) + "' "
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()

View File

@ -4780,7 +4780,7 @@ def Get_Dictionnary_data_For_Template(diction):
list_apprenant_data.append(new_apprenant_data)
print(" ### APPEND new_apprenant_data = ", new_apprenant_data)
#print(" ### APPEND new_apprenant_data = ", new_apprenant_data)
dictionnary_data['list_apprenant_data'] = list_apprenant_data