13/09/2023 - 18h
parent
3ab74ee2fe
commit
a9e355b762
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="11/09/23 - 19h">
|
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="12/09/2023 - 18h">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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$/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$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||||
|
@ -69,13 +69,6 @@
|
||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1680804787304</updated>
|
<updated>1680804787304</updated>
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00054" summary="28/07/23 - 19h">
|
|
||||||
<created>1690566255685</created>
|
|
||||||
<option name="number" value="00054" />
|
|
||||||
<option name="presentableId" value="LOCAL-00054" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1690566255686</updated>
|
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00055" summary="29/07/23 - 29h">
|
<task id="LOCAL-00055" summary="29/07/23 - 29h">
|
||||||
<created>1690661811531</created>
|
<created>1690661811531</created>
|
||||||
<option name="number" value="00055" />
|
<option name="number" value="00055" />
|
||||||
|
@ -412,7 +405,14 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1694451732113</updated>
|
<updated>1694451732113</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="103" />
|
<task id="LOCAL-00103" summary="12/09/2023 - 18h">
|
||||||
|
<created>1694533712540</created>
|
||||||
|
<option name="number" value="00103" />
|
||||||
|
<option name="presentableId" value="LOCAL-00103" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1694533712541</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="104" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
@ -427,7 +427,6 @@
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="21/08/23 - 21h" />
|
|
||||||
<MESSAGE value="22/08/23 - 13h" />
|
<MESSAGE value="22/08/23 - 13h" />
|
||||||
<MESSAGE value="22/08/23 - 20h" />
|
<MESSAGE value="22/08/23 - 20h" />
|
||||||
<MESSAGE value="23/08/23 - 20h" />
|
<MESSAGE value="23/08/23 - 20h" />
|
||||||
|
@ -452,6 +451,7 @@
|
||||||
<MESSAGE value="08/09/2023 - 18h30" />
|
<MESSAGE value="08/09/2023 - 18h30" />
|
||||||
<MESSAGE value="11/09/23 - 12h30" />
|
<MESSAGE value="11/09/23 - 12h30" />
|
||||||
<MESSAGE value="11/09/23 - 19h" />
|
<MESSAGE value="11/09/23 - 19h" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="11/09/23 - 19h" />
|
<MESSAGE value="12/09/2023 - 18h" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="12/09/2023 - 18h" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
1471
Log/log_file.log
1471
Log/log_file.log
File diff suppressed because it is too large
Load Diff
15
main.py
15
main.py
|
@ -1530,6 +1530,9 @@ def GetCustomerInvoice(invoiceid, token):
|
||||||
print(" ### payload facture = ", str(invoiceid), " token = ",str(token))
|
print(" ### payload facture = ", str(invoiceid), " token = ",str(token))
|
||||||
return factures.GetCustomerInvoice(payload)
|
return factures.GetCustomerInvoice(payload)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
API de facturation automatique des commandes
|
API de facturation automatique des commandes
|
||||||
"""
|
"""
|
||||||
|
@ -4521,6 +4524,18 @@ def GerneratePDF_Partner_Order(token, order_id):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
API qui envoie un partner_order par email au client
|
||||||
|
"""
|
||||||
|
@app.route('/myclass/api/Send_Partner_Order_By_Email/', methods=['GET','POST'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def Send_Partner_Order_By_Email():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||||
|
print(" ### Send_Partner_Order_By_Email payload = ", str(payload))
|
||||||
|
status, message = partner_order.Send_Partner_Order_By_Email(payload)
|
||||||
|
return jsonify(status=status, message=message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
401
partner_order.py
401
partner_order.py
|
@ -33,6 +33,14 @@ import email_mgt as email
|
||||||
import jinja2
|
import jinja2
|
||||||
from flask import send_file
|
from flask import send_file
|
||||||
from xhtml2pdf import pisa
|
from xhtml2pdf import pisa
|
||||||
|
from email.message import EmailMessage
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from email import encoders
|
||||||
|
import smtplib
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from email.mime.base import MIMEBase
|
||||||
|
from email import encoders
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Creation d'un commande client d'un partenaire
|
Creation d'un commande client d'un partenaire
|
||||||
|
@ -2703,7 +2711,7 @@ def Get_Given_Partner_Order_Lines_From_order_ref_interne(diction):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
print("#### Get_Given_Partner_Order_Lines_From_order_ref_interne : query pip= ", query)
|
#print("#### Get_Given_Partner_Order_Lines_From_order_ref_interne : query pip= ", query)
|
||||||
|
|
||||||
for retval in MYSY_GV.dbname['partner_order_line'].aggregate(query):
|
for retval in MYSY_GV.dbname['partner_order_line'].aggregate(query):
|
||||||
if ('myclass_collection' in retval.keys() and len(retval['myclass_collection']) > 0):
|
if ('myclass_collection' in retval.keys() and len(retval['myclass_collection']) > 0):
|
||||||
|
@ -3604,7 +3612,7 @@ def GerneratePDF_Partner_Order(diction):
|
||||||
if val not in field_list:
|
if val not in field_list:
|
||||||
mycommon.myprint(
|
mycommon.myprint(
|
||||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
return False, " Impossible d'imprimer la liste d'emargement"
|
return False, " Les informations fournies sont incorrectes"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Verification de la liste des champs obligatoires
|
Verification de la liste des champs obligatoires
|
||||||
|
@ -3615,7 +3623,7 @@ def GerneratePDF_Partner_Order(diction):
|
||||||
if val not in diction:
|
if val not in diction:
|
||||||
mycommon.myprint(
|
mycommon.myprint(
|
||||||
str(inspect.stack()[0][3]) + " - : La valeur '" + val + "' n'est pas presente dans liste ")
|
str(inspect.stack()[0][3]) + " - : La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
return False, " Impossible d'imprimer la liste d'emargement"
|
return False, "Les informations fournies sont incorrectes"
|
||||||
|
|
||||||
query_get_data = {}
|
query_get_data = {}
|
||||||
mytoken = ""
|
mytoken = ""
|
||||||
|
@ -3648,18 +3656,18 @@ def GerneratePDF_Partner_Order(diction):
|
||||||
my_partner['recid'])})
|
my_partner['recid'])})
|
||||||
|
|
||||||
partner_document_CONF_ORDER_data_qry = {'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'}
|
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER', 'type_doc':'pdf'}
|
||||||
|
|
||||||
print(" ### partner_document_CONF_ORDER_data_qry = ", partner_document_CONF_ORDER_data_qry)
|
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_CONF_ORDER_data = MYSY_GV.dbname['courrier_template'].find_one(
|
||||||
{'partner_owner_recid': str(my_partner['recid']),
|
{'partner_owner_recid': str(my_partner['recid']),
|
||||||
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER'})
|
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER', 'type_doc':'pdf'})
|
||||||
|
|
||||||
if (partner_document_CONF_ORDER_data is None):
|
if (partner_document_CONF_ORDER_data is None):
|
||||||
# Il n'existe pas de personnalisation de la preinscription pour ce partenaire, on va aller recuperer la presinscription pa defaut
|
# Il n'existe pas de personnalisation de la preinscription pour ce partenaire, on va aller recuperer la presinscription pa defaut
|
||||||
partner_document_CONF_ORDER_data = MYSY_GV.dbname['courrier_template'].find_one(
|
partner_document_CONF_ORDER_data = MYSY_GV.dbname['courrier_template'].find_one(
|
||||||
{'partner_owner_recid': 'default',
|
{'partner_owner_recid': 'default',
|
||||||
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER'})
|
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER', 'type_doc':'pdf'})
|
||||||
|
|
||||||
if (partner_document_CONF_ORDER_data is None):
|
if (partner_document_CONF_ORDER_data is None):
|
||||||
mycommon.myprint(
|
mycommon.myprint(
|
||||||
|
@ -3673,10 +3681,139 @@ def GerneratePDF_Partner_Order(diction):
|
||||||
3]) + " - Le parametrage du document est invalide")
|
3]) + " - Le parametrage du document est invalide")
|
||||||
return False, " Le parametrage du document est invalide "
|
return False, " Le parametrage du document est invalide "
|
||||||
|
|
||||||
|
# Recuperation des données du client
|
||||||
|
if ("order_header_client_id" in Order_header_data.keys()):
|
||||||
|
Order_header_client_data = MYSY_GV.dbname['partner_client'].find_one(
|
||||||
|
{'_id': ObjectId(str(Order_header_data['order_header_client_id'])),
|
||||||
|
'partner_recid': str(my_partner['recid']), 'valide': '1', 'locked': '0'})
|
||||||
|
|
||||||
|
if (Order_header_client_data is None):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " - Le client est invalide")
|
||||||
|
return False, " Le client est invalide"
|
||||||
|
|
||||||
|
# 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'])}
|
||||||
|
|
||||||
|
query = [{'$match': {'$and': [filt_order_header_order_id,
|
||||||
|
{'partner_owner_recid': str(my_partner['recid'])}]}},
|
||||||
|
{'$lookup':
|
||||||
|
{
|
||||||
|
'from': 'myclass',
|
||||||
|
'localField': 'order_line_formation',
|
||||||
|
'foreignField': 'internal_url',
|
||||||
|
'pipeline': [{'$match': {'$and': [filt_class_partner_recid]}},
|
||||||
|
{'$project': {'title': 1, 'domaine': 1,
|
||||||
|
'duration': 1,
|
||||||
|
'duration_unit': 1}}],
|
||||||
|
'as': 'myclass_collection'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
#print("#### Get_Given_Partner_Order_Lines_From_order_ref_interne : query pip= ", query)
|
||||||
|
val_tmp = 0
|
||||||
|
Order_header_lines_data = []
|
||||||
|
for retval in MYSY_GV.dbname['partner_order_line'].aggregate(query):
|
||||||
|
if ('myclass_collection' in retval.keys() and len(retval['myclass_collection']) > 0):
|
||||||
|
user = {}
|
||||||
|
user['id'] = str(val_tmp)
|
||||||
|
val_tmp = val_tmp + 1
|
||||||
|
user['_id'] = retval['_id']
|
||||||
|
user['order_line_formation'] = retval['order_line_formation']
|
||||||
|
user['order_line_qty'] = retval['order_line_qty']
|
||||||
|
user['order_line_prix_unitaire'] = retval['order_line_prix_unitaire']
|
||||||
|
user['order_header_id'] = retval['order_header_id']
|
||||||
|
user['order_header_ref_interne'] = retval['order_header_ref_interne']
|
||||||
|
user['valide'] = retval['valide']
|
||||||
|
user['locked'] = retval['locked']
|
||||||
|
|
||||||
|
if ("order_line_montant_reduction" in retval.keys()):
|
||||||
|
user['order_line_montant_reduction'] = retval['order_line_montant_reduction']
|
||||||
|
else:
|
||||||
|
user['order_line_montant_reduction'] = "0"
|
||||||
|
|
||||||
|
if ("order_line_montant_toutes_taxes" in retval.keys()):
|
||||||
|
user['order_line_montant_toutes_taxes'] = retval['order_line_montant_toutes_taxes']
|
||||||
|
else:
|
||||||
|
user['order_line_montant_toutes_taxes'] = "0"
|
||||||
|
|
||||||
|
if ("order_line_tax" in retval.keys()):
|
||||||
|
user['order_line_tax'] = retval['order_line_tax']
|
||||||
|
else:
|
||||||
|
user['order_line_tax'] = ""
|
||||||
|
|
||||||
|
if ("order_line_tax_amount" in retval.keys()):
|
||||||
|
user['order_line_tax_amount'] = retval['order_line_tax_amount']
|
||||||
|
else:
|
||||||
|
user['order_line_tax_amount'] = "0"
|
||||||
|
|
||||||
|
if ("order_line_type_reduction" in retval.keys()):
|
||||||
|
user['order_line_type_reduction'] = retval['order_line_type_reduction']
|
||||||
|
else:
|
||||||
|
user['order_line_montant_reduction'] = ""
|
||||||
|
|
||||||
|
if ("order_line_type_valeur" in retval.keys()):
|
||||||
|
user['order_line_type_valeur'] = retval['order_line_type_valeur']
|
||||||
|
else:
|
||||||
|
user['order_line_type_valeur'] = "0"
|
||||||
|
|
||||||
|
if ("order_line_montant_hors_taxes" in retval.keys()):
|
||||||
|
user['order_line_montant_hors_taxes'] = retval['order_line_montant_hors_taxes']
|
||||||
|
else:
|
||||||
|
user['order_line_montant_hors_taxes'] = "0"
|
||||||
|
|
||||||
|
user['date_update'] = retval['date_update']
|
||||||
|
user['partner_owner_recid'] = retval['partner_owner_recid']
|
||||||
|
user['order_line_type'] = retval['order_line_type']
|
||||||
|
user['order_line_status'] = retval['order_line_status']
|
||||||
|
if ("order_line_comment" in retval.keys()):
|
||||||
|
user['order_line_comment'] = retval['order_line_comment']
|
||||||
|
else:
|
||||||
|
user['order_line_comment'] = ""
|
||||||
|
|
||||||
|
user['title'] = retval['myclass_collection'][0]['title']
|
||||||
|
user['domaine'] = retval['myclass_collection'][0]['domaine']
|
||||||
|
user['duration'] = retval['myclass_collection'][0]['duration']
|
||||||
|
user['duration_unit'] = retval['myclass_collection'][0]['duration_unit']
|
||||||
|
|
||||||
|
if (str(retval['myclass_collection'][0]['duration_unit']) == "heure"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " h"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "jour"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " j"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "semaine"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " s"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "mois"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " m"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "annee"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " a"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "user_rythme"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " u"
|
||||||
|
|
||||||
|
else:
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " ?"
|
||||||
|
|
||||||
|
Order_header_lines_data.append(user)
|
||||||
|
|
||||||
|
if (len(Order_header_lines_data) <= 0):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " - Aucune ligne de détail pour cette commande ")
|
||||||
|
return False, " Aucune ligne de détail pour cette commande "
|
||||||
|
|
||||||
|
#print(" ### Order_header_lines_data = ", Order_header_lines_data)
|
||||||
|
|
||||||
|
|
||||||
contenu_doc_Template = jinja2.Template(str(partner_document_CONF_ORDER_data['contenu_doc']))
|
contenu_doc_Template = jinja2.Template(str(partner_document_CONF_ORDER_data['contenu_doc']))
|
||||||
|
|
||||||
print(" #### Order_header_data = ", Order_header_data)
|
#print(" #### Order_header_data = ", Order_header_data)
|
||||||
sourceHtml = contenu_doc_Template.render(params=Order_header_data)
|
#sourceHtml = contenu_doc_Template.render(params=Order_header_data)
|
||||||
|
sourceHtml = contenu_doc_Template.render(params=Order_header_data, param_order_lines=Order_header_lines_data)
|
||||||
|
|
||||||
|
|
||||||
orig_file_name = "Part_Order_"+str(Order_header_data['order_header_ref_interne'])+".pdf"
|
orig_file_name = "Part_Order_"+str(Order_header_data['order_header_ref_interne'])+".pdf"
|
||||||
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) +"/"+ str(orig_file_name)
|
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) +"/"+ str(orig_file_name)
|
||||||
|
@ -3709,4 +3846,252 @@ def GerneratePDF_Partner_Order(diction):
|
||||||
return False, False
|
return False, False
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Envoie de la commande par email
|
||||||
|
"""
|
||||||
|
def Send_Partner_Order_By_Email(diction):
|
||||||
|
try:
|
||||||
|
field_list = ['order_id', 'token', ]
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list:
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
|
return False, "Les informations fournies sont incorrectes"
|
||||||
|
|
||||||
|
"""
|
||||||
|
Verification de la liste des champs obligatoires
|
||||||
|
"""
|
||||||
|
field_list_obligatoire = ['order_id', 'token', ]
|
||||||
|
|
||||||
|
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, " Les informations fournies sont incorrectes "
|
||||||
|
|
||||||
|
query_get_data = {}
|
||||||
|
mytoken = ""
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
mytoken = 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
|
||||||
|
|
||||||
|
# Verification de la validité de l'order
|
||||||
|
qry = {'_id': ObjectId(str(diction['order_id'])), 'valide': '1', 'locked': '0',
|
||||||
|
'partner_owner_recid': str(my_partner['recid'])}
|
||||||
|
print(" ### qry = ", qry)
|
||||||
|
|
||||||
|
is_Order_Existe_Count = MYSY_GV.dbname['partner_order_header'].count_documents(
|
||||||
|
{'_id': ObjectId(str(diction['order_id'])),
|
||||||
|
'valide': '1', 'locked': '0',
|
||||||
|
'partner_owner_recid': str(my_partner['recid'])})
|
||||||
|
|
||||||
|
if (is_Order_Existe_Count != 1):
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " - La commande n'est pas valide ")
|
||||||
|
return False, " La commande n'est pas valide",
|
||||||
|
|
||||||
|
Order_header_data = MYSY_GV.dbname['partner_order_header'].find_one({'_id': ObjectId(str(diction['order_id'])),
|
||||||
|
'valide': '1', 'locked': '0',
|
||||||
|
'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'}
|
||||||
|
|
||||||
|
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_owner_recid': str(my_partner['recid']),
|
||||||
|
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER', 'type_doc':'email'})
|
||||||
|
|
||||||
|
if (partner_document_CONF_ORDER_data is None):
|
||||||
|
# Il n'existe pas de personnalisation de la preinscription pour ce partenaire, on va aller recuperer la presinscription pa defaut
|
||||||
|
partner_document_CONF_ORDER_data = MYSY_GV.dbname['courrier_template'].find_one(
|
||||||
|
{'partner_owner_recid': 'default',
|
||||||
|
'valide': '1', 'locked': '0', 'ref_interne': 'PART_ORDER', 'type_doc':'email'})
|
||||||
|
|
||||||
|
if (partner_document_CONF_ORDER_data is None):
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][
|
||||||
|
3]) + "Aucun document parametré ")
|
||||||
|
return False, "Aucun document parametré "
|
||||||
|
|
||||||
|
if ("contenu_doc" not in partner_document_CONF_ORDER_data or len(
|
||||||
|
str(partner_document_CONF_ORDER_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 "
|
||||||
|
|
||||||
|
|
||||||
|
# Recuperation des données du client
|
||||||
|
if( "order_header_client_id" in Order_header_data.keys() ):
|
||||||
|
Order_header_client_data = MYSY_GV.dbname['partner_client'].find_one({'_id':ObjectId(str(Order_header_data['order_header_client_id'])),
|
||||||
|
'partner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'})
|
||||||
|
|
||||||
|
if( Order_header_client_data is None):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " - Le client est invalide")
|
||||||
|
return False, " Le client est invalide"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 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'])}
|
||||||
|
|
||||||
|
query = [{'$match': {'$and': [filt_order_header_order_id,
|
||||||
|
{'partner_owner_recid': str(my_partner['recid'])}]}},
|
||||||
|
{'$lookup':
|
||||||
|
{
|
||||||
|
'from': 'myclass',
|
||||||
|
'localField': 'order_line_formation',
|
||||||
|
'foreignField': 'internal_url',
|
||||||
|
'pipeline': [{'$match': {'$and': [filt_class_partner_recid]}},
|
||||||
|
{'$project': {'title': 1, 'domaine': 1,
|
||||||
|
'duration': 1,
|
||||||
|
'duration_unit': 1}}],
|
||||||
|
'as': 'myclass_collection'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
#print("#### Get_Given_Partner_Order_Lines_From_order_ref_interne : query pip= ", query)
|
||||||
|
val_tmp = 0
|
||||||
|
Order_header_lines_data = []
|
||||||
|
for retval in MYSY_GV.dbname['partner_order_line'].aggregate(query):
|
||||||
|
if ('myclass_collection' in retval.keys() and len(retval['myclass_collection']) > 0):
|
||||||
|
user = {}
|
||||||
|
user['id'] = str(val_tmp)
|
||||||
|
val_tmp = val_tmp + 1
|
||||||
|
user['_id'] = retval['_id']
|
||||||
|
user['order_line_formation'] = retval['order_line_formation']
|
||||||
|
user['order_line_qty'] = retval['order_line_qty']
|
||||||
|
user['order_line_prix_unitaire'] = retval['order_line_prix_unitaire']
|
||||||
|
user['order_header_id'] = retval['order_header_id']
|
||||||
|
user['order_header_ref_interne'] = retval['order_header_ref_interne']
|
||||||
|
user['valide'] = retval['valide']
|
||||||
|
user['locked'] = retval['locked']
|
||||||
|
|
||||||
|
if ("order_line_montant_reduction" in retval.keys()):
|
||||||
|
user['order_line_montant_reduction'] = retval['order_line_montant_reduction']
|
||||||
|
else:
|
||||||
|
user['order_line_montant_reduction'] = "0"
|
||||||
|
|
||||||
|
if ("order_line_montant_toutes_taxes" in retval.keys()):
|
||||||
|
user['order_line_montant_toutes_taxes'] = retval['order_line_montant_toutes_taxes']
|
||||||
|
else:
|
||||||
|
user['order_line_montant_toutes_taxes'] = "0"
|
||||||
|
|
||||||
|
if ("order_line_tax" in retval.keys()):
|
||||||
|
user['order_line_tax'] = retval['order_line_tax']
|
||||||
|
else:
|
||||||
|
user['order_line_tax'] = ""
|
||||||
|
|
||||||
|
if ("order_line_tax_amount" in retval.keys()):
|
||||||
|
user['order_line_tax_amount'] = retval['order_line_tax_amount']
|
||||||
|
else:
|
||||||
|
user['order_line_tax_amount'] = "0"
|
||||||
|
|
||||||
|
if ("order_line_type_reduction" in retval.keys()):
|
||||||
|
user['order_line_type_reduction'] = retval['order_line_type_reduction']
|
||||||
|
else:
|
||||||
|
user['order_line_montant_reduction'] = ""
|
||||||
|
|
||||||
|
if ("order_line_type_valeur" in retval.keys()):
|
||||||
|
user['order_line_type_valeur'] = retval['order_line_type_valeur']
|
||||||
|
else:
|
||||||
|
user['order_line_type_valeur'] = "0"
|
||||||
|
|
||||||
|
if ("order_line_montant_hors_taxes" in retval.keys()):
|
||||||
|
user['order_line_montant_hors_taxes'] = retval['order_line_montant_hors_taxes']
|
||||||
|
else:
|
||||||
|
user['order_line_montant_hors_taxes'] = "0"
|
||||||
|
|
||||||
|
user['date_update'] = retval['date_update']
|
||||||
|
user['partner_owner_recid'] = retval['partner_owner_recid']
|
||||||
|
user['order_line_type'] = retval['order_line_type']
|
||||||
|
user['order_line_status'] = retval['order_line_status']
|
||||||
|
if ("order_line_comment" in retval.keys()):
|
||||||
|
user['order_line_comment'] = retval['order_line_comment']
|
||||||
|
else:
|
||||||
|
user['order_line_comment'] = ""
|
||||||
|
|
||||||
|
user['title'] = retval['myclass_collection'][0]['title']
|
||||||
|
user['domaine'] = retval['myclass_collection'][0]['domaine']
|
||||||
|
user['duration'] = retval['myclass_collection'][0]['duration']
|
||||||
|
user['duration_unit'] = retval['myclass_collection'][0]['duration_unit']
|
||||||
|
|
||||||
|
if (str(retval['myclass_collection'][0]['duration_unit']) == "heure"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " h"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "jour"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " j"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "semaine"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " s"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "mois"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " m"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "annee"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " a"
|
||||||
|
|
||||||
|
elif (str(retval['myclass_collection'][0]['duration_unit']) == "user_rythme"):
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " u"
|
||||||
|
|
||||||
|
else:
|
||||||
|
user['duration_concat'] = str(retval['myclass_collection'][0]['duration']) + " ?"
|
||||||
|
|
||||||
|
Order_header_lines_data.append(user)
|
||||||
|
|
||||||
|
|
||||||
|
if(len(Order_header_lines_data) <= 0 ):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " - Aucune ligne de détail pour cette commande ")
|
||||||
|
return False, " Aucune ligne de détail pour cette commande "
|
||||||
|
|
||||||
|
|
||||||
|
#print(" ### Order_header_lines_data = ", Order_header_lines_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
contenu_doc_Template = jinja2.Template(str(partner_document_CONF_ORDER_data['contenu_doc']))
|
||||||
|
|
||||||
|
contenu_doc_Template_subject = jinja2.Template(str(partner_document_CONF_ORDER_data['sujet']))
|
||||||
|
|
||||||
|
#print(" #### Order_header_data = ", Order_header_data)
|
||||||
|
sourceHtml = contenu_doc_Template.render(params=Order_header_data, param_order_lines=Order_header_lines_data)
|
||||||
|
sujetHtml = contenu_doc_Template_subject.render(params=Order_header_data)
|
||||||
|
|
||||||
|
print(" #### sourceHtml = ", sourceHtml)
|
||||||
|
|
||||||
|
|
||||||
|
print("debut envoi mail de test ")
|
||||||
|
msg = EmailMessage()
|
||||||
|
msg.set_content(sourceHtml, subtype='html')
|
||||||
|
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['Bcc'] = 'contact@mysy-training.com'
|
||||||
|
msg['Subject'] = sujetHtml
|
||||||
|
msg['To'] = "billardman01@hotmail.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))
|
||||||
|
|
||||||
|
|
||||||
|
return True, " L'email a été correctement envoyé "
|
||||||
|
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 l'email"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue