01/01/2024- 18h

master
cherif 2024-01-01 17:50:24 +01:00
parent 69a594865f
commit 44eb3c2e79
9 changed files with 4134 additions and 82 deletions

View File

@ -1,16 +1,14 @@
<?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="29/12/2023- 12h">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="31/12/2023- 18h">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Dashbord_queries/ressources_humaines_tbd_qries.py" beforeDir="false" afterPath="$PROJECT_DIR$/Dashbord_queries/ressources_humaines_tbd_qries.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$/apprenant_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/apprenant_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/class_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/class_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data_dict.csv" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/data_indexees.csv" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/data_indexees_article_avis.csv" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/Session_Formation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation.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$/purchase_prices.py" beforeDir="false" afterPath="$PROJECT_DIR$/purchase_prices.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ressources_humaines.py" beforeDir="false" afterPath="$PROJECT_DIR$/ressources_humaines.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tools_cherif/tools_cherif.py" beforeDir="false" afterPath="$PROJECT_DIR$/tools_cherif/tools_cherif.py" afterDir="false" />
</list>
@ -82,13 +80,6 @@
<option name="presentableId" value="Default" />
<updated>1680804787304</updated>
</task>
<task id="LOCAL-00135" summary="22/10/2023 - 22h">
<created>1698005958434</created>
<option name="number" value="00135" />
<option name="presentableId" value="LOCAL-00135" />
<option name="project" value="LOCAL" />
<updated>1698005958435</updated>
</task>
<task id="LOCAL-00136" summary="23/10/2023 - 13h">
<created>1698059598790</created>
<option name="number" value="00136" />
@ -425,7 +416,14 @@
<option name="project" value="LOCAL" />
<updated>1703848960676</updated>
</task>
<option name="localTasksCounter" value="184" />
<task id="LOCAL-00184" summary="31/12/2023- 18h">
<created>1704042376850</created>
<option name="number" value="00184" />
<option name="presentableId" value="LOCAL-00184" />
<option name="project" value="LOCAL" />
<updated>1704042376851</updated>
</task>
<option name="localTasksCounter" value="185" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -440,7 +438,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="24/11/2023 - 18h30" />
<MESSAGE value="30/11/2023 - 21h" />
<MESSAGE value="01/12/2023 - 23h" />
<MESSAGE value="04/12/2023 - 21h" />
@ -465,6 +462,7 @@
<MESSAGE value="27/12/2023 - 23h" />
<MESSAGE value="28/12/2023- 19h" />
<MESSAGE value="29/12/2023- 12h" />
<option name="LAST_COMMIT_MESSAGE" value="29/12/2023- 12h" />
<MESSAGE value="31/12/2023- 18h" />
<option name="LAST_COMMIT_MESSAGE" value="31/12/2023- 18h" />
</component>
</project>

View File

@ -22,6 +22,7 @@ from pymongo import ReturnDocument
import GlobalVariable as MYSY_GV
from math import isnan
import GlobalVariable as MYSY_GV
import GlobalVariable as MYSY_GV
from datetime import timedelta
from datetime import timedelta
from operator import itemgetter
@ -39,6 +40,7 @@ def Get_Humain_Ressource_With_Planning(diction):
"""
field_list = ['token', 'session_start_date', 'session_end_date', 'filter_value', 'tab_rh_id', 'event_type' ]
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
@ -271,8 +273,8 @@ def Get_Humain_Ressource_With_Planning(diction):
new_node['agenda_event_type'] = ""
if ("event_start" in agenda_retval.keys()):
new_node['agenda_date_jour'] = str(datetime.strptime(str(agenda_retval['event_end'])[0:16], '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y"))
new_node['agenda_event_start'] = str(datetime.strptime(str(agenda_retval['event_end'])[0:16], '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y %H:%M"))
new_node['agenda_date_jour'] = str(datetime.strptime(str(agenda_retval['event_start'])[0:16], '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y"))
new_node['agenda_event_start'] = str(datetime.strptime(str(agenda_retval['event_start'])[0:16], '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y %H:%M"))
else:
new_node['agenda_date_jour'] = ""
@ -295,9 +297,6 @@ def Get_Humain_Ressource_With_Planning(diction):
#print(" ### new_node = ", new_node)
RetObject.append(mycommon.JSONEncoder().encode(new_node))
return True, RetObject
@ -403,6 +402,12 @@ def TBD_RH_01_Export_Dashbord_To_Csv(diction):
return local_status, local_retval
new_retval_data = local_retval
if (my_user_dashbord['dashbord_internal_code'] == "tbd_rh_02"):
local_status, local_retval = Get_Humain_Ressource_With_Planning_And_Cost(my_new_diction)
if (local_status is False):
return local_status, local_retval
new_retval_data = local_retval
else:
mycommon.myprint(
@ -477,3 +482,542 @@ def TBD_RH_01_Export_Dashbord_To_Csv(diction):
return False, " Impossible d'exporter les données "
"""
Cette fonction permet de calculer les cout
par employé, par tache, selon le contrat
"""
def Get_Humain_Ressource_With_Planning_And_Cost(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'session_start_date', 'session_end_date', 'filter_value', 'tab_rh_id', 'event_type']
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', 'session_start_date', 'session_end_date']
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
# Verfication de la validité du type d'evenement
event_type_filter = {}
if ("event_type" in diction.keys() and diction['event_type']):
if (diction['event_type'] not in MYSY_GV.AGENDA_EVENT_TYPE):
mycommon.myprint(
str(inspect.stack()[0][3]) + " Le type d'évènement est invalide ")
return False, " Le type d'évènement est invalide "
event_type_filter = {'$eq': ["$event_type", str(diction['event_type'])]}
"""
/!\ : si 'tab_rh_id' == 'all', cela veut dire qu'on prend touts les employés
si non, on va aller filtrer selon les contenus de la tab tab_rh_id
"""
tab_rh_id = []
tab_rh_object_id = []
if (str(diction['tab_rh_id']) == "all"):
for val in MYSY_GV.dbname['ressource_humaine'].find({'valide': '1',
'locked': '0',
'partner_recid': str(my_partner['recid'])}):
tab_rh_object_id.append(val['_id'])
else: # Verification de la validité de toutes les ressources humaines dans tab_rh_id
tab_rh_id = str(diction['tab_rh_id']).split(',')
for rh_id in tab_rh_id:
if (MYSY_GV.dbname['ressource_humaine'].count_documents({'_id': ObjectId(str(rh_id)),
'valide': '1',
'locked': '0',
'partner_recid': str(
my_partner['recid'])}) != 1):
mycommon.myprint(
str(inspect.stack()[0][3]) + " La ressource humaine :" + str(rh_id) + " n'est pas valide ")
return False, " La session_id :" + str(rh_id) + " n'est pas valide "
tab_rh_object_id.append(ObjectId(str(rh_id)))
filt_session_start_date = ""
if ("session_start_date" in diction.keys() and diction['session_start_date']):
filt_session_start_date = str(diction['session_start_date'])[0:10]
local_status = mycommon.CheckisDate(filt_session_start_date)
if (local_status is False):
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le filtre : 'date de debut de session' n'est pas au format jj/mm/aaaa.")
return False, " Le filtre : 'date de debut de session' n'est pas au format jj/mm/aaaa."
filt_session_end_date = ""
if ("session_end_date" in diction.keys() and diction['session_end_date']):
filt_session_end_date = str(diction['session_end_date'])[0:10]
local_status = mycommon.CheckisDate(filt_session_end_date)
if (local_status is False):
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le filtre : 'date de fin de session' n'est pas au format jj/mm/aaaa.")
return False, " Le filtre : 'date de fin de session' 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()):
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_session_start_date = start_current_month_date
filt_session_end_date = end_current_month_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_session_start_date = start_current_month_date
filt_session_end_date = end_current_month_date
"""
Algorithme :
1 - Pour chaque employé, aller chercher ses contrats valides de la periode. Completer ce tableaux avec les données du contrat
mettre dans une tableau en local
2 - Pour chaque tache de l'employée, aller chercher le contrat qui correspond à la periode de la tache
- Peupler ce tableau avec : tache (agenda), contrat (data), employé (data)
"""
tab_lines_employe_by_contract = []
"""
Etape 1: Récuperation des donnée employé avec les contrat associés
"""
print(" #### tab_rh_object_id = ", tab_rh_object_id)
# { "$match": {'_id':{'$in':tab_rh_object_id} }},
# {'$match': {'_id': ObjectId('6509a1adaca6e5023d7af487')}},
qry_employe_contrat = ([
{"$match": {'_id': {'$in': tab_rh_object_id}}},
{'$lookup': {
'from': 'ressource_humaine_contrat',
'let': {'rh_id': {'$toString': '$_id'}, 'rh_partner_owner_recid': '$partner_recid'},
'pipeline': [
{'$match':
{'$expr':
{'$and':
[
{'$eq': ['$valide', '1']},
{'$eq': ['$rh_id', '$$rh_id']},
{'$eq': ['$partner_owner_recid', '$$rh_partner_owner_recid']}
]
}
}
},
{"$project": {"_id": 0, }}
],
'as': 'collection_ressource_humaine_contrat'
}
},
{
'$unwind': '$collection_ressource_humaine_contrat'
}
])
cpt = 0
for retval in MYSY_GV.dbname['ressource_humaine'].aggregate(qry_employe_contrat):
# print(" ### retval = ", retval)
cpt = cpt + 1
rh_id_Object = ObjectId(str(retval['_id']))
retval['_id'] = str(rh_id_Object)
"""
Si le contrat est lié à un groupe de prix, alors aller chercher les elements du groupe de prix
"""
if ("groupe_prix_achat_id" in retval['collection_ressource_humaine_contrat'].keys() and
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_id']):
price_grp_data = MYSY_GV.dbname['purchase_prices'].find_one(
{'_id': ObjectId(str(retval['collection_ressource_humaine_contrat']['groupe_prix_achat_id'])),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(retval['collection_ressource_humaine_contrat']['partner_owner_recid']),
})
if (price_grp_data and "prix" in price_grp_data.keys() and "periodicite" in price_grp_data.keys()):
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_code'] = str(price_grp_data['code_groupe_prix'])
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_cout'] = str(
price_grp_data['prix'])
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_periodicite'] = str(
price_grp_data['periodicite'])
else:
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_code'] = ""
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_cout'] = ""
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_periodicite'] = ""
else:
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_code'] = ""
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_cout'] = ""
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_periodicite'] = ""
retval['Tab_agenda'] = []
"""
Aller chercher toutes taches valides entre les date du contrat
"""
date_debut_contrat = ""
date_fin_contrat = ""
if ("collection_ressource_humaine_contrat" in retval.keys() and "date_debut" in retval[
'collection_ressource_humaine_contrat'].keys()):
date_debut_contrat = retval['collection_ressource_humaine_contrat']['date_debut']
if ("collection_ressource_humaine_contrat" in retval.keys() and "date_fin" in retval[
'collection_ressource_humaine_contrat'].keys()):
date_fin_contrat = retval['collection_ressource_humaine_contrat']['date_fin']
if (mycommon.CheckisDate(date_debut_contrat) is False or mycommon.CheckisDate(date_fin_contrat) is False):
mycommon.myprint(str(
inspect.stack()[0][3]) + " Les dates de debut et/ou fin de contrat de l'employé " + str(
retval['nom'] + " " + retval['prenom']) + " ne sont au format jj/mm/aaaa.")
return False, " Les dates de debut et/ou fin de contrat de l'employé " + str(
retval['nom'] + " " + retval['prenom']) + " ne sont au format jj/mm/aaaa. "
"""
Etape 2 :
Aller recuperer les taches dans les agendas
"""
filt_session_start_date_ISODATE = datetime.strptime(str(date_debut_contrat), '%d/%m/%Y')
filt_session_end_date_ISODATE = datetime.strptime(str(date_fin_contrat), '%d/%m/%Y')
local_qry_tache_agenda = ([
{"$match": {'_id': rh_id_Object}},
{'$lookup': {
'from': 'agenda',
"let": {"rh_id": {'$toString': "$_id"}, 'rh_partner_owner_recid': '$partner_recid'},
'pipeline': [
{'$match':
{'$expr':
{'$and':
[
event_type_filter,
{'$eq': ["$valide", "1"]},
{'$eq': ["$related_collection_recid", '$$rh_id']},
{'$eq': ["$partner_owner_recid", '$$rh_partner_owner_recid']},
{'$gte': [{'$toDate': "$event_start"}, filt_session_start_date_ISODATE]},
{'$lte': [{'$toDate': "$event_start"}, filt_session_end_date_ISODATE]}
]
}
}
},
],
'as': 'collection_agenda'
}
},
{
'$unwind': '$collection_agenda'
}
])
#print(" ### local_qry_tache_agenda ici pipe_qry = ", local_qry_tache_agenda)
for retval_agenda in MYSY_GV.dbname['ressource_humaine'].aggregate(local_qry_tache_agenda):
# print(" ### retval_agenda Trouvé = ", retval_agenda)
agenda_id_Object = ObjectId(str(retval_agenda['_id']))
retval_agenda['_id'] = str(agenda_id_Object)
retval_agenda['collection_agenda']['_id'] = str(retval_agenda['collection_agenda']['_id'])
if ("event_start" in retval_agenda['collection_agenda'].keys()):
retval_agenda['collection_agenda']['agenda_date_jour'] = str(
datetime.strptime(str(retval_agenda['collection_agenda']['event_end'])[0:16],
'%Y-%m-%dT%H:%M').strftime("%d/%m/%Y"))
else:
retval_agenda['collection_agenda']['agenda_date_jour'] = ""
event_duration_second = datetime.strptime(str(retval_agenda['collection_agenda']['event_end'])[0:16],
'%Y-%m-%dT%H:%M') - datetime.strptime(
str(retval_agenda['collection_agenda']['event_start'])[0:16], '%Y-%m-%dT%H:%M')
event_duration_second = event_duration_second.total_seconds()
event_duration_hour = round(
divmod(event_duration_second, 3600)[0] + divmod(event_duration_second, 3600)[1] / 3600, 2)
retval_agenda['collection_agenda']['event_duration_second'] = str(event_duration_second)
retval_agenda['collection_agenda']['event_duration_hour'] = str(event_duration_hour)
json_agenda_formatted_str = json.dumps(retval_agenda, indent=2)
if ("collection_agenda" in retval_agenda.keys() and "partner_owner_recid" in retval_agenda[
'collection_agenda'].keys()):
new_node = retval_agenda['collection_agenda']
retval['Tab_agenda'].append(new_node)
# print(" ### NODE ADDED = ", new_node)
json_formatted_str = json.dumps(retval, indent=2)
#print(" ### Final Line : ", json_formatted_str)
tab_lines_employe_by_contract.append(retval)
local_status, local_retval = Format_employee_contrat_agenda_events(tab_lines_employe_by_contract)
if (local_status is False):
return local_status, local_retval
RetObject = []
cpt = 1
for val in local_retval:
val['id'] = str(cpt)
RetObject.append(mycommon.JSONEncoder().encode(val))
cpt = cpt + 1
tab_lines_employe_by_contract_json_formatted_str = json.dumps(val, indent=2)
#print(" ### Final Line " + str(cpt) + " : ", tab_lines_employe_by_contract_json_formatted_str)
#print(" RetObject = ", RetObject)
print(' on a ' + str(cpt) + ' lignes ')
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 le tableau des tache et avec les cout"
"""
Cette fonction prend un dictionnaire qui rattache chaque evenement (agenda : type planning) au
contrat en cours (+les données de l'employé) et retourne une dictionnaire reformaté de manière
à avoir une ligne par evenement + toutes les data du contrat en face
"""
def Format_employee_contrat_agenda_events(tab_diction):
try:
return_tab = []
for val in tab_diction:
#print(" #### Debut traitement de la ligne " + str(val))
for event_data in val['Tab_agenda']:
new_node = {}
new_node['rh_id'] = val['_id']
new_node['rh_partner_recid'] = val['partner_recid']
new_node['rh_civilite'] = val['civilite']
new_node['rh_nom'] = val['nom']
new_node['rh_prenom'] = val['prenom']
new_node['rh_email'] = val['email']
new_node['rh_telephone_mobile'] = val['telephone_mobile']
new_node['rh_ismanager'] = val['ismanager']
new_node['rh_fonction'] = val['fonction']
new_node['rh_telephone'] = val['telephone']
if( "purchase_price_group_id" in val.keys() ):
new_node['rh_purchase_price_group_id'] = val['purchase_price_group_id']
else:
new_node['rh_purchase_price_group_id'] = ""
if ("date_naissance" in val.keys()):
new_node['rh_date_naissance'] = val['date_naissance']
else:
new_node['rh_date_naissance'] = ""
if ("adr_adresse" in val.keys()):
new_node['rh_adr_adresse'] = val['adr_adresse']
else:
new_node['rh_date_naissance'] = ""
if ("adr_code_postal" in val.keys()):
new_node['rh_adr_code_postal'] = val['adr_code_postal']
else:
new_node['rh_date_naissance'] = ""
if ("adr_ville" in val.keys()):
new_node['rh_adr_ville'] = val['adr_ville']
else:
new_node['rh_adr_ville'] = ""
if ("adr_pays" in val.keys()):
new_node['rh_adr_pays'] = val['adr_pays']
else:
new_node['rh_adr_pays'] = ""
if ("collection_ressource_humaine_contrat" in val.keys()):
if ("date_debut" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_date_debut'] = val['collection_ressource_humaine_contrat']['date_debut']
else:
new_node['rh_contrat_date_debut'] = ""
if ("date_fin" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_date_fin'] = val['collection_ressource_humaine_contrat']['date_fin']
else:
new_node['rh_contrat_date_fin'] = ""
if ("type_contrat" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_type_contrat'] = val['collection_ressource_humaine_contrat'][
'type_contrat']
else:
new_node['rh_contrat_type_contrat'] = ""
if ("type_employe" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_type_employe'] = val['collection_ressource_humaine_contrat'][
'type_employe']
else:
new_node['rh_contrat_type_employe'] = ""
if ("cout" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_cout'] = val['collection_ressource_humaine_contrat']['cout']
else:
new_node['rh_contrat_cout'] = ""
if ("periodicite" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_periodicite'] = val['collection_ressource_humaine_contrat']['periodicite']
else:
new_node['rh_contrat_periodicite'] = ""
if ("quantite" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_quantite'] = val['collection_ressource_humaine_contrat']['quantite']
else:
new_node['rh_contrat_quantite'] = ""
if ("groupe_prix_achat_id" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_groupe_prix_achat_id'] = val['collection_ressource_humaine_contrat'][
'groupe_prix_achat_id']
else:
new_node['rh_contrat_groupe_prix_achat_id'] = ""
if ("comment" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_comment'] = val['collection_ressource_humaine_contrat']['comment']
else:
new_node['rh_contrat_comment'] = ""
if ("groupe_prix_achat_code" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_groupe_prix_achat_code'] = val['collection_ressource_humaine_contrat'][ 'groupe_prix_achat_code']
else:
new_node['rh_contrat_groupe_prix_achat_code'] = ""
if ("groupe_prix_achat_cout" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_groupe_prix_achat_cout'] = val['collection_ressource_humaine_contrat']['groupe_prix_achat_cout']
else:
new_node['rh_contrat_groupe_prix_achat_cout'] = ""
if ("groupe_prix_achat_periodicite" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_groupe_prix_achat_periodicite'] = \
val['collection_ressource_humaine_contrat']['groupe_prix_achat_periodicite']
else:
new_node['rh_contrat_groupe_prix_achat_periodicite'] = ""
# Traitement des données de l'evement dans l'agenda
new_node['rh_event_planning_event_type'] = event_data['event_type']
new_node['rh_event_planning_event_title'] = event_data['event_title']
new_node['rh_event_planning_event_start'] = str(datetime.strptime(str(event_data['event_start'] )[0:16], '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y %H:%M"))
new_node['rh_event_planning_event_end'] = str(datetime.strptime(str(event_data['event_end'] )[0:16], '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y %H:%M"))
new_node['rh_event_planning_agenda_date_jour'] = event_data['agenda_date_jour']
new_node['rh_event_planning_event_duration_hour'] = event_data['event_duration_hour']
new_node['rh_event_planning_event_duration_second'] = event_data['event_duration_second']
if ("comment" in event_data.keys()):
new_node['rh_event_planning_even_comment'] = event_data['comment']
else:
new_node['rh_event_planning_even_comment'] = ""
"""
# Calcul du cout total d'une tache
/!\ Le prix du contrat prend toujours le pas sur le prix rentré à la main.
C'est a dire que si un pour quelque raison que ce soit, sur la même période un employé
a un groupe de prix d'achat et une prix saisie à la main, alors les totaux seront calculés en se basant
sur le prix qui est dans le contrat
"""
if ("rh_contrat_groupe_prix_achat_id" in new_node.keys() and new_node['rh_contrat_groupe_prix_achat_id']
and "rh_contrat_groupe_prix_achat_periodicite" in new_node.keys() and new_node[
'rh_contrat_groupe_prix_achat_periodicite']
and "rh_event_planning_event_duration_hour" in new_node.keys() and new_node[
'rh_event_planning_event_duration_hour']
and "rh_contrat_groupe_prix_achat_cout" in new_node.keys() and new_node[
'rh_contrat_groupe_prix_achat_cout']):
if (str(new_node['rh_contrat_groupe_prix_achat_periodicite']) == "heure"):
new_node['rh_event_planning_event_cost'] = str(
mycommon.tryFloat(new_node['rh_contrat_groupe_prix_achat_cout']) * mycommon.tryFloat(
new_node['rh_event_planning_event_duration_hour']))
elif (str(new_node['rh_contrat_groupe_prix_achat_periodicite']) == "fixe"):
new_node['rh_event_planning_event_cost'] = str((new_node['rh_contrat_groupe_prix_achat_cout']))
elif ("rh_contrat_groupe_prix_achat_id" in new_node.keys() and str(
new_node['rh_contrat_groupe_prix_achat_id']) == ""
and "rh_contrat_periodicite" in new_node.keys() and new_node['rh_contrat_periodicite']
and "rh_event_planning_event_duration_hour" in new_node.keys() and new_node[
'rh_event_planning_event_duration_hour']
and "rh_contrat_cout" in new_node.keys() and new_node['rh_contrat_cout']):
if (str(new_node['rh_contrat_periodicite']) == "heure"):
new_node['rh_event_planning_event_cost'] = str(
mycommon.tryFloat(new_node['rh_contrat_cout']) * mycommon.tryFloat(
new_node['rh_event_planning_event_duration_hour']))
elif (str(new_node['rh_contrat_periodicite']) == "fixe"):
new_node['rh_event_planning_event_cost'] = str((new_node['rh_contrat_cout']))
else:
new_node['rh_event_planning_event_cost'] = "Impossible a calculer"
return_tab.append(new_node)
return True, return_tab
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 reformater et de normer le tableau des tâches et coûts "

File diff suppressed because it is too large Load Diff

View File

@ -295,8 +295,7 @@ def Add_Update_SessionFormation(diction):
return False, " -Formation : "+str(code_session)+" : La date de fin n'est pas au format jj/mm/aaaa "
if (datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(
str(diction['date_fin'])[0:10], '%d/%m/%Y')):
if (datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(str(diction['date_fin'])[0:10], '%d/%m/%Y')):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " Session de Formation : La date debut " + str(

12
main.py
View File

@ -6855,7 +6855,17 @@ def TBD_RH_01_Export_Dashbord_To_Csv(token, user_dashbord_id):
else:
return False
"""
API/ TBD / QERY / Ressources Humaines avec le cout par tache réalisée
"""
@app.route('/myclass/api/Get_Humain_Ressource_With_Planning_And_Cost/', methods=['POST','GET'])
@crossdomain(origin='*')
def Get_Humain_Ressource_With_Planning_And_Cost():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Get_Humain_Ressource_With_Planning_And_Cost payload = ",payload)
status, retval = ressources_humaines_tbd_qries.Get_Humain_Ressource_With_Planning_And_Cost(payload)
return jsonify(status=status, message=retval)
if __name__ == '__main__':

View File

@ -730,6 +730,9 @@ def CheckisDate(mydate):
# mydate doit etre au format : jj/mm/aaaa
try:
#print(" analyse de "+mydate)
if( str(mydate).strip() == ""):
return False
val = datetime.strptime(str(mydate).strip(), '%d/%m/%Y')
return True

View File

@ -262,6 +262,8 @@ def Update_Group_Purchase_Price(diction):
"""
Suppression d'un groupe de prix d'achat
/!\ :
Si le groupe de prix est deja utilisé, alors il est impossible de le supprimer
"""
def Delete_Group_Purchase_Price(diction):
try:

View File

@ -3358,7 +3358,7 @@ def Add_Employee_Contrat(diction):
Verification des input acceptés
"""
field_list = ['token', 'rh_id', 'date_debut', 'date_fin', 'type_contrat',
'type_employe', 'cout', 'groupe_prix_achat_id', 'quantite', 'comment']
'type_employe', 'cout', 'groupe_prix_achat_id', 'quantite', 'comment', 'periodicite']
incom_keys = diction.keys()
for val in incom_keys:
@ -3419,6 +3419,54 @@ def Add_Employee_Contrat(diction):
3]) + " - L'identifiant du groupe d'achat est invalide ")
return False, " L'identifiant du groupe d'achat est invalide "
price_grp_data = MYSY_GV.dbname['purchase_prices'].find_one(
{'_id': ObjectId(str(diction['groupe_prix_achat_id'])),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(my_partner['recid'])})
"""
Verifier que les dates du groupe de prix sont valident pendant tout le contrat
"""
if (datetime.strptime(str(price_grp_data['date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(
str(diction['date_debut'])[0:10], '%d/%m/%Y')):
mycommon.myprint(str(inspect.stack()[0][3]) + " La date de début du contrat " + str(
datetime.strptime(str(diction['date_debut'])[0:10],
'%d/%m/%Y')) + " est antérieure à la date de début de validité du groupe de prix d'achat " + str(
datetime.strptime(str(price_grp_data['date_debut'])[0:10], '%d/%m/%Y')) + " ")
return False, " La date de début du contrat " + str(
datetime.strptime(str(diction['date_debut'])[0:10],
'%d/%m/%Y')) + " est antérieure à la date de début de validité du groupe de prix d'achat " + str(
datetime.strptime(str(price_grp_data['date_debut'])[0:10], '%d/%m/%Y')) + " "
if (datetime.strptime(str(price_grp_data['date_fin'])[0:10], '%d/%m/%Y') < datetime.strptime(
str(diction['date_fin'])[0:10], '%d/%m/%Y')):
mycommon.myprint(str(inspect.stack()[0][3]) + " La date de fin du contrat " + str(
datetime.strptime(str(diction['date_fin'])[0:10],
'%d/%m/%Y')) + " est postérieure à la date de début de validité du groupe de prix d'achat " + str(
datetime.strptime(str(price_grp_data['date_fin'])[0:10], '%d/%m/%Y')) + " ")
return False, " La date de début du contrat " + str(
datetime.strptime(str(diction['date_debut'])[0:10],
'%d/%m/%Y')) + " est antérieure à la date de début de validité du groupe de prix d'achat " + str(
datetime.strptime(str(price_grp_data['date_debut'])[0:10], '%d/%m/%Y')) + " "
else:
"""
Si groupe_prix_achat_id est vide, alors il me faut obligatoirement
le prix et la periodicité
"""
if ("cout" not in diction.keys() or str(diction['cout']).strip() == ""):
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le prix est obligatoire ")
return False, " Le prix est obligatoire"
if ("periodicite" not in diction.keys() or str(diction['periodicite']).strip() == ""):
mycommon.myprint(str(
inspect.stack()[0][3]) + " La périodicite est obligatoire ")
return False, " La périodicite est obligatoire"
# S'il ya des date, verifier la validité des dates
@ -3551,7 +3599,7 @@ def Update_Employee_Contrat(diction):
Verification des input acceptés
"""
field_list = ['token', '_id', 'rh_id', 'date_debut', 'date_fin', 'type_contrat',
'type_employe', 'cout', 'groupe_prix_achat_id', 'quantite', 'comment']
'type_employe', 'cout', 'groupe_prix_achat_id', 'quantite', 'comment', 'periodicite']
incom_keys = diction.keys()
for val in incom_keys:
@ -3585,6 +3633,12 @@ def Update_Employee_Contrat(diction):
return local_status, my_partner
if( "periodicite" in diction.keys() and diction['periodicite']):
if( diction['periodicite'] not in MYSY_GV.PURCHASE_PRICE_PERIODICITY):
mycommon.myprint(
str(inspect.stack()[0][3]) + " La périodicité est invalide ")
return False, " La périodicité est invalide "
# Verifier que le contrat existe et est valide
is_contrat_valide = MYSY_GV.dbname['ressource_humaine_contrat'].count_documents({'_id':ObjectId(str(diction['_id'])),
'valide': '1',
@ -3596,6 +3650,8 @@ def Update_Employee_Contrat(diction):
str(inspect.stack()[0][3]) + " L'identifiant du contrat est invalide ")
return False, " L'identifiant du contrat est invalide "
# Verifier que la ressource_humaine est valide
is_rh_id_valide = MYSY_GV.dbname['ressource_humaine'].count_documents({'_id': ObjectId(str(diction['rh_id'])),
'valide': '1',
@ -3627,23 +3683,6 @@ def Update_Employee_Contrat(diction):
inspect.stack()[0][3]) + " La date de fin n'est pas au format jj/mm/aaaa.")
return False, " La date de fin n'est pas au format jj/mm/aaaa. "
# Verifier que 'groupe_prix_achat_id' existe si dans diction
groupe_prix_achat_id = ""
if ("groupe_prix_achat_id" in diction.keys()):
if diction['groupe_prix_achat_id']:
groupe_prix_achat_id = diction['groupe_prix_achat_id']
if (MYSY_GV.dbname['purchase_prices'].count_documents(
{'_id': ObjectId(str(diction['groupe_prix_achat_id'])),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(my_partner['recid'])}) != 1):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - L'identifiant du groupe d'achat est invalide ")
return False, " L'identifiant du groupe d'achat est invalide "
# verifier la cohérence des dates
@ -3697,6 +3736,45 @@ def Update_Employee_Contrat(diction):
3]) + " La date de fin " + str(diction['date_debut']) + " chevauche un autre contrat ")
return False, " La date de fin de contrat" + str(diction['date_debut']) + " chevauche un autre contrat"
"""
# Verifier que 'groupe_prix_achat_id' existe si dans diction
01/01/2024 : /!\ Important :
Si le contrat est rattaché à un groupe de prix, alors verifier que
les dates de début et de fin du contrat ne sont pas en contration avec les dates de validé
du groupe de prix.
"""
groupe_prix_achat_id = ""
if ("groupe_prix_achat_id" in diction.keys()):
if diction['groupe_prix_achat_id']:
groupe_prix_achat_id = diction['groupe_prix_achat_id']
if (MYSY_GV.dbname['purchase_prices'].count_documents(
{'_id': ObjectId(str(diction['groupe_prix_achat_id'])),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(my_partner['recid'])}) != 1):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - L'identifiant du groupe d'achat est invalide ")
return False, " L'identifiant du groupe d'achat est invalide "
price_grp_data = MYSY_GV.dbname['purchase_prices'].find_one(
{'_id': ObjectId(str(diction['groupe_prix_achat_id'])),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(my_partner['recid'])})
if (datetime.strptime(str(price_grp_data['date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y')):
mycommon.myprint(str(inspect.stack()[0][3]) + " La date de début du contrat "+str(datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y')) +" est antérieure à la date de début de validité du groupe de prix d'achat "+str(datetime.strptime(str(price_grp_data['date_debut'])[0:10], '%d/%m/%Y')) +" ")
return False, " La date de début du contrat "+str(datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y')) +" est antérieure à la date de début de validité du groupe de prix d'achat "+str(datetime.strptime(str(price_grp_data['date_debut'])[0:10], '%d/%m/%Y')) +" "
if (datetime.strptime(str(price_grp_data['date_fin'])[0:10], '%d/%m/%Y') < datetime.strptime(str(diction['date_fin'])[0:10], '%d/%m/%Y')):
mycommon.myprint(str(inspect.stack()[0][3]) + " La date de fin du contrat "+str(datetime.strptime(str(diction['date_fin'])[0:10], '%d/%m/%Y')) +" est postérieure à la date de début de validité du groupe de prix d'achat "+str(datetime.strptime(str(price_grp_data['date_fin'])[0:10], '%d/%m/%Y')) +" ")
return False, " La date de début du contrat "+str(datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y')) +" est antérieure à la date de début de validité du groupe de prix d'achat "+str(datetime.strptime(str(price_grp_data['date_debut'])[0:10], '%d/%m/%Y')) +" "
# Verifier que le cout est un decimal
if ("cout" in diction.keys() and diction['cout']):
local_status, local_retval = mycommon.IsFloat(diction['cout'])

View File

@ -808,36 +808,16 @@ def test_web_service(diction):
"""
local_qry = ( [
tab_lines_employe_by_contract = []
"""
Etape 1: Récuperation des donnée employé avec les contrat associés
"""
qry_employe_contrat = ( [
{ '$match': {'_id':ObjectId('6509a1adaca6e5023d7af487')}},
{'$lookup': {
'from': 'agenda',
'let': { 'rh_id': {'$toString': '$_id'} , 'rh_partner_owner_recid':'$partner_recid'},
'pipeline': [
{'$match':
{'$expr':
{'$and':
[
{'$eq': ['$valide', '1']},
{'$eq': ['$related_collection_recid', '$$rh_id']},
{'$eq': ['$partner_owner_recid', '$$rh_partner_owner_recid']}
]
}
}
},
{"$project": {"_id": 0,} }
],
'as': 'collection_agenda'
}
},
{'$lookup': {
'from': 'ressource_humaine_contrat',
'let': { 'rh_id': {'$toString': '$_id'} , 'rh_partner_owner_recid':'$partner_recid'},
@ -863,42 +843,356 @@ def test_web_service(diction):
'as': 'collection_ressource_humaine_contrat'
}
},
{
'$unwind':'$collection_ressource_humaine_contrat'
}
])
cpt = 0
for retval in MYSY_GV.dbname['ressource_humaine'].aggregate(local_qry):
print(" ### retval = ",retval)
for retval in MYSY_GV.dbname['ressource_humaine'].aggregate(qry_employe_contrat):
#print(" ### retval = ", retval)
cpt = cpt +1
cpt = cpt + 1
del retval['_id']
#del retval['collection_agenda']['_id']
#del retval['collection_ressource_humaine_contrat']['_id']
print(" ### retval = ", retval)
json_string = json.dumps(retval)
rh_id_Object = ObjectId(str(retval['_id']))
retval['_id'] = str(rh_id_Object)
"""
Si le contrat est lié à un groupe de prix, alors aller chercher les elements du groupe de prix
"""
if( "groupe_prix_achat_id" in retval['collection_ressource_humaine_contrat'].keys() and retval['collection_ressource_humaine_contrat']['groupe_prix_achat_id'] ):
price_grp_data = MYSY_GV.dbname['purchase_prices'].find_one({'_id':ObjectId(str(retval['collection_ressource_humaine_contrat']['groupe_prix_achat_id'] )),
'valide':'1',
'locked':'0',
'partner_owner_recid':str(retval['collection_ressource_humaine_contrat']['partner_owner_recid']),
})
if( price_grp_data and "prix" in price_grp_data.keys() and "periodicite" in price_grp_data.keys()):
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_cout'] = str(price_grp_data['prix'])
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_periodicite'] = str(price_grp_data['periodicite'])
else:
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_cout'] = ""
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_periodicite'] = ""
else:
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_cout'] = ""
retval['collection_ressource_humaine_contrat']['groupe_prix_achat_periodicite'] = ""
retval['Tab_agenda'] = []
"""
Aller chercher toutes taches valides entre les date du contrat
"""
date_debut_contrat = ""
date_fin_contrat = ""
if( "collection_ressource_humaine_contrat" in retval.keys() and "date_debut" in retval['collection_ressource_humaine_contrat'].keys() ):
date_debut_contrat = retval['collection_ressource_humaine_contrat']['date_debut']
if ("collection_ressource_humaine_contrat" in retval.keys() and "date_fin" in retval[
'collection_ressource_humaine_contrat'].keys()):
date_fin_contrat = retval['collection_ressource_humaine_contrat']['date_fin']
print(" ### date_debut_contrat = ", date_debut_contrat)
print(" ### date_fin_contrat = ", date_fin_contrat)
if( mycommon.CheckisDate(date_debut_contrat) is False or mycommon.CheckisDate(date_fin_contrat) is False ) :
mycommon.myprint(str(
inspect.stack()[0][3]) + " Les dates de debut et/ou fin de contrat de l'employé "+str(retval['nom']+" "+retval['prenom']) +" ne sont au format jj/mm/aaaa.")
return False, " Les dates de debut et/ou fin de contrat de l'employé "+str(retval['nom']+" "+retval['prenom']) +" ne sont au format jj/mm/aaaa. "
#json_object = json.loads(str(retval))
print(" ### Du " + str(date_debut_contrat) + " Au " + str(
date_fin_contrat) + " les taches de type planning trouvées sont : ")
"""
Etape 2 :
Aller recuperer les taches dans les agendas
"""
event_type_filter = {'$eq': ["$event_type", "planning"]}
filt_session_start_date_ISODATE = datetime.strptime(str(date_debut_contrat), '%d/%m/%Y')
filt_session_end_date_ISODATE = datetime.strptime(str(date_fin_contrat), '%d/%m/%Y')
local_qry_tache_agenda = ([
{"$match": {'_id': rh_id_Object}},
{'$lookup': {
'from': 'agenda',
"let": {"rh_id": {'$toString': "$_id"}, 'rh_partner_owner_recid': '$partner_recid'},
'pipeline': [
{'$match':
{'$expr':
{'$and':
[
event_type_filter,
{'$eq': ["$valide", "1"]},
{'$eq': ["$related_collection_recid", '$$rh_id']},
{'$eq': ["$partner_owner_recid", '$$rh_partner_owner_recid']},
{'$gte': [{'$toDate': "$event_start"}, filt_session_start_date_ISODATE]},
{'$lte': [{'$toDate': "$event_start"}, filt_session_end_date_ISODATE]}
]
}
}
},
],
'as': 'collection_agenda'
}
},
{
'$unwind': '$collection_agenda'
}
])
print(" ### local_qry_tache_agenda ici pipe_qry = ", local_qry_tache_agenda)
for retval_agenda in MYSY_GV.dbname['ressource_humaine'].aggregate(local_qry_tache_agenda):
#print(" ### retval_agenda Trouvé = ", retval_agenda)
agenda_id_Object = ObjectId(str(retval_agenda['_id']))
retval_agenda['_id'] = str(agenda_id_Object)
retval_agenda['collection_agenda']['_id'] = str(retval_agenda['collection_agenda']['_id'])
if ("event_start" in retval_agenda['collection_agenda'].keys()):
retval_agenda['collection_agenda']['agenda_date_jour'] = str(datetime.strptime(str(retval_agenda['collection_agenda']['event_end'])[0:16], '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y"))
else:
retval_agenda['collection_agenda']['agenda_date_jour'] = ""
event_duration_second = datetime.strptime(str(retval_agenda['collection_agenda']['event_end'])[0:16],'%Y-%m-%dT%H:%M') - datetime.strptime(str(retval_agenda['collection_agenda']['event_start'])[0:16], '%Y-%m-%dT%H:%M')
event_duration_second = event_duration_second.total_seconds()
event_duration_hour = round(divmod(event_duration_second, 3600)[0] + divmod(event_duration_second, 3600)[1] / 3600, 2)
retval_agenda['collection_agenda']['event_duration_second'] = str(event_duration_second)
retval_agenda['collection_agenda']['event_duration_hour'] = str(event_duration_hour)
json_agenda_formatted_str = json.dumps(retval_agenda, indent=2)
if( "collection_agenda" in retval_agenda.keys() and "partner_owner_recid" in retval_agenda['collection_agenda'].keys()):
new_node = retval_agenda['collection_agenda']
retval['Tab_agenda'].append(new_node)
#print(" ### NODE ADDED = ", new_node)
print(" ### retval_agenda = ", json_agenda_formatted_str)
json_formatted_str = json.dumps(retval, indent=2)
print(json_formatted_str)
print(" ### Final Line : ", json_formatted_str)
tab_lines_employe_by_contract.append(retval)
print(' on a '+str(cpt)+' lignes ')
local_status, local_retval = format_emplee_contrat_agenda_events(tab_lines_employe_by_contract)
if( local_status is False):
return local_status, local_retval
print(" #### local_retval = ", local_retval)
cpt = 0
print(" =================== ")
for val in local_retval :
tab_lines_employe_by_contract_json_formatted_str = json.dumps(val, indent=2)
print(" ### Final Line "+str(cpt)+" : ", tab_lines_employe_by_contract_json_formatted_str)
cpt = cpt + 1
print(' on a ' + str(cpt) + ' lignes ')
"""tab_lines_employe_by_contract_json_formatted_str = json.dumps(tab_lines_employe_by_contract, indent=2)
print(" ### Final Line : ", tab_lines_employe_by_contract_json_formatted_str)
print(' on a ' + str(cpt) + ' lignes ')
"""
return True, "Test WebService OK Diction "
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, "Test WebService KOOO"
"""
Cette fonction prend un dictionnaire qui rattache chaque evenement (agenda : type planning) au
contrat en cours (+les données de l'employé) et retourne une dictionnaire reformaté de manière
à avoir une ligne par evenement + toutes les data du contrat en face
"""
def format_emplee_contrat_agenda_events(tab_diction):
try:
return_tab = []
for val in tab_diction:
print(" #### Debut traitement de la ligne "+str(val) )
for event_data in val['Tab_agenda'] :
new_node = {}
new_node['rh_id'] = val['_id']
new_node['rh_partner_recid'] = val['partner_recid']
new_node['rh_civilite'] = val['civilite']
new_node['rh_nom'] = val['nom']
new_node['rh_prenom'] = val['prenom']
new_node['rh_email'] = val['email']
new_node['rh_telephone_mobile'] = val['telephone_mobile']
new_node['rh_ismanager'] = val['ismanager']
new_node['rh_fonction'] = val['fonction']
new_node['rh_telephone'] = val['telephone']
new_node['rh_purchase_price_group_id'] = val['purchase_price_group_id']
new_node['rh_date_naissance'] = val['date_naissance']
new_node['rh_adr_adresse'] = val['adr_adresse']
new_node['rh_adr_code_postal'] = val['adr_code_postal']
new_node['rh_adr_ville'] = val['adr_ville']
new_node['rh_adr_pays'] = val['adr_pays']
if ("collection_ressource_humaine_contrat" in val.keys()):
if( "date_debut" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_date_debut'] = val['collection_ressource_humaine_contrat']['date_debut']
else:
new_node['rh_contrat_date_debut'] = ""
if ("date_fin" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_date_fin'] = val['collection_ressource_humaine_contrat']['date_fin']
else:
new_node['rh_contrat_date_fin'] = ""
if ("type_contrat" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_type_contrat'] = val['collection_ressource_humaine_contrat']['type_contrat']
else:
new_node['rh_contrat_type_contrat'] = ""
if( "type_employe" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_type_employe'] = val['collection_ressource_humaine_contrat']['type_employe']
else:
new_node['rh_contrat_type_employe'] = ""
if( "cout" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_cout'] = val['collection_ressource_humaine_contrat']['cout']
else:
new_node['rh_contrat_cout'] = ""
if( "periodicite" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_periodicite'] = val['collection_ressource_humaine_contrat']['periodicite']
else:
new_node['rh_contrat_periodicite'] = ""
if( "quantite" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_quantite'] = val['collection_ressource_humaine_contrat']['quantite']
else:
new_node['rh_contrat_quantite'] = ""
if( "groupe_prix_achat_id" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_groupe_prix_achat_id'] = val['collection_ressource_humaine_contrat']['groupe_prix_achat_id']
else:
new_node['rh_contrat_groupe_prix_achat_id'] = ""
if( "comment" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_comment'] = val['collection_ressource_humaine_contrat']['comment']
else:
new_node['rh_contrat_comment'] = ""
if( "groupe_prix_achat_cout" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_groupe_prix_achat_cout'] = val['collection_ressource_humaine_contrat']['groupe_prix_achat_cout']
else:
new_node['rh_contrat_groupe_prix_achat_cout'] = ""
if( "groupe_prix_achat_periodicite" in val['collection_ressource_humaine_contrat'].keys()):
new_node['rh_contrat_groupe_prix_achat_periodicite'] = val['collection_ressource_humaine_contrat']['groupe_prix_achat_periodicite']
else:
new_node['rh_contrat_groupe_prix_achat_periodicite'] = ""
# Traitement des données de l'evement dans l'agenda
new_node['rh_event_planning_event_type'] = event_data['event_type']
new_node['rh_event_planning_event_title'] = event_data['event_title']
new_node['rh_event_planning_event_start'] = event_data['event_start']
new_node['rh_event_planning_event_end'] = event_data['event_end']
new_node['rh_event_planning_agenda_date_jour'] = event_data['agenda_date_jour']
new_node['rh_event_planning_event_duration_hour'] = event_data['event_duration_hour']
new_node['rh_event_planning_event_duration_second'] = event_data['event_duration_second']
if( "comment" in event_data.keys()):
new_node['rh_event_planning_even_comment'] = event_data['comment']
else:
new_node['rh_event_planning_even_comment'] = ""
"""
# Calcul du cout total d'une tache
/!\ Le prix du contrat prend toujours le pas sur le prix rentré à la main.
C'est a dire que si un pour quelque raison que ce soit, sur la même période un employé
a un groupe de prix d'achat et une prix saisie à la main, alors les totaux seront calculés en se basant
sur le prix qui est dans le contrat
"""
if( "rh_contrat_groupe_prix_achat_id" in new_node.keys() and new_node['rh_contrat_groupe_prix_achat_id']
and "rh_contrat_groupe_prix_achat_periodicite" in new_node.keys() and new_node['rh_contrat_groupe_prix_achat_periodicite']
and "rh_event_planning_event_duration_hour" in new_node.keys() and new_node['rh_event_planning_event_duration_hour']
and "rh_contrat_groupe_prix_achat_cout" in new_node.keys() and new_node['rh_contrat_groupe_prix_achat_cout'] ):
if( str(new_node['rh_contrat_groupe_prix_achat_periodicite']) == "heure" ):
new_node['rh_event_planning_event_cost'] = str(mycommon.tryFloat(new_node['rh_contrat_groupe_prix_achat_cout'] ) * mycommon.tryFloat(new_node['rh_event_planning_event_duration_hour'] ) )
elif ( str(new_node['rh_contrat_groupe_prix_achat_periodicite']) == "fixe" ):
new_node['rh_event_planning_event_cost'] = str((new_node['rh_contrat_groupe_prix_achat_cout']) )
elif ( "rh_contrat_groupe_prix_achat_id" in new_node.keys() and str(new_node['rh_contrat_groupe_prix_achat_id']) == ""
and "rh_contrat_periodicite" in new_node.keys() and new_node['rh_contrat_periodicite']
and "rh_event_planning_event_duration_hour" in new_node.keys() and new_node['rh_event_planning_event_duration_hour']
and "rh_contrat_cout" in new_node.keys() and new_node['rh_contrat_cout']):
if (str(new_node['rh_contrat_periodicite']) == "heure"):
new_node['rh_event_planning_event_cost'] = str(
mycommon.tryFloat(new_node['rh_contrat_cout']) * mycommon.tryFloat(new_node['rh_event_planning_event_duration_hour']))
elif (str(new_node['rh_contrat_groupe_prix_achat_periodicite']) == "fixe"):
new_node['rh_event_planning_event_cost'] = str((new_node['rh_contrat_cout']))
else:
new_node['rh_event_planning_event_cost'] = "Impossible a calculer"
return_tab.append(new_node)
return True, return_tab
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, "Test WebService KOOO"
def flatten_data(y):
out = {}
def flatten(x, name=''):
if type(x) is dict:
for a in x:
flatten(x[a], name + a + '_')
elif type(x) is list:
i = 0
for a in x:
flatten(a, name + str(i) + '_')
i += 1
else:
out[name[:-1]] = x
flatten(y)
return out
def test_web_service2(diction):
try:
print(" #### ENVIRONNEMENT = "+str(MYSY_GV.MYSY_ENV)+" ")