0dfd
parent
a62a8e5062
commit
66e3b89695
|
@ -1,11 +1,15 @@
|
|||
<?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="08/05/2024 - 17h30">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="08/05/2024 - 21h30">
|
||||
<change afterPath="$PROJECT_DIR$/Job_Cron.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Dashbord_queries/factures_tbd_qries.py" beforeDir="false" afterPath="$PROJECT_DIR$/Dashbord_queries/factures_tbd_qries.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.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$/Session_Formation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/module_editique.py" beforeDir="false" afterPath="$PROJECT_DIR$/module_editique.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/survey_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/survey_mgt.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -75,13 +79,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00241" summary="10/03/24 - 21h">
|
||||
<created>1710101347415</created>
|
||||
<option name="number" value="00241" />
|
||||
<option name="presentableId" value="LOCAL-00241" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1710101347417</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00242" summary="11/03/2024 - 15h">
|
||||
<created>1710165434009</created>
|
||||
<option name="number" value="00242" />
|
||||
|
@ -418,7 +415,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1715182713802</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="290" />
|
||||
<task id="LOCAL-00290" summary="08/05/2024 - 21h30">
|
||||
<created>1715196233243</created>
|
||||
<option name="number" value="00290" />
|
||||
<option name="presentableId" value="LOCAL-00290" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1715196233246</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="291" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -460,7 +464,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="09/04/2024 - 23h50" />
|
||||
<MESSAGE value="10/04/2024 - 11h50" />
|
||||
<MESSAGE value="10/04/2024 - 22h50" />
|
||||
<MESSAGE value="11/04/2024 - 17h02" />
|
||||
|
@ -485,6 +488,7 @@
|
|||
<MESSAGE value="06/05/2024 - 22h30" />
|
||||
<MESSAGE value="07/05/2024 - 17h30" />
|
||||
<MESSAGE value="08/05/2024 - 17h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="08/05/2024 - 17h30" />
|
||||
<MESSAGE value="08/05/2024 - 21h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="08/05/2024 - 21h30" />
|
||||
</component>
|
||||
</project>
|
|
@ -1112,7 +1112,464 @@ def TBD_FACTURE_01_Export_Dashbord_To_Excel(diction):
|
|||
return False, " Impossible d'exporter les données "
|
||||
|
||||
|
||||
"""
|
||||
Recuperation du chiffre d'affaire previsionnelle sur une période donnée
|
||||
"""
|
||||
|
||||
def Get_Qery_List_Facture_Previsionnelle_Data_By_Periode_save(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'periode_start_date', 'periode_end_date', 'filter_value', 'filter_client_id' ]
|
||||
|
||||
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'existe pas")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['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",
|
||||
|
||||
"""
|
||||
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
|
||||
|
||||
filt_client_id = {}
|
||||
if ("filter_client_id" in diction.keys() and diction['filter_client_id']):
|
||||
filt_client_id = {'order_header_client_id': str(diction['filter_client_id'])}
|
||||
|
||||
|
||||
filt_periode_start_date = ""
|
||||
if ("periode_start_date" in diction.keys() and diction['periode_start_date']):
|
||||
filt_periode_start_date = str(diction['periode_start_date'])[0:10]
|
||||
local_status = mycommon.CheckisDate(filt_periode_start_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le filtre : 'date de debut' n'est pas au format jj/mm/aaaa.")
|
||||
return False, " Le filtre : 'date de debut' n'est pas au format jj/mm/aaaa."
|
||||
|
||||
filt_periode_end_date = ""
|
||||
if ("periode_end_date" in diction.keys() and diction['periode_end_date']):
|
||||
filt_periode_end_date = str(diction['periode_end_date'])[0:10]
|
||||
local_status = mycommon.CheckisDate(filt_periode_end_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa.")
|
||||
return False, " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa."
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Si la valeur de 'filter_value' est m0 ou m1, on va aller recuperer les date du mois correspondant.
|
||||
On ecrase les valeur de filt_session_start_date et filt_session_end_date
|
||||
"""
|
||||
if ('filter_value' in diction.keys()):
|
||||
# print(" filter_value = ", diction['filter_value'])
|
||||
if (str(diction['filter_value']) == "m0"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_periode_start_date = start_current_month_date
|
||||
filt_periode_end_date = end_current_month_date
|
||||
|
||||
# print(" ### filt_session_start_date = ", filt_session_start_date, " ### filt_session_end_date = ", filt_session_end_date)
|
||||
|
||||
elif (str(diction['filter_value']) == "m1"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_periode_start_date = start_current_month_date
|
||||
filt_periode_end_date = end_current_month_date
|
||||
|
||||
|
||||
|
||||
filt_periode_start_date_ISODATE = datetime.strptime(str(filt_periode_start_date), '%d/%m/%Y')
|
||||
filt_periode_end_date_ISODATE = datetime.strptime(str(filt_periode_end_date), '%d/%m/%Y')
|
||||
|
||||
|
||||
"""
|
||||
Creation de la range des mois entre filt_periode_start_date_ISODATE et
|
||||
filt_periode_end_date_ISODATE
|
||||
"""
|
||||
range_date_month = []
|
||||
start = filt_periode_start_date_ISODATE
|
||||
end = filt_periode_end_date_ISODATE
|
||||
while start <= end:
|
||||
node = {}
|
||||
node['month_year'] = '{:02d}'.format(start.month) +"_"+str(start.year)
|
||||
node['label'] = '{:02d}'.format(start.month) + "_" + str(start.year)
|
||||
node['TotalAmount'] = 0
|
||||
node['value'] = 0
|
||||
node['count'] = 0
|
||||
|
||||
range_date_month.append(node)
|
||||
start += relativedelta(months=1)
|
||||
|
||||
|
||||
print(" ### range_date_month = ", range_date_month)
|
||||
|
||||
|
||||
|
||||
qery_match = {'$and': [{"partner_owner_recid": str(my_partner['recid'])},
|
||||
{"valide": '1'},filt_client_id,
|
||||
|
||||
{
|
||||
'mysy_invoice_date': {'$gte': filt_periode_start_date_ISODATE,
|
||||
'$lte': filt_periode_end_date_ISODATE}}, ]}
|
||||
|
||||
pipe_qry = ([
|
||||
{"$addFields": {
|
||||
"mysy_invoice_date": {
|
||||
'$dateFromString': {
|
||||
'dateString': '$invoice_date',
|
||||
'format': "%d/%m/%Y"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
{'$match': qery_match},
|
||||
{'$lookup': {
|
||||
'from': 'partner_client',
|
||||
"let": {'order_header_client_id': "$order_header_client_id", 'partner_owner_recid': '$partner_owner_recid'},
|
||||
'pipeline': [
|
||||
{'$match':
|
||||
{'$expr':
|
||||
{'$and':
|
||||
[
|
||||
|
||||
{'$eq': ["$_id", {'$convert': {
|
||||
'input': "$$order_header_client_id",
|
||||
'to': "objectId",
|
||||
'onError': {'error': 'true'},
|
||||
'onNull': {'isnull': 'true'}
|
||||
}}]},
|
||||
|
||||
{'$eq': ["$valide", "1"]},
|
||||
{'$eq': ["$partner_recid", '$$partner_owner_recid']}
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
],
|
||||
'as': 'partner_client_collection'
|
||||
}
|
||||
},
|
||||
{'$group': {
|
||||
'_id': {
|
||||
|
||||
"mois_annee_facture": { "$concat": [{'$substr': ["$invoice_date", 3, 2]},"_", {'$substr': ["$invoice_date", 6, 4]}]},
|
||||
"annee_facture": {'$substr': ["$invoice_date", 6, 4]},
|
||||
"mois_facture": {'$substr': ["$invoice_date", 3, 2]},
|
||||
},
|
||||
"TotalAmount": {"$sum": {'$toDouble': '$total_header_toutes_taxes'}},
|
||||
"count": { "$sum": 1}
|
||||
}
|
||||
},
|
||||
{
|
||||
'$sort': {'count': -1}
|
||||
},
|
||||
|
||||
])
|
||||
|
||||
print(" ### Get_Qery_List_Facture_Previsionnelle_Data_By_Periode ici pipe_qry = ", pipe_qry)
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
axis_data = []
|
||||
series_TotalAmount_data = []
|
||||
|
||||
"""
|
||||
On recupere les données, on les format dans le 'range_date_month' et on retourne"""
|
||||
for retval in MYSY_GV.dbname['partner_invoice_header'].aggregate(pipe_qry):
|
||||
val_tmp = val_tmp + 1
|
||||
for tmp in range_date_month:
|
||||
axis_data.append(str(tmp['month_year']))
|
||||
|
||||
if( str(retval['_id']['mois_annee_facture']) == str(tmp['month_year']) ):
|
||||
tmp['TotalAmount'] = mycommon.tryFloat(str(retval['TotalAmount']))
|
||||
tmp['count'] = mycommon.tryFloat(str(retval['count']))
|
||||
|
||||
series_TotalAmount_data.append( str(retval['TotalAmount']))
|
||||
else:
|
||||
series_TotalAmount_data.append("0")
|
||||
|
||||
|
||||
|
||||
json_retval = {}
|
||||
json_retval['data'] = range_date_month
|
||||
json_retval['axis_data'] = axis_data
|
||||
json_retval['series_TotalAmount_data'] = series_TotalAmount_data
|
||||
|
||||
RetObject.append(mycommon.JSONEncoder().encode(json_retval))
|
||||
|
||||
return True, RetObject
|
||||
|
||||
|
||||
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 de récupérer les données "
|
||||
|
||||
|
||||
def Get_Qery_List_Facture_Previsionnelle_Data_By_Periode(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'periode_start_date', 'periode_end_date', 'filter_value', 'filter_client_id']
|
||||
|
||||
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'existe pas")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['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",
|
||||
|
||||
"""
|
||||
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
|
||||
|
||||
filt_client_id = {}
|
||||
if ("filter_client_id" in diction.keys() and diction['filter_client_id']):
|
||||
filt_client_id = {'order_header_client_id': str(diction['filter_client_id'])}
|
||||
|
||||
filt_periode_start_date = ""
|
||||
if ("periode_start_date" in diction.keys() and diction['periode_start_date']):
|
||||
filt_periode_start_date = str(diction['periode_start_date'])[0:10]
|
||||
local_status = mycommon.CheckisDate(filt_periode_start_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le filtre : 'date de debut' n'est pas au format jj/mm/aaaa.")
|
||||
return False, " Le filtre : 'date de debut' n'est pas au format jj/mm/aaaa."
|
||||
|
||||
filt_periode_end_date = ""
|
||||
if ("periode_end_date" in diction.keys() and diction['periode_end_date']):
|
||||
filt_periode_end_date = str(diction['periode_end_date'])[0:10]
|
||||
local_status = mycommon.CheckisDate(filt_periode_end_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa.")
|
||||
return False, " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa."
|
||||
|
||||
"""
|
||||
Si la valeur de 'filter_value' est m0 ou m1, on va aller recuperer les date du mois correspondant.
|
||||
On ecrase les valeur de filt_session_start_date et filt_session_end_date
|
||||
"""
|
||||
if ('filter_value' in diction.keys()):
|
||||
# print(" filter_value = ", diction['filter_value'])
|
||||
if (str(diction['filter_value']) == "m0"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_periode_start_date = start_current_month_date
|
||||
filt_periode_end_date = end_current_month_date
|
||||
|
||||
# print(" ### filt_session_start_date = ", filt_session_start_date, " ### filt_session_end_date = ", filt_session_end_date)
|
||||
|
||||
elif (str(diction['filter_value']) == "m1"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_periode_start_date = start_current_month_date
|
||||
filt_periode_end_date = end_current_month_date
|
||||
|
||||
filt_periode_start_date_ISODATE = datetime.strptime(str(filt_periode_start_date), '%d/%m/%Y')
|
||||
filt_periode_end_date_ISODATE = datetime.strptime(str(filt_periode_end_date), '%d/%m/%Y')
|
||||
|
||||
"""
|
||||
Creation de la range des mois entre filt_periode_start_date_ISODATE et
|
||||
filt_periode_end_date_ISODATE
|
||||
"""
|
||||
range_date_month = []
|
||||
start = filt_periode_start_date_ISODATE
|
||||
end = filt_periode_end_date_ISODATE
|
||||
while start <= end:
|
||||
node = {}
|
||||
node['month_year'] = '{:02d}'.format(start.month) + "_" + str(start.year)
|
||||
node['label'] = '{:02d}'.format(start.month) + "_" + str(start.year)
|
||||
node['first_day'] = "01/"+'{:02d}'.format(start.month) + "/" + str(start.year)
|
||||
node['list_session'] = []
|
||||
node['TotalAmount'] = 0
|
||||
node['value'] = 0
|
||||
node['count'] = 0
|
||||
|
||||
range_date_month.append(node)
|
||||
start += relativedelta(months=1)
|
||||
|
||||
#print(" ### range_date_month = ", range_date_month)
|
||||
|
||||
|
||||
for data in range_date_month:
|
||||
#print(" data = ", data)
|
||||
ca_month_previsionnel = 0
|
||||
|
||||
local_first_day_ISODATE = datetime.strptime(str(data['first_day']), '%d/%m/%Y')
|
||||
work_first_day = str(local_first_day_ISODATE.strftime("%d/%m/%Y"))
|
||||
|
||||
#filt_periode_start_date_ISODATE = datetime.strptime(str(filt_periode_start_date), '%d/%m/%Y')
|
||||
|
||||
|
||||
|
||||
#print(" local_first_day_ISODATE = ", local_first_day_ISODATE)
|
||||
|
||||
qery_match = {'$and': [{"valide": '1', 'partner_owner_recid': str(my_partner['recid'])},
|
||||
|
||||
{
|
||||
'mysy_session_start_date': {'$lte': local_first_day_ISODATE},
|
||||
},
|
||||
{
|
||||
'mysy_session_end_date': {'$gte': local_first_day_ISODATE, },
|
||||
},
|
||||
|
||||
]}
|
||||
|
||||
pipe_qry = [
|
||||
|
||||
{"$addFields": {
|
||||
"mysy_session_start_date": {
|
||||
'$dateFromString': {
|
||||
'dateString': '$date_debut',
|
||||
'format': "%d/%m/%Y"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{"$addFields": {
|
||||
"mysy_session_end_date": {
|
||||
'$dateFromString': {
|
||||
'dateString': '$date_fin',
|
||||
'format': "%d/%m/%Y"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{'$match': qery_match},
|
||||
|
||||
|
||||
{'$lookup': {
|
||||
'from': 'inscription',
|
||||
'let': {'session_id': {'$toString': '$_id'}, 'session_partner_owner_recid': '$partner_owner_recid'},
|
||||
'pipeline': [
|
||||
{'$match':
|
||||
{'$expr':
|
||||
{'$and':
|
||||
[
|
||||
{'$eq': ['$session_id', '$$session_id']},
|
||||
{'$eq': ['$partner_owner_recid', '$$session_partner_owner_recid']}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
],
|
||||
'as': 'inscription_collection'
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
#print(" ### pipe_qry previsionnel = ", pipe_qry)
|
||||
#print(" ### datetime.strptime(str(data['first_day']), '%d/%m/%Y') = ", datetime.strptime(str(data['first_day']), '%d/%m/%Y'))
|
||||
|
||||
|
||||
|
||||
for val in MYSY_GV.dbname['session_formation'].aggregate(pipe_qry):
|
||||
|
||||
|
||||
for tmp in range_date_month:
|
||||
CA_previsionnel = 0
|
||||
|
||||
if( tmp['first_day'] == work_first_day):
|
||||
ca_prev = 0
|
||||
|
||||
local_node = {}
|
||||
local_node['session_id'] = str(val['_id'])
|
||||
local_node['code_session'] = val['code_session']
|
||||
local_node['prix_session'] = val['prix_session']
|
||||
local_node['price_by'] = val['price_by']
|
||||
if( "inscription_collection" in val.keys() ):
|
||||
local_node['nb_participant'] = len(val['inscription_collection'])
|
||||
else:
|
||||
local_node['nb_participant'] = '0'
|
||||
|
||||
if( val['price_by'] == "perstagiaire"):
|
||||
ca_prev = (mycommon.tryFloat( val['prix_session']) * mycommon.tryFloat( local_node['nb_participant'])) + ca_prev
|
||||
|
||||
elif( val['price_by'] == "persession"):
|
||||
ca_prev = (mycommon.tryFloat( val['prix_session']) ) + ca_prev
|
||||
|
||||
local_node['ca_previsionnel'] = str(ca_prev)
|
||||
|
||||
tmp['list_session'].append(local_node)
|
||||
ca_month_previsionnel = ca_month_previsionnel + ca_prev
|
||||
|
||||
data['ca_month_previsionnel'] = str(ca_month_previsionnel)
|
||||
|
||||
print(" ### range_date_month = ", range_date_month)
|
||||
|
||||
RetObject = []
|
||||
RetObject.append(mycommon.JSONEncoder().encode(range_date_month))
|
||||
|
||||
return True, RetObject
|
||||
|
||||
|
||||
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 de récupérer les données "
|
||||
|
||||
|
||||
"""
|
||||
|
|
|
@ -682,9 +682,9 @@ FILE_NAME_MAX_SIZE = 250
|
|||
Les types de formulaire
|
||||
- pos = Formulaire pour questionnaire de positionnement
|
||||
- hot_eval = Formulaire pour evaluation à chaud
|
||||
- cool_eval = Formulaire pour evaluation à froid
|
||||
- cold_eval = Formulaire pour evaluation à froid
|
||||
"""
|
||||
FORM_TYPE = ['pos', 'hot_eval', 'cool_eval']
|
||||
FORM_TYPE = ['pos', 'hot_eval', 'cold_eval']
|
||||
|
||||
|
||||
"""
|
||||
|
|
|
@ -0,0 +1,215 @@
|
|||
"""
|
||||
Ce fichier permet de gerer les crons et differents job
|
||||
"""
|
||||
import ast
|
||||
|
||||
import bson
|
||||
import pymongo
|
||||
import xlsxwriter
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
from bson import ObjectId
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
import module_editique
|
||||
import prj_common as mycommon
|
||||
import secrets
|
||||
import inspect
|
||||
import sys, os
|
||||
import csv
|
||||
import pandas as pd
|
||||
from pymongo import ReturnDocument
|
||||
import GlobalVariable as MYSY_GV
|
||||
from math import isnan
|
||||
import GlobalVariable as MYSY_GV
|
||||
import ela_index_bdd_classes as eibdd
|
||||
import email_mgt as email
|
||||
import jinja2
|
||||
from flask import send_file
|
||||
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
|
||||
import survey_mgt as survey_mgt
|
||||
|
||||
|
||||
"""
|
||||
Ce job permet d'envoyer les demandes d'enquetes comme les
|
||||
evaluation à froid.
|
||||
|
||||
Les informations sont stockées dans la collection : "survey"
|
||||
|
||||
Par exemple, une fois par jour ce job va tourner,
|
||||
"date_demande_envoi" = date_jour, alors on envoi
|
||||
|
||||
on met à jour avec la collection avec
|
||||
"""
|
||||
def Global_MySy_Cron_Traitement():
|
||||
try:
|
||||
|
||||
today = str(datetime.now().strftime("%d/%m/%Y"))
|
||||
today_date_ISODATE = datetime.strptime(str(today), '%d/%m/%Y')
|
||||
|
||||
|
||||
qery_match = {'$and': [{"valide": '1', 'locked':'0'},
|
||||
|
||||
{
|
||||
'mysy_cron_date_start': {'$lte': today_date_ISODATE},
|
||||
},
|
||||
{
|
||||
'mysy_cron_date_end': {'$gte': today_date_ISODATE,},
|
||||
},
|
||||
|
||||
|
||||
]}
|
||||
|
||||
pipe_qry = ([
|
||||
{"$addFields": {
|
||||
"mysy_cron_date_start": {
|
||||
'$dateFromString': {
|
||||
'dateString': '$date_start',
|
||||
'format': "%d/%m/%Y"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{"$addFields": {
|
||||
"mysy_cron_date_end": {
|
||||
'$dateFromString': {
|
||||
'dateString': '$date_end',
|
||||
'format': "%d/%m/%Y"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{'$match': qery_match},
|
||||
])
|
||||
|
||||
|
||||
for val in MYSY_GV.dbname['Job_Cron'].aggregate(pipe_qry):
|
||||
if( "job_name" in val.keys() ):
|
||||
possibles = globals().copy()
|
||||
possibles.update(locals())
|
||||
cron_function = possibles.get(val['job_name'])
|
||||
if not cron_function:
|
||||
return False, "Fonction '"+str(val['job_name'])+"' est introuvable"
|
||||
|
||||
local_con_status, local_con_retval = cron_function()
|
||||
|
||||
print(" local_con_status = ", local_con_status)
|
||||
|
||||
"""
|
||||
Mettre à jour le cron pour dire que tout s'est bien poassé
|
||||
"""
|
||||
|
||||
now = str(datetime.now())
|
||||
cron_update_data = {}
|
||||
|
||||
cron_update_data['last_run'] = str(now)
|
||||
if( local_con_status is True ):
|
||||
cron_update_data['last_run_status'] = "1"
|
||||
else:
|
||||
cron_update_data['last_run_status'] = "0"
|
||||
|
||||
cron_update_data['last_run_message'] = local_con_retval
|
||||
|
||||
node_traitement = {}
|
||||
node_traitement['run_date'] = str(now)
|
||||
node_traitement['run_status'] = str(cron_update_data['last_run_status'])
|
||||
node_traitement['run_message'] = str(local_con_retval)
|
||||
|
||||
|
||||
|
||||
if( "cront_list_traitement" in val.keys() and val['cront_list_traitement']):
|
||||
local_cront_list_traitement = val['cront_list_traitement']
|
||||
local_cront_list_traitement.append(node_traitement)
|
||||
else:
|
||||
local_cront_list_traitement = []
|
||||
local_cront_list_traitement.append(node_traitement)
|
||||
|
||||
|
||||
cron_update_data['cront_list_traitement'] = local_cront_list_traitement
|
||||
|
||||
ret_val = MYSY_GV.dbname['Job_Cron'].find_one_and_update(
|
||||
{'_id': ObjectId(str(val['_id']))},
|
||||
{"$set": cron_update_data},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=False,
|
||||
)
|
||||
|
||||
return True, "OK"
|
||||
|
||||
|
||||
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, str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno)
|
||||
|
||||
|
||||
def Cron_Send_Survey():
|
||||
try:
|
||||
for val in MYSY_GV.dbname['survey'].find({"automatique_traitement":"1",
|
||||
'automatique_traitement_done':'0',
|
||||
'valide':'1',
|
||||
'locked':'0'}) :
|
||||
|
||||
|
||||
|
||||
|
||||
if( "automatique_sending_request_date" in val.keys() and val['automatique_sending_request_date']):
|
||||
automatic_date_to_send = str(val['automatique_sending_request_date'])[0:10]
|
||||
local_status = mycommon.CheckisDate(automatic_date_to_send)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " La date 'automatique_sending_request_date' de n'est pas au format jj/mm/aaaa.")
|
||||
return False, " La date 'automatique_sending_request_date' de n'est pas au format jj/mm/aaaa."
|
||||
|
||||
|
||||
|
||||
if (datetime.strptime(str(automatic_date_to_send), '%d/%m/%Y') <= datetime.strptime(str(datetime.now().strftime("%d/%m/%Y")), '%d/%m/%Y') ) :
|
||||
print(" OKK to run job ")
|
||||
|
||||
local_dicton = {}
|
||||
local_dicton['partner_owner_recid'] = str(val['partner_owner_recid'])
|
||||
local_dicton['tab_ids'] = (str(val['_id']))
|
||||
|
||||
|
||||
|
||||
local_status, local_retval = survey_mgt.Automatic_Send_Survey_TabIds(local_dicton)
|
||||
|
||||
#data['date_update'] = str(datetime.now())
|
||||
survey_update_data = {}
|
||||
|
||||
sending_status = "0"
|
||||
if( local_status is False ):
|
||||
sending_status = "0"
|
||||
|
||||
else:
|
||||
sending_status = "1"
|
||||
survey_update_data['automatique_traitement_done'] = "1"
|
||||
|
||||
survey_update_data['date_envoi'] = str(datetime.now())
|
||||
|
||||
|
||||
ret_val = MYSY_GV.dbname['survey'].find_one_and_update(
|
||||
{'_id': ObjectId(str(val['_id']))},
|
||||
{"$set": survey_update_data},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=False,
|
||||
)
|
||||
|
||||
|
||||
|
||||
return True, ""
|
||||
|
||||
|
||||
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, str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno)
|
4419
Log/log_file.log
4419
Log/log_file.log
File diff suppressed because it is too large
Load Diff
45
main.py
45
main.py
|
@ -86,6 +86,7 @@ import metier_formation_mgt as metier_formation_mgt
|
|||
import categorie_formation_mgt as categorie_formation_mgt
|
||||
import domaine_formation_mgt as domaine_formation_mgt
|
||||
import invoice_paiement_mgt as invoice_paiement_mgt
|
||||
import Job_Cron as Job_Cron
|
||||
|
||||
app = Flask(__name__)
|
||||
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
|
||||
|
@ -6848,6 +6849,9 @@ def Get_Qery_List_Session_Data():
|
|||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API / TBD / QRY : Recuperation des sessions par formateur sur une periode
|
||||
"""
|
||||
|
@ -8495,7 +8499,7 @@ def Init_Survey_Tab_For_All_Session_Inscrit():
|
|||
"""
|
||||
API pour recuperer la liste des survey avec des filtre sur
|
||||
- sesson_id,
|
||||
- formulaire_type - ['pos', 'hot_eval', 'cool_eval']
|
||||
- formulaire_type - ['pos', 'hot_eval', 'cold_eval']
|
||||
"""
|
||||
@app.route('/myclass/api/Get_List_Survey_with_filter/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
|
@ -8563,6 +8567,23 @@ def Get_Qery_List_Factures_Data_By_Periode():
|
|||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API / TBD / QRY : Recuperation des factures PREVISIONNELLES sur une periode
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Qery_List_Facture_Previsionnelle_Data_By_Periode/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Qery_List_Facture_Previsionnelle_Data_By_Periode():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Qery_List_Facture_Previsionnelle_Data_By_Periode payload = ",payload)
|
||||
status, retval = factures_tbd_qries.Get_Qery_List_Facture_Previsionnelle_Data_By_Periode(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API / TBD / QRY : Recuperation des factures sur une periode PAR CLIENT
|
||||
"""
|
||||
|
@ -9128,6 +9149,17 @@ def Delete_Given_Invoice_Paiement():
|
|||
status, retval = invoice_paiement_mgt.Delete_Given_Invoice_Paiement(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
"""
|
||||
api test gestion cron
|
||||
"""
|
||||
@app.route('/myclass/api/Global_MySy_Cron_Traitement/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Global_MySy_Cron_Traitement():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Global_MySy_Cron_Traitement payload = ",payload)
|
||||
status, retval = Job_Cron.Global_MySy_Cron_Traitement()
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -9150,15 +9182,18 @@ if __name__ == '__main__':
|
|||
|
||||
"""
|
||||
/!\ Dasactivé en dev pour pas consommer de ressource pr rien.
|
||||
"""
|
||||
scheduler = BackgroundScheduler()
|
||||
# Create the job
|
||||
scheduler.add_job(func=Flask_Cron_Strip_Get_Customer_Abonnement_Data, trigger="interval", minutes=5)
|
||||
#scheduler.add_job(func=Flask_Cron_Strip_Get_Customer_Abonnement_Data, trigger="interval", minutes=5)
|
||||
scheduler.add_job(func=Global_MySy_Cron_Traitement, trigger="interval", minutes=2)
|
||||
# Start the scheduler
|
||||
scheduler.start()
|
||||
|
||||
|
||||
# /!\ IMPORTANT /!\ : Shut down the scheduler when exiting the app
|
||||
atexit.register(lambda: scheduler.shutdown())
|
||||
"""
|
||||
|
||||
app.run(host='localhost', port=MYSY_GV.MYSY_PORT_DEV, debug=True, threaded=True)
|
||||
# Create the background scheduler
|
||||
|
||||
|
@ -9172,7 +9207,7 @@ if __name__ == '__main__':
|
|||
|
||||
scheduler = BackgroundScheduler()
|
||||
# Create the job
|
||||
scheduler.add_job(func=Flask_Cron_Strip_Get_Customer_Abonnement_Data, trigger="interval", minutes=5)
|
||||
scheduler.add_job(func=Flask_Cron_Strip_Get_Customer_Abonnement_Data, trigger="interval", minutes=50)
|
||||
# Start the scheduler
|
||||
scheduler.start()
|
||||
|
||||
|
@ -9192,7 +9227,7 @@ if __name__ == '__main__':
|
|||
|
||||
scheduler = BackgroundScheduler()
|
||||
# Create the job
|
||||
scheduler.add_job(func=Flask_Cron_Strip_Get_Customer_Abonnement_Data, trigger="interval", minutes=5)
|
||||
scheduler.add_job(func=Flask_Cron_Strip_Get_Customer_Abonnement_Data, trigger="interval", minutes=50)
|
||||
# Start the scheduler
|
||||
scheduler.start()
|
||||
|
||||
|
|
|
@ -4190,7 +4190,6 @@ Cette fonction retourne les données du partenair rattaché au user connecté
|
|||
def Get_Connected_User_Partner_Data_From_RecID(user_recid):
|
||||
try:
|
||||
|
||||
|
||||
mydata = MYSY_GV.dbname['partnair_account'].find_one({'recid':str(user_recid), 'is_partner_admin_account':'1', 'active':'1', 'locked':'0'})
|
||||
if( mydata is None):
|
||||
return False, " Aucun compte partenaire actif pour cet utilisateur"
|
||||
|
|
352
survey_mgt.py
352
survey_mgt.py
|
@ -360,7 +360,7 @@ def Add_Survey_Tab_Inscrit(diction):
|
|||
'valide': '1', 'status':'1'
|
||||
}
|
||||
|
||||
print(" ### req = ", req)
|
||||
#print(" ### req = ", req)
|
||||
local_Insc_retval = MYSY_GV.dbname['inscription'].find_one({'session_id': str(diction['session_id']),
|
||||
'_id':ObjectId(str(my_inscription_id)),
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
|
@ -371,11 +371,14 @@ def Add_Survey_Tab_Inscrit(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant de l'inscrit est invalide ")
|
||||
return False, " L'identifiant de l'inscrit est invalide "
|
||||
|
||||
mytoday = datetime.today().strftime("%d/%m/%Y")
|
||||
|
||||
server_diction = {}
|
||||
server_diction['token'] = diction['token']
|
||||
server_diction['session_id'] = diction['session_id']
|
||||
server_diction['inscrit_id'] = str(local_Insc_retval['_id'])
|
||||
server_diction['formulaire_id'] = diction['formulaire_id']
|
||||
server_diction['sending_date'] = str(mytoday)
|
||||
|
||||
|
||||
local_status, local_retval = Create_One_Survey_To_Inscrit(server_diction)
|
||||
|
@ -401,7 +404,7 @@ On supprime tous enregistrements avec le clé :
|
|||
"""
|
||||
def Init_Survey_Tab_For_All_Session_Inscrit(diction):
|
||||
try:
|
||||
field_list_obligatoire = ['session_id', 'token', 'formulaire_id', 'survey_type']
|
||||
field_list_obligatoire = ['session_id', 'token', 'formulaire_id', 'survey_type', 'sending_date']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -442,7 +445,7 @@ def Init_Survey_Tab_For_All_Session_Inscrit(diction):
|
|||
|
||||
|
||||
"""
|
||||
Verifier la valididé du formulaire
|
||||
Verifier la validité du formulaire
|
||||
"""
|
||||
is_valide_form = MYSY_GV.dbname['formulaire'].count_documents({'_id':ObjectId(str(diction['formulaire_id'])),
|
||||
'valide':'1',
|
||||
|
@ -495,6 +498,7 @@ def Init_Survey_Tab_For_All_Session_Inscrit(diction):
|
|||
server_diction['inscrit_id'] = str(local_Insc_retval['_id'])
|
||||
server_diction['formulaire_id'] = diction['formulaire_id']
|
||||
server_diction['survey_type'] = diction['survey_type']
|
||||
server_diction['sending_date'] = diction['sending_date']
|
||||
|
||||
|
||||
local_status, local_retval = Create_One_Survey_To_Inscrit(server_diction)
|
||||
|
@ -519,7 +523,7 @@ Cette fonction envoi un formulaire pour inscrit
|
|||
"""
|
||||
def Create_One_Survey_To_Inscrit(diction):
|
||||
try:
|
||||
field_list_obligatoire = ['session_id', 'token', 'inscrit_id', 'formulaire_id', 'survey_type']
|
||||
field_list_obligatoire = ['session_id', 'token', 'inscrit_id', 'formulaire_id', 'survey_type', 'sending_date']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -612,6 +616,9 @@ def Create_One_Survey_To_Inscrit(diction):
|
|||
new_survey_data['class_id'] = str(my_class_data['_id'])
|
||||
new_survey_data['survey_type'] = str(diction['survey_type'])
|
||||
new_survey_data['date_envoi'] = ""
|
||||
new_survey_data['automatique_sending_request_date'] = str(diction['sending_date'])
|
||||
new_survey_data['automatique_traitement'] = "1"
|
||||
new_survey_data['automatique_traitement_done'] = "0"
|
||||
|
||||
new_survey_data['locked'] = "0"
|
||||
new_survey_data['valide'] = "1"
|
||||
|
@ -978,11 +985,346 @@ def Send_Survey_TabIds(diction):
|
|||
return False, " Impossible d'envoyer les demande "
|
||||
|
||||
|
||||
"""
|
||||
Fonction qui permet d'envoyer des demande d'enquete avec le job/cron
|
||||
Ici on a pas besoin du cron, mais recuperer directement le 'partner_owner_recid'
|
||||
de la ligne à traiter
|
||||
"""
|
||||
def Automatic_Send_Survey_TabIds(diction):
|
||||
try:
|
||||
field_list_obligatoire = [ 'partner_owner_recid', 'tab_ids']
|
||||
|
||||
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"
|
||||
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Get_Connected_User_Partner_Data_From_RecID(str(diction['partner_owner_recid']))
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
my_survey_ids = ""
|
||||
if ("tab_ids" in diction.keys()):
|
||||
if diction['tab_ids']:
|
||||
my_survey_ids = diction['tab_ids']
|
||||
|
||||
tab_my_survey_ids = str(my_survey_ids).split(",")
|
||||
for my_survey_id in tab_my_survey_ids:
|
||||
|
||||
# Verifier que les survey sont valides
|
||||
qry = { '_id':ObjectId(str(my_survey_id)), 'partner_owner_recid': str(my_partner['recid']),'valide':'1', 'locked':'0'}
|
||||
|
||||
print(" qry2 === ", qry)
|
||||
tmp_count = MYSY_GV.dbname['survey'].count_documents(qry)
|
||||
|
||||
if (tmp_count <= 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant de l'enquete "+str(my_survey_id)+" invalide ")
|
||||
return False, " L'identifiant de l'enquete "+str(my_survey_id)+" invalide "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Les enquete etant toutes valides, on va preceder à l'envoie des email de demande
|
||||
"""
|
||||
"""
|
||||
Recuperation des parametre SMTP du partner si le client a decidé d'utiliser son propre smpt
|
||||
"""
|
||||
partner_own_smtp_value = "0"
|
||||
partner_own_smtp = MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'partner_owner_recid': str(my_partner['recid']),
|
||||
'config_name': 'partner_smtp',
|
||||
'valide': '1',
|
||||
'locked': '0'})
|
||||
|
||||
if (partner_own_smtp and "config_value" in partner_own_smtp.keys()):
|
||||
partner_own_smtp_value = partner_own_smtp['config_value']
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
partner_SMTP_COUNT_password = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{'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(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(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(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(my_partner['recid']),
|
||||
'config_name': 'smtp_count_port',
|
||||
'valide': '1',
|
||||
'locked': '0'}, {'config_value': 1})['config_value'])
|
||||
|
||||
|
||||
for my_survey_id in tab_my_survey_ids:
|
||||
# Recuperation des données de l'inscript
|
||||
|
||||
qry = { '_id':ObjectId(str(my_survey_id)), 'partner_owner_recid': str(my_partner['recid']),'valide':'1', 'locked':'0'}
|
||||
|
||||
local_survey_retval = MYSY_GV.dbname['survey'].find_one(qry)
|
||||
|
||||
if(local_survey_retval is None ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant de l'inscrit est invalide ")
|
||||
return False, " L'identifiant de l'inscrit est invalide "
|
||||
|
||||
|
||||
courrier_ref_interne = ""
|
||||
if ( "survey_type" in local_survey_retval.keys() and local_survey_retval['survey_type'] == "pos"):
|
||||
courrier_ref_interne = "QUESTION_POSITIONNEMENT"
|
||||
|
||||
elif ( "survey_type" in local_survey_retval.keys() and local_survey_retval['survey_type'] == "hot_eval"):
|
||||
courrier_ref_interne = "EVAL_FORMATION"
|
||||
|
||||
elif ("survey_type" in local_survey_retval.keys() and local_survey_retval['survey_type'] == "cold_eval"):
|
||||
courrier_ref_interne = "EVAL_FORMATION"
|
||||
|
||||
else :
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " Le type d'enquete est invalide ")
|
||||
return False, " Le type d'enquete est invalide "
|
||||
|
||||
"""
|
||||
Recuperation du modele de courrier (unique) associé à l'envoie des questions de positionnement
|
||||
le principe est de prendre le module du partenaire. si pas de modele du partenaire on
|
||||
prend le modele par default
|
||||
"""
|
||||
|
||||
courrier_template_model = MYSY_GV.dbname['courrier_template'].count_documents(
|
||||
{'ref_interne': str(courrier_ref_interne),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'type_doc': 'email',
|
||||
'partner_owner_recid': str(my_partner['recid'])}
|
||||
)
|
||||
if (courrier_template_model == 1):
|
||||
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one(
|
||||
{'ref_interne': str(courrier_ref_interne),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'type_doc': 'email',
|
||||
'partner_owner_recid': str(my_partner['recid'])}
|
||||
)
|
||||
|
||||
else:
|
||||
courrier_template_model = MYSY_GV.dbname['courrier_template'].count_documents(
|
||||
{'ref_interne': str(courrier_ref_interne),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'type_doc': 'email',
|
||||
'partner_owner_recid': "default"}
|
||||
)
|
||||
if (courrier_template_model == 1):
|
||||
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one(
|
||||
{'ref_interne': str(courrier_ref_interne),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'type_doc': 'email',
|
||||
'partner_owner_recid': "default"}
|
||||
)
|
||||
else:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][
|
||||
3]) + " Aucun modèle de document configuré pour envoyer les demandes pour les questionnaires de positionnement ")
|
||||
return False, " Aucun modèle de document configuré pour envoyer les demandes pour les questionnaires de positionnement "
|
||||
|
||||
if ("contenu_doc" not in courrier_template_data.keys() or str(
|
||||
courrier_template_data['contenu_doc']).strip() == ""):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Le modèle de document ne contient pas de valeur 'contenu_doc' ")
|
||||
return False, " Le modèle de document ne contient pas de valeur 'contenu_doc' "
|
||||
|
||||
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
||||
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
||||
convention_dictionnary_data = {}
|
||||
new_diction = {}
|
||||
new_diction['token'] = my_partner['token']
|
||||
|
||||
is_apprenant = 0
|
||||
new_diction['list_stagiaire_id'] = []
|
||||
if( "inscription_id" in local_survey_retval.keys() and local_survey_retval['inscription_id']):
|
||||
new_diction['list_stagiaire_id'].append(ObjectId(str( local_survey_retval['inscription_id'])))
|
||||
|
||||
|
||||
|
||||
new_diction['list_session_id'] = []
|
||||
if ("session_id" in local_survey_retval.keys() and local_survey_retval['session_id']):
|
||||
new_diction['list_session_id'].append(ObjectId(str(local_survey_retval['session_id'])))
|
||||
|
||||
new_diction['list_class_id'] = []
|
||||
if ("class_id" in local_survey_retval.keys() and local_survey_retval['class_id']):
|
||||
new_diction['list_class_id'].append(ObjectId(str(local_survey_retval['class_id'])))
|
||||
|
||||
|
||||
new_diction['list_client_id'] = []
|
||||
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
|
||||
|
||||
servey_url = MYSY_GV.CLIENT_URL_BASE + "Survey/" + str(local_survey_retval['_id'])
|
||||
|
||||
convention_dictionnary_data["servey_url"] = str(servey_url)
|
||||
convention_dictionnary_data["servey_email"] = str(local_survey_retval['email'])
|
||||
convention_dictionnary_data["servey_nom"] = str(local_survey_retval['nom'])
|
||||
convention_dictionnary_data["servey_prenom"] =str(local_survey_retval['prenom'])
|
||||
|
||||
|
||||
body = {
|
||||
"params": convention_dictionnary_data
|
||||
}
|
||||
|
||||
|
||||
|
||||
html = contenu_doc_Template.render(params=body["params"])
|
||||
|
||||
subject_doc_Template = jinja2.Template(str(courrier_template_data['sujet']))
|
||||
subject = subject_doc_Template.render(params=body["params"])
|
||||
|
||||
|
||||
html_mime = MIMEText(html, 'html')
|
||||
|
||||
# Creation de l'email à enoyer
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
||||
else:
|
||||
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
||||
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = partner_SMTP_COUNT_From_User
|
||||
msg['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = str(subject)
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
|
||||
msg['to'] = str(local_survey_retval['email'])
|
||||
|
||||
smtpserver.ehlo()
|
||||
smtpserver.starttls()
|
||||
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
||||
|
||||
else:
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
||||
msg['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = str(subject)
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
|
||||
msg['to'] = str(local_survey_retval['email'])
|
||||
|
||||
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))
|
||||
|
||||
"""
|
||||
Mettre à jour l'enquete pour dire que c'est envoyé
|
||||
"""
|
||||
now = str(datetime.now())
|
||||
|
||||
qry = {'_id': ObjectId(str(my_survey_id)), 'partner_owner_recid': str(my_partner['recid']),
|
||||
'valide': '1', 'locked': '0'}
|
||||
result = MYSY_GV.dbname['survey'].find_one_and_update(qry,
|
||||
{'$set':{'statut':'1', 'date_update':str(now),
|
||||
'update_by':str(my_partner['_id']),
|
||||
'date_envoi':now}}
|
||||
)
|
||||
|
||||
courrier_ref_interne = ""
|
||||
if ("survey_type" in result.keys() and result['survey_type'] == "pos"):
|
||||
courrier_ref_interne = "QUESTION_POSITIONNEMENT"
|
||||
|
||||
elif ("survey_type" in result.keys() and result['survey_type'] == "hot_eval"):
|
||||
courrier_ref_interne = "EVAL_FORMATION"
|
||||
|
||||
elif ("survey_type" in result.keys() and result['survey_type'] == "cold_eval"):
|
||||
courrier_ref_interne = "EVAL_FORMATION"
|
||||
|
||||
else:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " Le type d'enquete est invalide ")
|
||||
return False, " Le type d'enquete est invalide "
|
||||
|
||||
"""
|
||||
Apres que l'envoie est fait, on va loguer le traitement dans la collection : courrier_template_tracking_history
|
||||
"""
|
||||
if( "inscription_id" in local_survey_retval.keys() ):
|
||||
# Cette demande d'enquete concerne une inscription
|
||||
local_inscription_id = local_survey_retval['inscription_id']
|
||||
|
||||
qry = {'_id': ObjectId(str(local_inscription_id)),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])}
|
||||
|
||||
#print(" ### qry 010101 = ", qry)
|
||||
|
||||
inscription_data = MYSY_GV.dbname['inscription'].find_one({'_id': ObjectId(str(local_inscription_id)),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
|
||||
if( inscription_data is None or "session_id" not in inscription_data.keys() ):
|
||||
mycommon.myprint(
|
||||
" WARNING : Impossible de logguer l'historique pour l'inscrit : " + str(local_inscription_id))
|
||||
|
||||
print(" inscription_data = ", inscription_data)
|
||||
|
||||
local_status, local_retval = module_editique.Editic_Log_History_Action_From_courrier_template_type_document_ref_interne(
|
||||
my_partner, str(courrier_ref_interne), str(inscription_data['session_id']), 'inscription',
|
||||
str(local_inscription_id),"")
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
" WARNING : Impossible de logguer l'historique pour l'inscrit (2) : " + str(local_inscription_id))
|
||||
|
||||
|
||||
|
||||
return True, " Les demandes d'enquete ont été envoyées "
|
||||
|
||||
|
||||
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 d'envoyer les demande "
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Fonction pour Recuperer la liste des enquete avec les filtre suivant :
|
||||
- session_id,
|
||||
- formulaire_type - ['pos', 'hot_eval', 'cool_eval']
|
||||
- formulaire_type - ['pos', 'hot_eval', 'cold_eval']
|
||||
|
||||
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue