359 lines
14 KiB
Python
359 lines
14 KiB
Python
"""
|
|
Ce document calqué sur la collection : base_document_automatic_setup
|
|
permet de gerer le paramettrage de l'envoi automatique des documents.
|
|
par exemple :
|
|
- les Convocations doivent etre envoyées 7 jours avant le début de la session
|
|
|
|
/!\ principe d'utilisation :
|
|
Il y aura un paramettrage par société qui va s'appliquer à tous les documents de la societe.
|
|
Ce paramettrage sera dubliqué sur chaque instance du document.
|
|
|
|
En suite, l'utilisation pourra décider de modifier exceptionnellement le paramettrage d'une instance du document.
|
|
|
|
C'est le meme principe que la gestion de la relance des devis
|
|
"""
|
|
from base64 import b64encode
|
|
|
|
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
|
|
|
|
|
|
|
|
"""
|
|
Ajout ou mise à jour d'un paramettrage
|
|
les champs :
|
|
- courrier_template_type_document_id : Id du type de document
|
|
- nb_jour_action : definit le nombre de avant ou après action (-5 = faire l'action 5 jours avant ..., +2 = faire l'action 2 après ...)
|
|
- action_target_date : Définit la date cible. exemple (start_session = Debut de la session, end_session = fin de la session, etc)
|
|
- collection_target : Définit la collection concernéer ( exe : session_formation)
|
|
|
|
/!\ : Pour un début on va rester sur des actions autours de sessions de formation
|
|
|
|
/!\ : Pour eviter les ecart de date trop long, une traitement automatique se trouver dans un intervalle de
|
|
+/- 30 jours avant ou après la session.
|
|
|
|
|
|
"""
|
|
def Add_Update_base_document_automatic_setup(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', 'courrier_template_type_document_ref_interne', 'nb_jour_action', 'action_target_date',
|
|
'collection_target', 'actif']
|
|
|
|
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', 'courrier_template_type_document_ref_interne', 'nb_jour_action', 'action_target_date',
|
|
'collection_target', 'actif']
|
|
|
|
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
|
|
|
|
|
|
my_token = diction['token']
|
|
|
|
"""
|
|
verifier que le courrier_template_type_document_id existe et est valide
|
|
"""
|
|
is_valide_courrier_template_type_document_id_count = MYSY_GV.dbname['courrier_template_type_document'].count_documents({'ref_interne':str(diction['courrier_template_type_document_ref_interne']),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if(is_valide_courrier_template_type_document_id_count != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du courrier_template_type_document_id est invalide ")
|
|
return False, " L'identifiant du courrier_template_type_document_id est invalide "
|
|
|
|
is_valide_courrier_template_type_document_id_data = MYSY_GV.dbname[
|
|
'courrier_template_type_document'].find_one(
|
|
{'ref_interne': str(diction['courrier_template_type_document_ref_interne']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
|
|
local_status, local_retval = mycommon.IsInt(str(diction['nb_jour_action']))
|
|
if (local_status is False):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][
|
|
3]) + " Le nombre de jours est invalide ")
|
|
return False, " Le nombre de jours est invalide "
|
|
|
|
my_id = str(is_valide_courrier_template_type_document_id_data['_id'])
|
|
|
|
|
|
|
|
del diction['_id']
|
|
del diction['token']
|
|
|
|
nom_document = ""
|
|
if( "nom" in is_valide_courrier_template_type_document_id_data.keys() ):
|
|
nom_document = is_valide_courrier_template_type_document_id_data['nom']
|
|
|
|
diction['nom_document'] = nom_document
|
|
|
|
if (my_id):
|
|
|
|
diction['date_update'] = str(datetime.now())
|
|
diction['update_by'] = str(my_partner['_id'])
|
|
result = MYSY_GV.dbname['base_document_automatic_setup'].find_one_and_update(
|
|
{'courrier_template_type_document_ref_interne': str(diction['courrier_template_type_document_ref_interne']),
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{"$set": diction},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if (result is None or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible d'ajouter ou mettre à jour la configuration du catalogue public (2) ")
|
|
return False, " Impossible d'ajouter ou mettre à jour la configuration du catalogue public (2) "
|
|
|
|
return True, " La configuration a été correctement mise à jour"
|
|
|
|
else:
|
|
|
|
diction['valide'] = "1"
|
|
diction['locked'] = "0"
|
|
diction['partner_owner_recid'] = str(my_partner['recid'])
|
|
diction['date_update'] = str(datetime.now())
|
|
diction['date_created'] = str(datetime.now())
|
|
diction['update_by'] = str(my_partner['_id'])
|
|
|
|
result = MYSY_GV.dbname['base_document_automatic_setup'].insert_one(diction)
|
|
|
|
return True, " La configuration du catalogue a été correctement ajoutée"
|
|
|
|
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 ou mettre à jour la configuration du document "
|
|
|
|
|
|
"""
|
|
Recuperation de la liste des documents parametrés pour un partenaire donné
|
|
"""
|
|
def Get_List_base_document_automatic_setup(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
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = my_partner['recid']
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['base_document_automatic_setup'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
# Recuperation des données du courrier_template_type_document
|
|
document_ref_interne = ""
|
|
document_type_doc = ""
|
|
document_type_nom = ""
|
|
if( "courrier_template_type_document_id" in user.keys()):
|
|
courrier_template_type_document_data = MYSY_GV.dbname['courrier_template_type_document'].find_one({'ref_interne':str(user['courrier_template_type_document_ref_interne']),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( courrier_template_type_document_data and "ref_interne" in courrier_template_type_document_data.keys() ):
|
|
document_ref_interne = courrier_template_type_document_data["ref_interne"]
|
|
|
|
if (courrier_template_type_document_data and "type_doc" in courrier_template_type_document_data.keys()):
|
|
document_type_doc = courrier_template_type_document_data["type_doc"]
|
|
|
|
if ( courrier_template_type_document_data and "nom" in courrier_template_type_document_data.keys()):
|
|
document_type_nom = courrier_template_type_document_data["nom"]
|
|
|
|
user['document_ref_interne'] = document_ref_interne
|
|
user['document_type_doc'] = document_type_doc
|
|
user['document_type_nom'] = document_type_nom
|
|
|
|
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
#print(" ### RetObject = ", RetObject);
|
|
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 thèmes "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des données d'un base_document_automatic_setup donné
|
|
"""
|
|
|
|
def Get_Given_base_document_automatic_setup(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
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = my_partner['recid']
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
data_cle['_id'] = ObjectId(str(diction['_id']))
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['base_document_automatic_setup'].find(data_cle).sort(
|
|
[("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
# Recuperation des données du courrier_template_type_document
|
|
document_ref_interne = ""
|
|
document_type_doc = ""
|
|
document_type_nom = ""
|
|
if ("courrier_template_type_document_id" in user.keys()):
|
|
courrier_template_type_document_data = MYSY_GV.dbname['courrier_template_type_document'].find_one(
|
|
{'_id': ObjectId(str(user['courrier_template_type_document_id'])),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (courrier_template_type_document_data and "ref_interne" in courrier_template_type_document_data.keys()):
|
|
document_ref_interne = courrier_template_type_document_data["ref_interne"]
|
|
|
|
if (courrier_template_type_document_data and "type_doc" in courrier_template_type_document_data.keys()):
|
|
document_type_doc = courrier_template_type_document_data["type_doc"]
|
|
|
|
if (courrier_template_type_document_data and "nom" in courrier_template_type_document_data.keys()):
|
|
document_type_nom = courrier_template_type_document_data["nom"]
|
|
|
|
user['document_ref_interne'] = document_ref_interne
|
|
user['document_type_doc'] = document_type_doc
|
|
user['document_type_nom'] = document_type_nom
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
# print(" ### RetObject = ", RetObject);
|
|
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 thèmes "
|