409 lines
16 KiB
Python
409 lines
16 KiB
Python
"""
|
|
Ce fichier permet de gerer la configuration des journée type
|
|
|
|
|
|
"""
|
|
|
|
|
|
import bson
|
|
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
|
|
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
|
|
|
|
|
|
"""
|
|
Ajout et mise à jour d'un modele de journée
|
|
"""
|
|
def Add_Update_Modele_Journee(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', 'modele_journee']
|
|
|
|
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'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '_id', 'modele_journee']
|
|
|
|
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 la liste des arguments ")
|
|
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
|
|
|
|
|
|
journee_model_id = ""
|
|
if ("_id" in diction.keys()):
|
|
if diction['_id']:
|
|
journee_model_id = diction['_id']
|
|
|
|
|
|
my_data = diction['modele_journee']
|
|
|
|
|
|
|
|
my_data_JSON = json.loads(str(my_data))
|
|
|
|
my_data_JSON['valide'] = '1'
|
|
my_data_JSON['locked'] = '0'
|
|
my_data_JSON['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
|
|
print(" #### my_data_JSON = ", my_data_JSON)
|
|
|
|
|
|
# Si journee_model_id est vide on est en mode creation, si non on est en mode mise à jour
|
|
if( str(journee_model_id).strip() != ""):
|
|
# Verifier si l'_id existe vraiment en base de donnée
|
|
is_journee_model_id_valide_exist = MYSY_GV.dbname['base_config_modele_journee'].count_documents({'_id':ObjectId(str(journee_model_id)),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_journee_model_id_valide_exist <= 0 ):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " L'identifiant du modèle est invalide ")
|
|
return False, " L'identifiant du modèle est invalide "
|
|
|
|
# Il s'agit d'une mise à jour
|
|
my_data_JSON['date_update'] = str(datetime.now())
|
|
my_data_JSON['update_by'] = str(my_partner['_id'])
|
|
|
|
result = MYSY_GV.dbname['base_config_modele_journee'].find_one_and_update(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'locked': '0'},
|
|
{"$set": my_data_JSON},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
else:
|
|
# Il s'agit d'une creation
|
|
result = MYSY_GV.dbname['base_config_modele_journee'].insert_one(my_data_JSON)
|
|
|
|
|
|
return True, " La configuration a été correctement ajoutée / mise à jour"
|
|
|
|
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 configuration "
|
|
|
|
|
|
"""
|
|
Recuperation d'un journée type en partant de l'_id
|
|
"""
|
|
def Get_Given_Modele_Journee(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_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','_id' ]
|
|
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 la liste des arguments ")
|
|
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
|
|
|
|
RetObject = []
|
|
|
|
qry = {'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
|
|
'locked': '0', '_id': ObjectId(str(diction['_id']))}
|
|
|
|
|
|
New_retVal = MYSY_GV.dbname['base_config_modele_journee'].find_one( qry)
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(New_retVal))
|
|
|
|
# print(" ### retval_json =", retval_json)
|
|
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 la liste des points de paramétrage "
|
|
|
|
|
|
"""
|
|
Recuperation d'un journée type en par defaut
|
|
"""
|
|
def Get_Default_Modele_Journee(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token',]
|
|
|
|
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 la liste des arguments ")
|
|
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
|
|
|
|
RetObject = []
|
|
|
|
qry = {'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
|
|
'locked': '0'}
|
|
|
|
New_retVal_count = MYSY_GV.dbname['base_config_modele_journee'].count_documents(qry)
|
|
|
|
if( New_retVal_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Plusieurs modèles existe. Les données sont incohérentes ")
|
|
return False, " Plusieurs modèles existe. Les données sont incohérentes",
|
|
|
|
elif (New_retVal_count <= 0):
|
|
# Aucun modèle pour ce partenaire, on va aller chercher le modèle par defaut de mysy
|
|
qry_mysy = {'partner_owner_recid': "default", 'valide': '1',
|
|
'locked': '0'}
|
|
|
|
New_retVal_count_mysy = MYSY_GV.dbname['base_config_modele_journee'].count_documents(qry_mysy)
|
|
if( New_retVal_count_mysy != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Aucun modèle de journée de travail n'est configuré dans le système ")
|
|
return False, " Aucun modèle de journée de travail n'est configuré dans le système ",
|
|
|
|
else:
|
|
New_retVal_mysy_data = MYSY_GV.dbname['base_config_modele_journee'].find_one( qry_mysy)
|
|
RetObject.append(mycommon.JSONEncoder().encode(New_retVal_mysy_data))
|
|
# print(" ### retval_json =", retval_json)
|
|
return True, RetObject
|
|
|
|
|
|
elif (New_retVal_count <= 1):
|
|
qry = {'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
|
|
'locked': '0'}
|
|
|
|
New_retVal_data = MYSY_GV.dbname['base_config_modele_journee'].find_one(qry)
|
|
RetObject.append(mycommon.JSONEncoder().encode(New_retVal_data))
|
|
# print(" ### retval_json =", retval_json)
|
|
return True, RetObject
|
|
|
|
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Impossible de trouver un modèle de journée de travail dans le système ")
|
|
return False, " Impossible de trouver un modèle de journée de travail dans le système ",
|
|
|
|
|
|
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 la liste des points de paramétrage (jounée de travail) "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des heures de debut et fin des journée.
|
|
Cette fonction est utilisé dans les planning en gle.
|
|
"""
|
|
def Get_Default_Debut_Fin_journee_Modele_Journee(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token',]
|
|
|
|
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 la liste des arguments ")
|
|
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
|
|
|
|
RetObject = []
|
|
|
|
qry = {'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
|
|
'locked': '0'}
|
|
|
|
New_retVal_count = MYSY_GV.dbname['base_config_modele_journee'].count_documents(qry)
|
|
|
|
if( New_retVal_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Plusieurs modèles existe. Les données sont incohérentes ")
|
|
return False, " Plusieurs modèles existe. Les données sont incohérentes",
|
|
|
|
elif (New_retVal_count <= 0):
|
|
# Aucun modèle pour ce partenaire, on va aller chercher le modèle par defaut de mysy
|
|
qry_mysy = {'partner_owner_recid': "default", 'valide': '1',
|
|
'locked': '0'}
|
|
|
|
New_retVal_count_mysy = MYSY_GV.dbname['base_config_modele_journee'].count_documents(qry_mysy)
|
|
if( New_retVal_count_mysy != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Aucun modèle de journée de travail n'est configuré dans le système ")
|
|
return False, " Aucun modèle de journée de travail n'est configuré dans le système ",
|
|
|
|
else:
|
|
New_retVal_mysy_data = MYSY_GV.dbname['base_config_modele_journee'].find_one( qry_mysy)
|
|
if ("debut_fin_journee" not in New_retVal_mysy_data.keys()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Votre configuration ne dispose pas d'un début et d'une fin de journée ")
|
|
return False, " Votre configuration ne dispose pas d'un début et d'une fin de journée ",
|
|
|
|
debut_fin_journee = New_retVal_mysy_data['debut_fin_journee']
|
|
RetObject.append(mycommon.JSONEncoder().encode(debut_fin_journee))
|
|
|
|
# print(" ### retval_json =", retval_json)
|
|
return True, RetObject
|
|
|
|
|
|
elif (New_retVal_count <= 1):
|
|
qry = {'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
|
|
'locked': '0'}
|
|
|
|
New_retVal_data = MYSY_GV.dbname['base_config_modele_journee'].find_one(qry)
|
|
if( "debut_fin_journee" not in New_retVal_data.keys()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Votre configuration ne dispose pas d'un début et d'une fin de journée ")
|
|
return False, " Votre configuration ne dispose pas d'un début et d'une fin de journée ",
|
|
|
|
|
|
debut_fin_journee = New_retVal_data['debut_fin_journee']
|
|
RetObject.append(mycommon.JSONEncoder().encode(debut_fin_journee))
|
|
# print(" ### retval_json =", retval_json)
|
|
return True, RetObject
|
|
|
|
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Impossible de trouver un modèle de journée de travail dans le système ")
|
|
return False, " Impossible de trouver un modèle de journée de travail dans le système ",
|
|
|
|
|
|
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 la liste des points de paramétrage (jounée de travail) "
|