273 lines
9.3 KiB
Python
273 lines
9.3 KiB
Python
"""
|
|
Ce fichier permet de gerer de tout ce qui a atrait aux ressources humaines.
|
|
c'est dire :
|
|
- enseignent
|
|
- cadre administratif
|
|
- employés,
|
|
etc
|
|
|
|
Une ressource humaine a toujours un profil (enseignant, cadre admin) et une fonction.
|
|
"""
|
|
|
|
import pymongo
|
|
from pymongo import MongoClient
|
|
import json
|
|
from bson import ObjectId
|
|
import re
|
|
from datetime import datetime
|
|
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
|
|
|
|
|
|
|
|
def Add_Ressource_Humaine(diction):
|
|
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "raison_sociale", "nom", "siret", "tva", "email",
|
|
"telephone", "website", "comment",'adr_adresse', 'adr_code_postal',
|
|
'adr_ville', 'adr_pays', 'profil', 'telephone_mobile', 'linkedin',
|
|
'facebook', 'twitter',
|
|
'prenom', 'fonction', 'civilite']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
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', "email", 'related_collection', 'related_collection_owner_email',]
|
|
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
|
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire. "
|
|
|
|
|
|
"""
|
|
Verification s'il n'existe pas un cient du partenaire qui porte la meme adresse email
|
|
"""
|
|
|
|
|
|
tmp_count = MYSY_GV.dbname['ressource_humaine'].count_documents({'email': str(diction['email']),
|
|
'valide': '1', 'partner_recid': my_partner['recid']})
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Il existe déjà un contact qui porte le même email principal = " +str(diction['email']))
|
|
|
|
return False, " - Vous avez déjà un contact qui a le même email principal "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
data = {}
|
|
data['partner_recid'] = my_partner['recid']
|
|
|
|
raison_sociale = ""
|
|
if ("raison_sociale" in diction.keys()):
|
|
if diction['raison_sociale']:
|
|
raison_sociale = diction['raison_sociale']
|
|
data['raison_sociale'] = diction['raison_sociale']
|
|
|
|
nom = ""
|
|
if ("nom" in diction.keys()):
|
|
if diction['nom']:
|
|
nom = diction['nom']
|
|
data['nom'] = diction['nom']
|
|
|
|
siret = ""
|
|
if ("siret" in diction.keys()):
|
|
if diction['siret']:
|
|
siret = diction['siret']
|
|
data['siret'] = diction['siret']
|
|
|
|
prenom = ""
|
|
if ("prenom" in diction.keys()):
|
|
if diction['prenom']:
|
|
prenom = diction['prenom']
|
|
data['prenom'] = diction['prenom']
|
|
|
|
fonction = ""
|
|
if ("fonction" in diction.keys()):
|
|
if diction['fonction']:
|
|
fonction = diction['fonction']
|
|
data['fonction'] = diction['fonction']
|
|
|
|
civilite = ""
|
|
if ("civilite" in diction.keys()):
|
|
if diction['civilite']:
|
|
civilite = diction['civilite']
|
|
data['civilite'] = diction['civilite']
|
|
|
|
|
|
|
|
adr_adresse = ""
|
|
if ("adr_adresse" in diction.keys()):
|
|
if diction['adr_adresse']:
|
|
adr_adresse = diction['adr_adresse']
|
|
data['adr_adresse'] = diction['adr_adresse']
|
|
|
|
adr_code_postal = ""
|
|
if ("adr_code_postal" in diction.keys()):
|
|
if diction['adr_code_postal']:
|
|
adr_code_postal = diction['adr_code_postal']
|
|
data['adr_code_postal'] = diction['adr_code_postal']
|
|
|
|
adr_ville = ""
|
|
if ("adr_ville" in diction.keys()):
|
|
if diction['adr_ville']:
|
|
adr_ville = diction['adr_ville']
|
|
data['adr_ville'] = diction['adr_ville']
|
|
|
|
adr_pays = ""
|
|
if ("adr_pays" in diction.keys()):
|
|
if diction['adr_pays']:
|
|
adr_pays = diction['siret']
|
|
data['adr_pays'] = diction['adr_pays']
|
|
|
|
tva = ""
|
|
if ("tva" in diction.keys()):
|
|
if diction['tva']:
|
|
tva = diction['tva']
|
|
data['tva'] = diction['tva']
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
email = diction['email']
|
|
data['email'] = diction['email']
|
|
if( mycommon.isEmailValide(email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - L'adresse email "+str(email)+" n'est pas valide")
|
|
|
|
return False, " - - L'adresse email "+str(email)+" n'est pas valide "
|
|
|
|
|
|
telephone = ""
|
|
if ("telephone" in diction.keys()):
|
|
if diction['telephone']:
|
|
telephone = diction['telephone']
|
|
data['telephone'] = diction['telephone']
|
|
|
|
telephone_mobile = ""
|
|
if ("telephone_mobile" in diction.keys()):
|
|
if diction['telephone_mobile']:
|
|
telephone_mobile = diction['telephone_mobile']
|
|
data['telephone_mobile'] = diction['telephone_mobile']
|
|
|
|
|
|
website = ""
|
|
if ("website" in diction.keys()):
|
|
if diction['website']:
|
|
website = diction['website']
|
|
data['website'] = diction['website']
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
comment = diction['comment']
|
|
data['comment'] = diction['comment']
|
|
|
|
linkedin = ""
|
|
if ("linkedin" in diction.keys()):
|
|
if diction['linkedin']:
|
|
linkedin = diction['linkedin']
|
|
data['linkedin'] = diction['linkedin']
|
|
|
|
facebook = ""
|
|
if ("facebook" in diction.keys()):
|
|
if diction['facebook']:
|
|
facebook = diction['facebook']
|
|
data['facebook'] = diction['facebook']
|
|
|
|
twitter = ""
|
|
if ("twitter" in diction.keys()):
|
|
if diction['twitter']:
|
|
twitter = diction['twitter']
|
|
data['twitter'] = diction['twitter']
|
|
|
|
|
|
profil = ""
|
|
if ("profil" in diction.keys()):
|
|
if diction['profil']:
|
|
profil = diction['profil']
|
|
data['profil'] = diction['profil']
|
|
if( type not in MYSY_GV.RESSOURCE_PROFIL):
|
|
mycommon.myprint(
|
|
"- Le type de contact "+str(type)+" n'est pas autorisé")
|
|
return False, "- Le type de contact "+str(type)+" n'est pas autorisé"
|
|
|
|
|
|
data['valide'] = '1'
|
|
data['locked'] = '0'
|
|
data['date_update'] = str(datetime.now())
|
|
|
|
# Creation du RecId
|
|
data['recid'] = mycommon.create_user_recid()
|
|
|
|
|
|
inserted_id = ""
|
|
inserted_id = MYSY_GV.dbname['ressource_humaine'].insert_one(data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le contact ")
|
|
return False, " Impossible de créer la ressource "
|
|
|
|
|
|
return True, " Le contact a été correctement créé"
|
|
|
|
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'ajouter la ressource "
|