2925 lines
124 KiB
Python
2925 lines
124 KiB
Python
"""
|
|
Ce fichier permet de gerer les ressources matériels
|
|
Par exemple :
|
|
- Les cartes
|
|
- Les projecteurs
|
|
- Les ordinateurs, imprimantes, scanner,
|
|
- Les livres,
|
|
- Les sales reunion
|
|
- Les empphithéatres
|
|
- etc
|
|
|
|
En gros toute ressources non humaine
|
|
|
|
Une ressource materiel est defini par :
|
|
- ref_interne, ref_externe, nom, description, detail, famille, marque, type (à definir), prix_achat (prix d'achat estimé), image, fournisseur, qty_stock (qté en stock),
|
|
"""
|
|
|
|
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
|
|
|
|
|
|
"""
|
|
La clé d'une ressource materielle est :
|
|
- la ref_interne
|
|
"""
|
|
def Add_Ressource_Materielle(diction):
|
|
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "ref_interne", "nom", "description", "detail", "famille",'marque',
|
|
'prix_achat', 'fournisseur', 'qty_stock', 'type', 'site_formation_id', "code_categorie",
|
|
'complement_adresse', 'capacite_ideale', 'capacite_max', 'acces_handicape', 'prix_achat_by']
|
|
|
|
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', "ref_interne", ]
|
|
|
|
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
|
|
|
|
|
|
"""
|
|
Verification s'il n'existe pas un matereiel avec la meme reference interne
|
|
"""
|
|
|
|
tmp_count = MYSY_GV.dbname['ressource_materielle'].count_documents({'ref_interne': str(diction['ref_interne']),
|
|
'valide': '1', 'partner_recid': my_partner['recid']})
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Il existe déjà un matereiel avec cette reference interne = " +str(diction['ref_interne']))
|
|
|
|
return False, " - Il existe déjà un matereiel avec cette reference interne " +str(diction['ref_interne'])+" "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
data = {}
|
|
data['partner_recid'] = my_partner['recid']
|
|
|
|
|
|
ref_interne = ""
|
|
if ("ref_interne" in diction.keys()):
|
|
if diction['ref_interne']:
|
|
ref_interne = diction['ref_interne']
|
|
if (len(str(ref_interne)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'ref_interne' fait plus de 255 caractères")
|
|
|
|
return False, " - Le champ 'ref_interne' fait plus de 255 caractères"
|
|
data['ref_interne'] = ref_interne
|
|
|
|
complement_adresse = ""
|
|
if ("complement_adresse" in diction.keys()):
|
|
if diction['complement_adresse']:
|
|
complement_adresse = diction['complement_adresse']
|
|
if (len(str(ref_interne)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'complement_adresse' fait plus de 500 caractères")
|
|
|
|
return False, " - Le champ 'complement_adresse' fait plus de 500 caractères"
|
|
data['complement_adresse'] = complement_adresse
|
|
|
|
capacite_ideale = "0"
|
|
if ("capacite_ideale" in diction.keys()):
|
|
if diction['capacite_ideale']:
|
|
capacite_ideale = diction['capacite_ideale']
|
|
local_status, new_participants = mycommon.IsInt(capacite_ideale)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'capacite_ideale' n'est pas un nombre entier")
|
|
return False, " Le champ 'capacite_ideale' n'est pas un nombre entier "
|
|
|
|
data['capacite_ideale'] = capacite_ideale
|
|
|
|
capacite_max = "0"
|
|
if ("capacite_max" in diction.keys()):
|
|
if diction['capacite_max']:
|
|
capacite_max = diction['capacite_max']
|
|
local_status, new_participants = mycommon.IsInt(capacite_max)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'capacite_max' n'est pas un nombre entier")
|
|
return False, " Le champ 'capacite_max' n'est pas un nombre entier "
|
|
|
|
data['capacite_max'] = capacite_max
|
|
|
|
acces_handicape = "0"
|
|
if ("acces_handicape" in diction.keys()):
|
|
if diction['acces_handicape']:
|
|
acces_handicape = diction['acces_handicape']
|
|
local_status, new_participants = mycommon.IsInt(acces_handicape)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'acces_handicape' doit etre '0' ou '1' ")
|
|
return False, "Le champ 'acces_handicape' doit etre '0' ou '1' "
|
|
|
|
data['acces_handicape'] = acces_handicape
|
|
|
|
prix_achat_by = ""
|
|
if( "prix_achat_by" in diction.keys() and diction['prix_achat_by']):
|
|
prix_achat_by = diction['prix_achat_by']
|
|
if( diction['prix_achat_by'] not in ['fixe', 'heure', 'jour', 'mois']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'prix_achat_by' doit etre 'fixe', 'heure', 'jour', 'mois' ")
|
|
return False, "Le champ 'prix_achat_by' doit etre 'fixe', 'heure', 'jour', 'mois' "
|
|
|
|
data['prix_achat_by'] = prix_achat_by
|
|
|
|
# Si la catégorie est fournie, alors verifier qu'elle existe, si non, mettre par defaut à 'autre"
|
|
code_categorie = "autre"
|
|
if( "code_categorie" in diction.keys() and diction['code_categorie']):
|
|
is_code_categorie_exist = MYSY_GV.dbname['ressource_materielle_categorie'].count_documents({'code':str(diction['code_categorie']).lower(),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':'default'})
|
|
|
|
if( is_code_categorie_exist != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du code categorie est invalide ")
|
|
|
|
return False, " L'identifiant du code categorie est invalide "
|
|
|
|
code_categorie = str(diction['code_categorie']).lower()
|
|
|
|
data['code_categorie'] = code_categorie
|
|
|
|
|
|
nom = ""
|
|
if ("nom" in diction.keys()):
|
|
if diction['nom']:
|
|
nom = diction['nom']
|
|
if (len(str(nom)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'nom' fait plus de 255 caractères")
|
|
|
|
return False, " - Le champ 'nom' fait plus de 255 caractères"
|
|
data['nom'] = nom
|
|
|
|
|
|
description = ""
|
|
if ("description" in diction.keys()):
|
|
if diction['description']:
|
|
description = diction['description']
|
|
if (len(str(description)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'description' fait plus de 500 caractères")
|
|
|
|
return False, " - Le champ 'Detail' fait plus de 500 caractères"
|
|
data['description'] = description
|
|
|
|
|
|
detail = ""
|
|
if ("detail" in diction.keys()):
|
|
if diction['detail']:
|
|
detail = diction['detail']
|
|
if(len(str(detail)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'Detail' fait plus de 255 caractères")
|
|
|
|
return False, " - Le champ 'Detail' fait plus de 255 caractères"
|
|
|
|
data['detail'] = detail
|
|
|
|
|
|
|
|
famille = ""
|
|
if ("famille" in diction.keys()):
|
|
if diction['famille']:
|
|
famille = diction['famille']
|
|
data['famille'] = famille
|
|
|
|
|
|
marque = ""
|
|
if ("marque" in diction.keys()):
|
|
if diction['marque']:
|
|
marque = diction['marque']
|
|
data['marque'] = marque
|
|
|
|
|
|
prix_achat = ""
|
|
if ("prix_achat" in diction.keys()):
|
|
if diction['prix_achat']:
|
|
prix_achat = diction['prix_achat']
|
|
local_status, local_val = mycommon.IsFloat(prix_achat)
|
|
if( local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le prix d'achat est invalide ")
|
|
|
|
return False, " - Le prix d'achat est invalide "
|
|
|
|
data['prix_achat'] = prix_achat
|
|
|
|
|
|
fournisseur = ""
|
|
if ("fournisseur" in diction.keys()):
|
|
if diction['fournisseur']:
|
|
fournisseur = diction['fournisseur']
|
|
data['fournisseur'] = fournisseur
|
|
|
|
type = ""
|
|
if ("type" in diction.keys()):
|
|
if diction['type']:
|
|
type = diction['type']
|
|
is_valide_type_materiel = MYSY_GV.dbname['ressource_materielle_type'].count_documents({'code':type,
|
|
'partner_owner_recid':'default',
|
|
'valide':'1',
|
|
'locked':'0'})
|
|
|
|
if( is_valide_type_materiel != 1):
|
|
mycommon.myprint(" Le type de materiel est invalide ")
|
|
return False, " Le type de materiel est invalide "
|
|
|
|
data['type'] = type
|
|
|
|
site_formation_id = ""
|
|
if ("site_formation_id" in diction.keys()):
|
|
if diction['site_formation_id']:
|
|
site_formation_id = diction['site_formation_id']
|
|
# verifier que le site de formation existe et est valide
|
|
is_site_formation_valide = MYSY_GV.dbname['site_formation'].count_documents({'_id':ObjectId(str(site_formation_id)),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0'})
|
|
|
|
if( is_site_formation_valide != 1):
|
|
mycommon.myprint(" L'identifiant du site de formation est invalide ")
|
|
return False, " L'identifiant du site de formation est invalide "
|
|
|
|
data['site_formation_id'] = site_formation_id
|
|
|
|
|
|
qty_stock = ""
|
|
if ("qty_stock" in diction.keys()):
|
|
if diction['qty_stock']:
|
|
qty_stock = diction['qty_stock']
|
|
local_status, local_val = mycommon.IsFloat(qty_stock)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La quantité en stock est invalide ")
|
|
|
|
return False, " - La quantité en stock est invalide "
|
|
|
|
data['qty_stock'] = qty_stock
|
|
|
|
|
|
|
|
|
|
data['valide'] = '1'
|
|
data['locked'] = '0'
|
|
data['date_update'] = str(datetime.now())
|
|
data['update_by'] = str(my_partner['_id'])
|
|
|
|
# Creation du RecId
|
|
data['recid'] = mycommon.create_user_recid()
|
|
|
|
|
|
inserted_id = ""
|
|
inserted_id = MYSY_GV.dbname['ressource_materielle'].insert_one(data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le materiel (2) ")
|
|
return False, " Impossible de créer le materiel (2) "
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(diction['token'])
|
|
history_event_dict['related_collection'] = "ressource_materielle"
|
|
history_event_dict['related_collection_recid'] = str(inserted_id)
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Création "
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique pour la ressource materielle (ref_interne): " + str(diction['ref_interne']))
|
|
|
|
return True, " Le materiel 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 le materiel "
|
|
|
|
|
|
|
|
"""
|
|
Mise à jour d'une ressource matereiel en se basant sur son _id
|
|
"""
|
|
def Update_Ressource_Materielle(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "ref_interne", "nom", "description", "detail", "famille",'marque', 'type',
|
|
'prix_achat', 'fournisseur', 'qty_stock', '_id', 'site_formation_id', 'code_categorie',
|
|
'complement_adresse', 'capacite_ideale', 'capacite_max', 'acces_handicape', 'prix_achat_by']
|
|
|
|
|
|
|
|
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']
|
|
|
|
# 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 récupérer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire. "
|
|
|
|
"""
|
|
Verification si ce materiel n'existe pas deja pour ce partner
|
|
"""
|
|
|
|
qry_update = {'_id': ObjectId(str(diction['_id'])), 'valide': '1', 'partner_recid': str(my_partner['recid']),}
|
|
|
|
|
|
|
|
#print(" ### qry_update aa = ", qry_update)
|
|
|
|
tmp_count = MYSY_GV.dbname['ressource_materielle'].count_documents(qry_update)
|
|
if (tmp_count <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Ce materiel n'existe pas = "+str(diction['nom']))
|
|
|
|
return False, " -Ce materiel n'existe pas "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
|
|
data_update = {}
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
|
|
ref_interne = ""
|
|
if ("ref_interne" in diction.keys()):
|
|
ref_interne = diction['ref_interne']
|
|
if (len(str(ref_interne)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'ref_interne' fait plus de 255 caractères")
|
|
|
|
return False, " - Le champ 'ref_interne' fait plus de 255 caractères"
|
|
data_update['ref_interne'] = diction['ref_interne']
|
|
|
|
# Si la catégorie est fournie, alors verifier qu'elle existe, si non, mettre par defaut à 'autre"
|
|
|
|
if ("code_categorie" in diction.keys() and diction['code_categorie']):
|
|
is_code_categorie_exist = MYSY_GV.dbname['ressource_materielle_categorie'].count_documents(
|
|
{'code': str(diction['code_categorie']).lower(),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': 'default'})
|
|
|
|
if (is_code_categorie_exist != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du code categorie est invalide ")
|
|
|
|
return False, " L'identifiant du code categorie est invalide "
|
|
|
|
code_categorie = str(diction['code_categorie']).lower()
|
|
data_update['code_categorie'] = code_categorie
|
|
|
|
|
|
complement_adresse = ""
|
|
if ("complement_adresse" in diction.keys()):
|
|
if diction['complement_adresse']:
|
|
complement_adresse = diction['complement_adresse']
|
|
if (len(str(ref_interne)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'complement_adresse' fait plus de 500 caractères")
|
|
|
|
return False, " - Le champ 'complement_adresse' fait plus de 500 caractères"
|
|
data_update['complement_adresse'] = complement_adresse
|
|
|
|
capacite_ideale = "0"
|
|
if ("capacite_ideale" in diction.keys()):
|
|
if diction['capacite_ideale']:
|
|
capacite_ideale = diction['capacite_ideale']
|
|
local_status, new_participants = mycommon.IsInt(capacite_ideale)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'capacite_ideale' n'est pas un nombre entier")
|
|
return False, " Le champ 'capacite_ideale' n'est pas un nombre entier "
|
|
|
|
data_update['capacite_ideale'] = capacite_ideale
|
|
|
|
capacite_max = "0"
|
|
if ("capacite_max" in diction.keys()):
|
|
if diction['capacite_max']:
|
|
capacite_max = diction['capacite_max']
|
|
local_status, new_participants = mycommon.IsInt(capacite_max)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'capacite_max' n'est pas un nombre entier")
|
|
return False, " Le champ 'capacite_max' n'est pas un nombre entier "
|
|
|
|
data_update['capacite_max'] = capacite_max
|
|
|
|
|
|
if ("acces_handicape" in diction.keys()):
|
|
acces_handicape = "0"
|
|
if diction['acces_handicape']:
|
|
acces_handicape = diction['acces_handicape']
|
|
local_status, new_participants = mycommon.IsInt(acces_handicape)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'acces_handicape' doit etre '0' ou '1' ")
|
|
return False, "Le champ 'acces_handicape' doit etre '0' ou '1' "
|
|
|
|
data_update['acces_handicape'] = acces_handicape
|
|
|
|
prix_achat_by = ""
|
|
if ("prix_achat_by" in diction.keys() and diction['prix_achat_by']):
|
|
prix_achat_by = diction['prix_achat_by']
|
|
if (diction['prix_achat_by'] not in ['fixe', 'heure', 'jour', 'mois']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'prix_achat_by' doit etre 'fixe', 'heure', 'jour', 'mois' ")
|
|
return False, "Le champ 'prix_achat_by' doit etre 'fixe', 'heure', 'jour', 'mois' "
|
|
|
|
data_update['prix_achat_by'] = prix_achat_by
|
|
|
|
|
|
nom = ""
|
|
if ("nom" in diction.keys()):
|
|
nom = diction['nom']
|
|
if (len(str(nom)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'nom' fait plus de 255 caractères")
|
|
|
|
return False, " - Le champ 'nom' fait plus de 255 caractères"
|
|
data_update['nom'] = diction['nom']
|
|
|
|
description = ""
|
|
if ("description" in diction.keys()):
|
|
description = diction['description']
|
|
if (len(str(description)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'description' fait plus de 500 caractères")
|
|
|
|
return False, " - Le champ 'Detail' fait plus de 500 caractères"
|
|
data_update['description'] = diction['description']
|
|
|
|
detail = ""
|
|
if ("detail" in diction.keys()):
|
|
detail = diction['detail']
|
|
if (len(str(detail)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'Detail' fait plus de 255 caractères")
|
|
|
|
return False, " - Le champ 'Detail' fait plus de 255 caractères"
|
|
|
|
data_update['detail'] = diction['detail']
|
|
|
|
famille = ""
|
|
if ("famille" in diction.keys()):
|
|
famille = diction['famille']
|
|
data_update['famille'] = diction['famille']
|
|
|
|
marque = ""
|
|
if ("marque" in diction.keys()):
|
|
marque = diction['marque']
|
|
data_update['marque'] = diction['marque']
|
|
|
|
type = ""
|
|
if ("type" in diction.keys()):
|
|
if diction['type']:
|
|
type = diction['type']
|
|
is_valide_type_materiel = MYSY_GV.dbname['ressource_materielle_type'].count_documents({'code': type,
|
|
'partner_owner_recid': 'default',
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_type_materiel != 1):
|
|
mycommon.myprint(" Le type de materiel est invalide ")
|
|
return False, " Le type de materiel est invalide "
|
|
|
|
data_update['type'] = type
|
|
|
|
site_formation_id = ""
|
|
if ("site_formation_id" in diction.keys()):
|
|
if diction['site_formation_id']:
|
|
site_formation_id = diction['site_formation_id']
|
|
# verifier que le site de formation existe et est valide
|
|
is_site_formation_valide = MYSY_GV.dbname['site_formation'].count_documents(
|
|
{'_id': ObjectId(str(site_formation_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_site_formation_valide != 1):
|
|
mycommon.myprint(" L'identifiant du site de formation est invalide ")
|
|
return False, " L'identifiant du site de formation est invalide "
|
|
|
|
#print(" ##### GGRR site_formation_id = ", site_formation_id)
|
|
data_update['site_formation_id'] = site_formation_id
|
|
|
|
prix_achat = ""
|
|
if ("prix_achat" in diction.keys()):
|
|
prix_achat = diction['prix_achat']
|
|
local_status, local_val = mycommon.IsFloat(prix_achat)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le prix d'achat est invalide ")
|
|
|
|
return False, " - Le prix d'achat est invalide "
|
|
|
|
data_update['prix_achat'] = diction['prix_achat']
|
|
|
|
fournisseur = ""
|
|
if ("fournisseur" in diction.keys()):
|
|
fournisseur = diction['fournisseur']
|
|
data_update['fournisseur'] = diction['fournisseur']
|
|
|
|
qty_stock = ""
|
|
if ("qty_stock" in diction.keys()):
|
|
qty_stock = diction['qty_stock']
|
|
local_status, local_val = mycommon.IsFloat(qty_stock)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La quantité en stock est invalide ")
|
|
|
|
return False, " - La quantité en stock est invalide "
|
|
|
|
data_update['qty_stock'] = diction['qty_stock']
|
|
|
|
|
|
data_update['valide'] = '1'
|
|
data_update['locked'] = '0'
|
|
data_update['date_update'] = str(datetime.now())
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {'_id': ObjectId(str(diction['_id'])), 'valide': '1', 'locked': '0', 'partner_recid': str(my_partner['recid']),}
|
|
|
|
|
|
inserted_id = ""
|
|
result = MYSY_GV.dbname['ressource_materielle'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": data_update},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if (result is None or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le materiel : email = ")
|
|
return False, " Impossible de mettre à jour le materiel "
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(diction['token'])
|
|
history_event_dict['related_collection'] = "ressource_materielle"
|
|
history_event_dict['related_collection_recid'] = str(diction['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Mise à jour "
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique : " + str(diction['_id']) )
|
|
|
|
|
|
return True, " Le materiel a été correctement mis à 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 de mettre à jour les données "
|
|
|
|
"""
|
|
Suppression d'une ressource materiel
|
|
"""
|
|
|
|
def Delete_Ressource_Materielle(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', 'ref_interne', ]
|
|
|
|
|
|
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']
|
|
|
|
# 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 récupérer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire. "
|
|
|
|
|
|
"""
|
|
Verification de l'existance du materiel a supprimer
|
|
"""
|
|
existe_employee_count = MYSY_GV.dbname['ressource_materielle'].count_documents({'_id': ObjectId(str(diction['_id'])),
|
|
'partner_recid': str(my_partner['recid']),})
|
|
|
|
if( existe_employee_count <= 0 ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Ce materiel est invalide")
|
|
return False, str(inspect.stack()[0][3]) + " -Cet materiel est invalide "
|
|
|
|
existe_materiel_data = MYSY_GV.dbname['ressource_materielle'].find_one(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'partner_recid': str(my_partner['recid']), })
|
|
"""
|
|
Suppression des eventuels affectation de ce materiel
|
|
"""
|
|
MYSY_GV.dbname['ressource_materielle_affectation'].delete_many({'related_collection_recid': (str(diction['_id'])),
|
|
'partner_recid': str(my_partner['recid']),
|
|
'related_collection':'ressource_materielle'})
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
Suppression du materiel
|
|
"""
|
|
MYSY_GV.dbname['ressource_materielle'].delete_many({'_id': ObjectId(str(diction['_id'])),
|
|
'partner_recid': str(my_partner['recid']),})
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(diction['token'])
|
|
history_event_dict['related_collection'] = "ressource_materielle"
|
|
history_event_dict['related_collection_recid'] = str(diction['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Suppression du materiel Nom = "+str(existe_materiel_data['nom'])+", ref_interne = "+str(existe_materiel_data['ref_interne'])
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique : " + str(diction['_id']))
|
|
|
|
return True, " Le materiel a été correctement supprimé"
|
|
|
|
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 supprimer le materiel "
|
|
|
|
|
|
"""
|
|
Recuperation de la liste des ressources materielle d'une entité en se basant sur
|
|
- token (partner_recid)
|
|
|
|
"""
|
|
def Get_List_Ressource_Materielle(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']
|
|
|
|
# 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"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_materielle'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
if ("prix_achat_by" in retval.keys()):
|
|
user['prix_achat_by'] = retval['prix_achat_by']
|
|
else:
|
|
user['prix_achat_by'] = ""
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
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 du materiel "
|
|
|
|
|
|
"""
|
|
Recherche sans filter - no_filter
|
|
"""
|
|
def Get_List_Ressource_Materielle_no_filter(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_recid'] = str(my_partner['recid'])
|
|
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
find_qry = {'partner_recid': str(my_partner['recid']), 'valide':'1', 'locked':'0' }
|
|
|
|
print(" ### materiel find_qry = ", find_qry)
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_materielle'].find(find_qry):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
if ("prix_achat_by" in retval.keys()):
|
|
user['prix_achat_by'] = retval['prix_achat_by']
|
|
else:
|
|
user['prix_achat_by'] = ""
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
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 ressources materielles "
|
|
|
|
"""
|
|
Recuperation d'une ressource materielle donnée en se basant sur on token, _id,
|
|
"""
|
|
def Get_Given_Ressource_Materielle(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_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(str(diction['_id']))
|
|
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
#print(" ### data_cle = ", data_cle)
|
|
for retval in MYSY_GV.dbname['ressource_materielle'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
if ("prix_achat_by" in retval.keys()):
|
|
user['prix_achat_by'] = retval['prix_achat_by']
|
|
else:
|
|
user['prix_achat_by'] = ""
|
|
|
|
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 les données du materiel "
|
|
|
|
|
|
"""
|
|
Cette fonction ajoute une image de profil d'un materiel
|
|
"""
|
|
def Update_Ressource_Materielle_Image(file_img=None, Folder=None, diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token', 'file_img_recid', 'rm_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'est pas autorisé ")
|
|
return False, " Le champ '" + val + "' n'est pas accepté "
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
|
|
|
# recuperation des paramettre
|
|
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
|
|
|
|
|
|
|
|
rm_id = ""
|
|
if ("rm_id" in diction.keys()):
|
|
if diction['rm_id']:
|
|
rm_id = diction['rm_id']
|
|
|
|
|
|
if( file_img ):
|
|
recordimage_diction = {}
|
|
recordimage_diction['token'] = diction['token']
|
|
recordimage_diction['related_collection'] = "ressource_materielle"
|
|
recordimage_diction['type_img'] = "user"
|
|
recordimage_diction['related_collection_recid'] = str(rm_id)
|
|
recordimage_diction['image_recid'] = diction['file_img_recid']
|
|
|
|
|
|
local_status, local_message = mycommon.recordClassImage_v2(file_img, MYSY_GV.upload_folder, recordimage_diction)
|
|
if( local_status is False):
|
|
return local_status, local_message
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(diction['token'])
|
|
history_event_dict['related_collection'] = "ressource_materielle"
|
|
history_event_dict['related_collection_recid'] = str(diction['rm_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Modification de l'image "
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique : " + str(diction['rm_id']))
|
|
|
|
return True, "L'image a été correctement enregistrée"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible d'enregistrer l'image"
|
|
|
|
"""
|
|
Suppression d'un image d'une ressource humaine
|
|
"""
|
|
def DeleteImage_Ressource_Materielle(diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'image_recid', ]
|
|
incom_keys = diction.keys()
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
for val in incom_keys:
|
|
if str(val).lower() not in str(field_list).lower():
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas accepté dans cette API")
|
|
return False, " Impossible de se connecter"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'image_recid']
|
|
for val in field_list_obligatoire:
|
|
if str(val).lower() not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments des champs")
|
|
return False, "Impossible de se connecter"
|
|
|
|
mydata = {}
|
|
mytoken = ""
|
|
|
|
# recuperation des paramettre
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
image_recid = ""
|
|
if ("image_recid" in diction.keys()):
|
|
if diction['image_recid']:
|
|
image_recid = diction['image_recid']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# " Lecture du fichier "
|
|
# print(" Lecture du fichier : " + saved_file + ". le token est :" + str(mytoken))
|
|
nb_line = 0
|
|
coll_name = MYSY_GV.dbname['mysy_images']
|
|
|
|
query_delete = {"recid": image_recid,}
|
|
|
|
|
|
ret_val = coll_name.delete_one({"recid": image_recid,}, )
|
|
|
|
print(" ### recordClassImage_v2 :L'image a été correctement supprimée ")
|
|
return True, "L'image a été correctement supprimée"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de supprimer l'image "
|
|
|
|
""" Recuperation de l'image d'un employé
|
|
|
|
/!\ important : on prend le 'related_collection_recid' comme le '_id' de la collection inscription
|
|
"""
|
|
def getRecoded_Materielle_Image_from_front(diction=None):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'rm_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, requete annulée")
|
|
return False, " Impossible de récupérer les informations"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'rm_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, " Impossible de récupérer les informations"
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
qery_images = {'locked': '0', 'valide': '1', 'related_collection': 'ressource_materielle',
|
|
'related_collection_recid': str(diction['rm_id'])}
|
|
|
|
#print(" ### qery_images = ", qery_images)
|
|
|
|
RetObject = []
|
|
employee_images = {}
|
|
# Recuperation des image 'logo' et 'cachet' si le partenaire en a
|
|
for retVal in MYSY_GV.dbname['mysy_images'].find(qery_images):
|
|
if ('type_img' in retVal.keys()):
|
|
if (retVal['type_img'] == "user"):
|
|
employee_images['logo_img'] = retVal['img'].decode()
|
|
employee_images['logo_img_recid'] = retVal['recid']
|
|
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(employee_images))
|
|
|
|
|
|
return True, RetObject
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recupérer l'image de l'employé "
|
|
|
|
|
|
""""
|
|
récupérer les affectations d'un materiel
|
|
:!\ : Pour le moment une affectation ne peut concerner que
|
|
- Une formation (collection : myclass) ou
|
|
- Une session de formation (collection session_formation) ou
|
|
- Un materiel
|
|
- rien du tout (cela veut dire que la fonction concene le partenaire, donc l'ecole.
|
|
|
|
exemple : Directeur des etude, etc)
|
|
"""
|
|
def Get_List_Ressource_Materielle_Affectation(diction):
|
|
try:
|
|
field_list_obligatoire = [ 'token', 'rm_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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'imprimer la fiche detaillée")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
|
|
|
|
qry_affectation = {'partner_owner_recid':str(my_partner_data['recid']),
|
|
'related_collection':'ressource_materielle', 'related_collection_recid':str(diction['rm_id']),
|
|
'valide':'1', 'locked':'0'}
|
|
|
|
|
|
print(" ### qry_affectation = ",qry_affectation)
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_materielle_affectation'].find(qry_affectation):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
related_target_collection_id_nom = ""
|
|
related_target_collection_object = ""
|
|
|
|
# Si l'affectation a un 'related_target_collection_id', alors cela veut dire qu'il faut aller chercheer
|
|
# la cible de cette affection.
|
|
if( "related_target_collection_id" in retval.keys() and "related_target_collection" in retval.keys()):
|
|
if( retval["related_target_collection_id"] and retval["related_target_collection"]):
|
|
|
|
# Si l'affectation concerne une formation
|
|
if( retval["related_target_collection"] == "myclass"):
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one({"_id":ObjectId(str( retval["related_target_collection_id"])),
|
|
'partner_owner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':"0"})
|
|
|
|
if(affectation_target_data is not None):
|
|
related_target_collection_id_nom = affectation_target_data["title"]
|
|
related_target_collection_object = "Formation"
|
|
|
|
# Si l'affectation concerne une session de formation
|
|
elif ( retval["related_target_collection"] == "session_formation") :
|
|
# Si l'affectation concerne une session
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_target_collection_id"])),
|
|
'partner_owner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
if (affectation_target_data is not None):
|
|
related_target_collection_id_nom = affectation_target_data["code_session"]
|
|
related_target_collection_object = "Session Formation"
|
|
|
|
# Si l'affectation concerne un salarié
|
|
elif (retval["related_target_collection"] == "ressource_humaine"):
|
|
# Si l'affectation concerne un salarié
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_target_collection_id"])),
|
|
'partner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
if (affectation_target_data is not None):
|
|
prenom = ""
|
|
nom = ""
|
|
if( "prenom" in affectation_target_data.keys() ):
|
|
prenom =affectation_target_data['prenom']
|
|
|
|
if ("nom" in affectation_target_data.keys()):
|
|
nom = affectation_target_data['nom']
|
|
|
|
|
|
related_target_collection_id_nom = str(prenom+" "+nom)
|
|
related_target_collection_object = "Employe"
|
|
|
|
|
|
# 11/01/2024 - Update : affectation d'un materiel a un materiel
|
|
# Si l'affectation concerne un materiel (oui car un materiel peut rattaché à un materiel)
|
|
elif (retval["related_target_collection"] == "ressource_materielle"):
|
|
# Si l'affectation concerne un materiel
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_target_collection_id"])),
|
|
'partner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
if (affectation_target_data is not None):
|
|
related_target_collection_id_nom = str(
|
|
affectation_target_data["ref_interne"] + " " + affectation_target_data["nom"])
|
|
related_target_collection_object = "Materiel"
|
|
|
|
user['related_target_collection_id_nom'] = related_target_collection_id_nom
|
|
user['related_target_collection_object'] = related_target_collection_object
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
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 affectations de l'employé "
|
|
|
|
|
|
"""
|
|
Ajout d'une affectation d'une ressource materiel à une formation ou une session
|
|
/!\ ou a une employé
|
|
"""
|
|
|
|
def Add_Affectation_Ressource_Materielle_Poste(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "rm_id", "poste", "date_du", "date_au", "comment", 'related_target_collection', 'related_target_collection_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'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
|
|
field_list_obligatoire = ['token', 'rm_id', "poste", 'date_du' ]
|
|
|
|
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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
rm_id = ""
|
|
if ("rm_id" in diction.keys()):
|
|
if diction['rm_id']:
|
|
rm_id = diction['rm_id']
|
|
# Verifier que le materiel existe bien
|
|
materiel_existe_count = MYSY_GV.dbname['ressource_materielle'].count_documents({'_id':ObjectId(str(rm_id)), 'partner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( materiel_existe_count <= 0 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Materiel invalide ")
|
|
return False, " Materiel invalide "
|
|
|
|
if (materiel_existe_count > 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Materiel incohérent. il a plusieurs materiels avec le meme id ")
|
|
return False, " Materiel incohérent. il a plusieurs materiels avec le meme id "
|
|
|
|
|
|
date_du = ""
|
|
if ("date_du" in diction.keys()):
|
|
if diction['date_du']:
|
|
date_du = str(diction['date_du'])[0:10]
|
|
|
|
# la date_du etant obligatoire, donc normal de faire le controle apres le "IF"
|
|
local_status = mycommon.CheckisDate(date_du)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La date de debut d'affectation n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, "La date de debut d'affectation n'est pas au format 'jj/mm/aaaa'"
|
|
|
|
|
|
date_au = ""
|
|
if ("date_au" in diction.keys()):
|
|
if diction['date_au']:
|
|
date_au = str(diction['date_au'])[0:10]
|
|
local_status = mycommon.CheckisDate(date_au)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin d'affectation n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, "La date de fin d'affectation n'est pas au format 'jj/mm/aaaa'"
|
|
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
comment = diction['comment']
|
|
if(len(str(comment)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'comment' a plus de 500 caractères ")
|
|
return False, "Le champ 'comment' a plus de 500 caractères "
|
|
|
|
poste = ""
|
|
if ("poste" in diction.keys()):
|
|
poste = diction['poste']
|
|
if (len(str(poste)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'poste' a plus de 255 caractères ")
|
|
return False, "Le champ 'poste' a plus de 255 caractères "
|
|
|
|
|
|
related_target_collection_id = ""
|
|
related_target_collection = ""
|
|
if ("related_target_collection_id" in diction.keys() and "related_target_collection" in diction.keys()):
|
|
if( diction['related_target_collection_id'] and diction['related_target_collection'] ):
|
|
related_target_collection_id = diction['related_target_collection_id']
|
|
related_target_collection = diction['related_target_collection']
|
|
else:
|
|
if( diction['related_target_collection_id'] != "" or diction['related_target_collection'] != ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Les données related_target_collection_id et related_target_collection sont incohérentes")
|
|
return False, "Les données related_target_collection_id et related_target_collection sont incohérentes "
|
|
|
|
|
|
|
|
|
|
# Verifier qu'on pas une affectation avec le meme poste qui demarre à la meme date.
|
|
if_affectation_exist_count_qry = {'related_collection':'ressource_materielle', 'related_collection_recid':str(diction['rm_id']),
|
|
'partner_owner_recid':str(partner_recid),'valide':'1', 'poste':str(diction['poste']),
|
|
'date_du':str(date_du)}
|
|
|
|
if_affectation_exist_count = MYSY_GV.dbname['ressource_materielle_affectation'].count_documents(if_affectation_exist_count_qry)
|
|
if(if_affectation_exist_count > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Ce materiel est deja affecté à ce poste ")
|
|
return False, "Ce materiel est deja affecté à ce poste"
|
|
|
|
|
|
my_data = {}
|
|
my_data['related_collection'] = 'ressource_materielle'
|
|
my_data['related_collection_recid'] = str(diction['rm_id'])
|
|
my_data['partner_owner_recid'] = str(partner_recid)
|
|
my_data['poste'] = str(poste)
|
|
my_data['related_target_collection_id'] = str(related_target_collection_id)
|
|
my_data['related_target_collection'] = str(related_target_collection)
|
|
my_data['comment'] = str(diction['comment'])
|
|
|
|
my_data['date_du'] = str(date_du)
|
|
my_data['date_au'] = str(date_au)
|
|
my_data['valide'] = "1"
|
|
my_data['locked'] = "0"
|
|
my_data['date_update'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
|
|
inserted_data = MYSY_GV.dbname['ressource_materielle_affectation'].insert_one(my_data)
|
|
if( inserted_data is None):
|
|
return False," Impossible d'affecter le materiel(2)"
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(diction['token'])
|
|
history_event_dict['related_collection'] = "ressource_materielle"
|
|
history_event_dict['related_collection_recid'] = str(diction['rm_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Affectation du materiel du "+str(date_du)+" au "+str(date_au)+". Poste : "+str(diction['poste'])+" . Cible "+str(related_target_collection)+" ==> "+str(related_target_collection_id)
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique : " + str(diction['rm_id']))
|
|
|
|
return True, "L'affectation du materiel a été correctement faite."
|
|
|
|
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'affecter le materiel "
|
|
|
|
|
|
"""
|
|
Mise à jour d'une affectation
|
|
"""
|
|
def Update_Affectation_Ressource_Materielle_Poste(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "rm_id", "poste", "date_du", "date_au", "comment", "_id", 'related_target_collection', 'related_target_collection_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'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
|
|
field_list_obligatoire = ['token', '_id', 'date_du', 'poste', "rm_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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
update_data = {}
|
|
|
|
rm_id = ""
|
|
if ("rm_id" in diction.keys()):
|
|
if diction['rm_id']:
|
|
rm_id = diction['rm_id']
|
|
# Verifier que l'employé existe bien
|
|
employee_existe_count = MYSY_GV.dbname['ressource_materielle'].count_documents({'_id':ObjectId(str(rm_id)), 'partner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( employee_existe_count <= 0 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Materiel invalide ")
|
|
return False, " Materiel invalide "
|
|
|
|
if (employee_existe_count > 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Materiel incohérent. il a plusieurs Materiels avec le meme id ")
|
|
return False, " Materiel incohérent. il a plusieurs Materiels avec le meme id "
|
|
|
|
|
|
date_du = ""
|
|
if ("date_du" in diction.keys()):
|
|
if diction['date_du']:
|
|
date_du = str(diction['date_du'])[0:10]
|
|
|
|
# la date_du etant obligatoire, donc normal de faire le controle apres le "IF"
|
|
local_status = mycommon.CheckisDate(date_du)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La date de debut d'affectation n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, "La date de debut d'affectation n'est pas au format 'jj/mm/aaaa'"
|
|
update_data['date_du'] = date_du
|
|
|
|
|
|
date_au = ""
|
|
if ("date_fin" in diction.keys()):
|
|
date_au = str(diction['date_fin'])[0:10]
|
|
local_status = mycommon.CheckisDate(date_au)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin d'affectation n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, "La date de fin d'affectation n'est pas au format 'jj/mm/aaaa'"
|
|
|
|
update_data['date_du'] = date_du
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
comment = diction['comment']
|
|
if(len(str(comment)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'comment' a plus de 500 caractères ")
|
|
return False, "Le champ 'comment' a plus de 500 caractères "
|
|
update_data['comment'] = comment
|
|
|
|
|
|
poste = ""
|
|
if ("poste" in diction.keys()):
|
|
poste = diction['poste']
|
|
if (len(str(poste)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'poste' a plus de 255 caractères ")
|
|
return False, "Le champ 'poste' a plus de 255 caractères "
|
|
update_data['poste'] = poste
|
|
|
|
|
|
related_target_collection_id = ""
|
|
related_target_collection = ""
|
|
if ("related_target_collection_id" in diction.keys() and "related_target_collection" in diction.keys()):
|
|
if (diction['related_target_collection_id'] and diction['related_target_collection']):
|
|
related_target_collection_id = diction['related_target_collection_id']
|
|
related_target_collection = diction['related_target_collection']
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Les données related_target_collection_id et related_target_collection sont incohérentes")
|
|
return False, "Les données related_target_collection_id et related_target_collection sont incohérentes "
|
|
|
|
update_data['related_target_collection_id'] = str(related_target_collection_id)
|
|
update_data['related_target_collection'] = str(related_target_collection)
|
|
|
|
update_data['date_update'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
|
|
# Verifier l'existance de l'affectation
|
|
affectation_existe_count_qry = {'_id': ObjectId(str(diction['_id'])), 'valide': "1", "locked":"0", 'partner_owner_recid':str(partner_recid)}
|
|
#print(" ### affectation_existe_count_qry = ", affectation_existe_count_qry)
|
|
affectation_existe_count = MYSY_GV.dbname['ressource_materielle_affectation'].count_documents( affectation_existe_count_qry)
|
|
|
|
if( affectation_existe_count != 1 ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour cette affectation. Données incohérentes ")
|
|
return False, " Impossible de mettre à jour cette affectation. Données incohérentes "
|
|
|
|
|
|
inserted_data = MYSY_GV.dbname['ressource_materielle_affectation'].find_one_and_update(
|
|
{'_id': ObjectId(str(diction['_id'])), 'valide': "1", "locked":"0", 'partner_owner_recid':str(partner_recid)},
|
|
{"$set": update_data},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
if( inserted_data is None ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour cette affectation (3)")
|
|
return False, " Impossible de mettre à jour cette affectation (3) "
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(diction['token'])
|
|
history_event_dict['related_collection'] = "ressource_materielle"
|
|
history_event_dict['related_collection_recid'] = str(diction['rm_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Modification affectation du materiel "
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique : " + str(diction['rm_id']))
|
|
|
|
return True, "L'affectation du materiel a été correctement 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 de mettre à jour cette affectation "
|
|
|
|
|
|
"""
|
|
Supprimer une affectation
|
|
"""
|
|
def Delete_Affectation_Ressource_Materielle_Poste(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "rm_id", "_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'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
|
|
field_list_obligatoire = ['token', "rm_id", "_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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
update_data = {}
|
|
|
|
rm_id = ""
|
|
if ("rm_id" in diction.keys()):
|
|
if diction['rm_id']:
|
|
rm_id = diction['rm_id']
|
|
|
|
# Verifier que le materiel existe bien
|
|
employee_existe_count = MYSY_GV.dbname['ressource_materielle'].count_documents({'_id':ObjectId(str(rm_id)), 'partner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( employee_existe_count <= 0 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Materiel invalide ")
|
|
return False, " Materiel invalide "
|
|
|
|
if (employee_existe_count > 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Materiel incohérent. il a plusieurs Materiels avec le meme id ")
|
|
return False, " Materiel incohérent. il a plusieurs Materiels avec le meme id "
|
|
|
|
|
|
# Verifier l'existance de l'affectation
|
|
affectation_existe_count = MYSY_GV.dbname['ressource_materielle_affectation'].count_documents( {'_id': ObjectId(str(diction['_id'])), 'valide': "1",
|
|
"locked":"0", 'partner_owner_recid':str(partner_recid)})
|
|
|
|
if( affectation_existe_count != 1 ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de supprimer cette affectation. Données incohérentes ")
|
|
return False, " Impossible de supprimer cette affectation. Données incohérentes "
|
|
|
|
|
|
inserted_data = MYSY_GV.dbname['ressource_materielle_affectation'].delete_one( {'_id': ObjectId(str(diction['_id'])), 'valide': "1", "locked":"0",
|
|
'partner_owner_recid':str(partner_recid)}, )
|
|
|
|
if( inserted_data is None ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de supprimer à jour cette affectation (3)")
|
|
return False, " Impossible de supprimer cette affectation (3) "
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(diction['token'])
|
|
history_event_dict['related_collection'] = "ressource_materielle"
|
|
history_event_dict['related_collection_recid'] = str(diction['rm_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Suppression affectation du materiel "
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique : " + str(diction['rm_id']))
|
|
|
|
return True, "L'affectation du materiel a été correctement supprimé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 de supprimer cette affectation "
|
|
|
|
|
|
|
|
def Get_Given_Affectation_Ressource_Materielle_Poste(diction):
|
|
try:
|
|
field_list_obligatoire = ['token', 'affectation_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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'imprimer la fiche detaillée")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
qry_affectation = {'partner_owner_recid': str(my_partner_data['recid']),
|
|
'_id': ObjectId(str(diction['affectation_id'])),
|
|
'valide': '1', 'locked': '0'}
|
|
|
|
print(" ### qry_affectation = ", qry_affectation)
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_materielle_affectation'].find(qry_affectation):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
related_target_collection_id_nom = ""
|
|
related_target_collection_object = ""
|
|
|
|
# Si l'affectation a un 'related_target_collection_id', alors cela veut dire qu'il faut aller chercheer
|
|
# la cible de cette affection.
|
|
if ("related_target_collection_id" in retval.keys() and "related_target_collection" in retval.keys()):
|
|
if (retval["related_target_collection_id"] and retval["related_target_collection"]):
|
|
|
|
# Si l'affectation concerne une formation
|
|
if (retval["related_target_collection"] == "myclass"):
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_target_collection_id"])),
|
|
'partner_owner_recid': str(partner_recid),
|
|
'valide': '1', 'locked': "0"})
|
|
|
|
if (affectation_target_data is not None):
|
|
related_target_collection_id_nom = affectation_target_data["title"]
|
|
related_target_collection_object = "Formation"
|
|
|
|
# Si l'affectation concerne une session
|
|
elif (retval["related_target_collection"] == "session_formation"):
|
|
# Si l'affectation concerne une session
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_target_collection_id"])),
|
|
'partner_owner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
if (affectation_target_data is not None):
|
|
related_target_collection_id_nom = affectation_target_data["code_session"]
|
|
related_target_collection_object = "Session de formation"
|
|
|
|
# Si l'affectation concerne un employé
|
|
elif (retval["related_target_collection"] == "ressource_humaine"):
|
|
# Si l'affectation concerne un employé
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_target_collection_id"])),
|
|
'partner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
if (affectation_target_data is not None):
|
|
related_target_collection_id_nom = str(affectation_target_data["prenom"]+" "+affectation_target_data["nom"])
|
|
related_target_collection_object = "Employe"
|
|
|
|
|
|
user['related_target_collection_id_nom'] = related_target_collection_id_nom
|
|
user['related_target_collection_object'] = related_target_collection_object
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
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 l'affectation du materiel "
|
|
|
|
|
|
"""
|
|
Cette API permet de récupérer la liste des 'related_target_collection_object' avec les 'related_target_collection_id_nom'
|
|
et de les formater pour une utilisation simple coté front.
|
|
|
|
les collections cibles sont :
|
|
- les formations et les sessions de formation, les employé et le materiel (oui la cas ou un PC est affecté à une salle)
|
|
|
|
ex :
|
|
{
|
|
{'related_target_collection':'session_formation',
|
|
'related_target_collection_id':'64e797fd168e0c57cefe4fd0'
|
|
'related_target_collection_id_nom' : 'ch_Manual_1'
|
|
},
|
|
{'related_target_collection':'myclass',
|
|
'related_target_collection_id':'64e79630ea7b810a3d835ceb'
|
|
'related_target_collection_id_nom' : 'PRATICIEN EN AROMATHERAPIE INTEGRATIVE'
|
|
},
|
|
{'related_target_collection':'ressource_humaine',
|
|
'related_target_collection_id':'64e4e9ce347aaa05b2d207b0'
|
|
'related_target_collection_id_nom' : 'prenom_employe3 nom_employe3u'
|
|
},
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
def Get_Related_Target_Materiel_Collection_Data(diction):
|
|
try:
|
|
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -Les informations d'identification sont invalides")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
RetObject = []
|
|
|
|
# Recuperation des données des formations
|
|
for retval in MYSY_GV.dbname['myclass'].find({'partner_owner_recid': str(partner_recid),
|
|
'valide': '1', 'locked': '0'}, {'_id': 1, 'title': 1}):
|
|
retval_data = {}
|
|
retval_data['related_target_collection'] = "myclass"
|
|
retval_data['related_target_collection_id'] = str(retval['_id'])
|
|
retval_data['related_target_collection_id_nom'] = str(retval['title'])
|
|
RetObject.append(mycommon.JSONEncoder().encode(retval_data))
|
|
|
|
# Recuperation des données des sessions
|
|
for retval in MYSY_GV.dbname['session_formation'].find({'partner_owner_recid': str(partner_recid),
|
|
'valide': '1'}, {'_id': 1, 'code_session': 1}):
|
|
retval_data = {}
|
|
retval_data['related_target_collection'] = "session_formation"
|
|
retval_data['related_target_collection_id'] = str(retval['_id'])
|
|
retval_data['related_target_collection_id_nom'] = str(retval['code_session'])
|
|
RetObject.append(mycommon.JSONEncoder().encode(retval_data))
|
|
|
|
# Recuperation des données des employés
|
|
for retval in MYSY_GV.dbname['ressource_humaine'].find({'partner_recid': str(partner_recid),
|
|
'valide': '1', 'is_partner_admin_account':{ '$ne': '1' } }, {'_id': 1, 'prenom': 1, 'nom':1}):
|
|
retval_data = {}
|
|
retval_data['related_target_collection'] = "ressource_humaine"
|
|
retval_data['related_target_collection_id'] = str(retval['_id'])
|
|
nom = ""
|
|
prenom = ""
|
|
if( "nom" in retval.keys()):
|
|
nom = retval['nom']
|
|
|
|
if ("prenom" in retval.keys()):
|
|
prenom = retval['prenom']
|
|
|
|
|
|
retval_data['related_target_collection_id_nom'] = str(str(nom+" "+prenom))
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(retval_data))
|
|
|
|
# Recuperation des données du materiel (ceci permet d'affectuer un materiel à une salles de réunion par exmple)
|
|
for retval in MYSY_GV.dbname['ressource_materielle'].find({'partner_recid': str(partner_recid),
|
|
'valide': '1'}, {'_id': 1, 'ref_interne': 1, 'nom':1}):
|
|
retval_data = {}
|
|
retval_data['related_target_collection'] = "ressource_materielle"
|
|
retval_data['related_target_collection_id'] = str(retval['_id'])
|
|
nom = ""
|
|
ref_interne = ""
|
|
if( "nom" in retval.keys()):
|
|
nom = retval['nom']
|
|
|
|
if ("ref_interne" in retval.keys()):
|
|
ref_interne = retval['ref_interne']
|
|
|
|
|
|
retval_data['related_target_collection_id_nom'] = str(str(nom+" "+ref_interne))
|
|
RetObject.append(mycommon.JSONEncoder().encode(retval_data))
|
|
|
|
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 informations des cibles "
|
|
|
|
|
|
"""
|
|
Recuperation de la liste des ressources materielles avec des filtres sur
|
|
- nom
|
|
- email
|
|
"""
|
|
def Get_List_Ressource_Materielle_with_filter(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'nom', 'ref_interne', 'formation', 'session', 'employe_email',
|
|
'code_categorie']
|
|
|
|
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']
|
|
|
|
# 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"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
filt_nom = {}
|
|
if ("nom" in diction.keys()):
|
|
filt_nom = {'nom': {'$regex': str(diction['nom']), "$options": "i"}}
|
|
|
|
filt_ref_interne = {}
|
|
if ("ref_interne" in diction.keys()):
|
|
filt_ref_interne = {
|
|
'ref_interne': {'$regex': str(diction['ref_interne']), "$options": "i"}}
|
|
|
|
filt_code_categorie = {}
|
|
if ("code_categorie" in diction.keys()):
|
|
filt_code_categorie = {
|
|
'code_categorie': {'$regex': str(diction['code_categorie']), "$options": "i"}}
|
|
|
|
# Sous Filter pour une formation
|
|
sub_filt_formation = {}
|
|
if ("formation" in diction.keys()):
|
|
sub_filt_formation = {
|
|
'external_code': {'$regex': str(diction['formation']), "$options": "i"}, 'partner_owner_recid':str(my_partner['recid'])}
|
|
|
|
# Sous Filter pour une session
|
|
sub_filt_session = {}
|
|
if ("session" in diction.keys()):
|
|
sub_filt_session = { 'code_session': {'$regex': str(diction['session']), "$options": "i"}, 'partner_owner_recid':str(my_partner['recid'])}
|
|
|
|
|
|
# Sous Filter pour un employe
|
|
sub_filt_employee = {}
|
|
if ("employe_email" in diction.keys()):
|
|
sub_filt_employee = {'email': {'$regex': str(diction['employe_email']), "$options": "i"},
|
|
'partner_recid': str(my_partner['recid'])}
|
|
|
|
"""
|
|
Recuperation des id des codes session pouvant correspondre a la valeur fournie par le user
|
|
(regexp bien sur)
|
|
"""
|
|
filt_session = {}
|
|
Lists_session_id = []
|
|
if ("session" in diction.keys()):
|
|
for Lists_session in MYSY_GV.dbname['session_formation'].find(sub_filt_session, {'_id':1}):
|
|
Lists_session_id.append(str(Lists_session['_id']))
|
|
|
|
if( len(Lists_session_id) > 0):
|
|
filt_session = {'related_target_collection_id': {'$in': Lists_session_id, },
|
|
'related_collection': 'ressource_materielle',
|
|
'related_target_collection': 'session_formation',
|
|
}
|
|
|
|
|
|
"""
|
|
Recuperation des id des formation pouvant correspondre a la valeur fournie par le user
|
|
(regexp bien sur)
|
|
"""
|
|
filt_formation = {}
|
|
Lists_formation_id = []
|
|
if ("formation" in diction.keys()):
|
|
for Lists_formation in MYSY_GV.dbname['myclass'].find(sub_filt_formation, {'_id': 1}):
|
|
Lists_formation_id.append(str(Lists_formation['_id']))
|
|
|
|
|
|
if(len(Lists_formation_id) > 0 ):
|
|
filt_formation = {'related_target_collection_id': {'$in': Lists_formation_id, },
|
|
'related_collection':'ressource_materielle',
|
|
'related_target_collection':'myclass',
|
|
}
|
|
|
|
"""
|
|
Recuperation des id des employées dont l'email corresponds en mode regexp
|
|
"""
|
|
filt_employee = {}
|
|
Lists_employee_id = []
|
|
if ("employe_email" in diction.keys()):
|
|
for Lists_employee in MYSY_GV.dbname['ressource_humaine'].find(sub_filt_employee, {'_id': 1}):
|
|
Lists_employee_id.append(str(Lists_employee['_id']))
|
|
|
|
if (len(Lists_employee_id) > 0):
|
|
filt_employee = {'related_target_collection_id': {'$in': Lists_employee_id, },
|
|
'related_collection': 'ressource_materielle',
|
|
'related_target_collection': 'ressource_humaine',
|
|
}
|
|
|
|
#print(" ### sub_filt_employee = ", sub_filt_employee)
|
|
#print(" ### Lists_employee_id = ", Lists_employee_id)
|
|
#print(" ### filt_employee = ", filt_employee)
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
find_qry = {'$and':[{'partner_recid': str(my_partner['recid']), 'valide':'1', 'locked':'0' }, filt_nom, filt_ref_interne, filt_code_categorie] }
|
|
|
|
|
|
new_myquery = [{'$match': find_qry},
|
|
{"$addFields": {"ressource_materielle_Id": {"$toString": "$_id"}}},
|
|
{'$lookup':
|
|
{
|
|
'from': 'ressource_materielle_affectation',
|
|
'localField': "ressource_materielle_Id",
|
|
'foreignField': 'related_collection_recid',
|
|
'pipeline': [{'$match':{ '$and' : [ filt_formation, filt_session, filt_employee, {'partner_owner_recid': str(my_partner['recid'])}, {'valide':'1'}] } }, {'$project': {'poste': 1,
|
|
'date_du': 1,
|
|
'date_au':1,
|
|
'related_target_collection':1
|
|
}}],
|
|
'as': 'ressource_materielle_affectation_collection'
|
|
}
|
|
}
|
|
]
|
|
|
|
|
|
|
|
New_RetObject = []
|
|
New_val_tmp = 1
|
|
|
|
|
|
""""
|
|
Si dans la requette on a les champ : 'formation' ou 'session' on utiliser la requete ci-dessous.
|
|
Cela veut dire qu'on cherche des ressources qui sont des affectation avec une formation ou une session.
|
|
"""
|
|
if( "formation" in diction.keys() or "session" in diction.keys() or "employe_email" in diction.keys() ):
|
|
for New_retVal in MYSY_GV.dbname['ressource_materielle'].aggregate(new_myquery):
|
|
if ('ressource_materielle_affectation_collection' in New_retVal.keys() and len(New_retVal['ressource_materielle_affectation_collection']) > 0):
|
|
print(" #### RESULT New_retVal for = ", New_retVal['nom'])
|
|
user = {}
|
|
user['id'] = str(New_val_tmp)
|
|
New_val_tmp = New_val_tmp + 1
|
|
|
|
|
|
user['_id'] = New_retVal['_id']
|
|
user['partner_recid'] = New_retVal['partner_recid']
|
|
user['ref_interne'] = New_retVal['ref_interne']
|
|
user['nom'] = New_retVal['nom']
|
|
|
|
|
|
if ("prix_achat_by" in New_retVal.keys()):
|
|
user['prix_achat_by'] = New_retVal['prix_achat_by']
|
|
else:
|
|
user['prix_achat_by'] = ""
|
|
|
|
|
|
if ("description" in New_retVal.keys()):
|
|
user['description'] = New_retVal['description']
|
|
else:
|
|
user['description'] = ""
|
|
|
|
if ("detail" in New_retVal.keys()):
|
|
user['detail'] = New_retVal['detail']
|
|
else:
|
|
user['detail'] = ""
|
|
|
|
if( "famille" in New_retVal.keys()):
|
|
user['famille'] = New_retVal['famille']
|
|
else:
|
|
user['famille'] = ""
|
|
|
|
if ("marque" in New_retVal.keys()):
|
|
user['marque'] = New_retVal['marque']
|
|
else:
|
|
user['marque'] = ""
|
|
|
|
if ("type" in New_retVal.keys()):
|
|
user['type'] = New_retVal['type']
|
|
else:
|
|
user['type'] = ""
|
|
|
|
if ("prix_achat" in New_retVal.keys()):
|
|
user['prix_achat'] = New_retVal['prix_achat']
|
|
else:
|
|
user['prix_achat'] = ""
|
|
|
|
if ("fournisseur" in New_retVal.keys()):
|
|
user['fournisseur'] = New_retVal['fournisseur']
|
|
else:
|
|
user['fournisseur'] = ""
|
|
|
|
if ("qty_stock" in New_retVal.keys()):
|
|
user['qty_stock'] = New_retVal['qty_stock']
|
|
else:
|
|
user['qty_stock'] = ""
|
|
|
|
site_formation_code_site = ""
|
|
if( "site_formation_id" in New_retVal.keys() and New_retVal['site_formation_id'] ):
|
|
local_site = MYSY_GV.dbname['site_formation'].find_one({'_id':ObjectId(str(New_retVal['site_formation_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( local_site and 'code_site' in local_site.keys() ):
|
|
site_formation_code_site = local_site['code_site']
|
|
|
|
user['site_formation_code_site'] = site_formation_code_site
|
|
|
|
|
|
|
|
user['affectation'] = []
|
|
for local_affectation in New_retVal['ressource_materielle_affectation_collection']:
|
|
affectation = {}
|
|
if ("poste" in local_affectation.keys()):
|
|
affectation['poste'] = local_affectation['poste']
|
|
else:
|
|
affectation['poste'] = ""
|
|
|
|
affectation['related_target_collection'] = local_affectation['related_target_collection']
|
|
affectation['date_du'] = local_affectation['date_du']
|
|
affectation['date_au'] = local_affectation['date_au']
|
|
|
|
|
|
#print(" ### AFFACTATION local_affectation = ", local_affectation)
|
|
|
|
New_RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, New_RetObject
|
|
else:
|
|
# Il s'agit d'une recherche sans lien avec des fonctions occupés dans une formation ou une session
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_materielle'].find(find_qry):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
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 contact "
|
|
|
|
|
|
"""
|
|
Récuperation d'une ressource materiel hors salle (No_Salle)
|
|
"""
|
|
def Get_List_Ressource_Materielle_with_filter_No_Salle(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'nom', 'ref_interne', 'formation', 'session', 'employe_email',
|
|
'code_categorie']
|
|
|
|
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']
|
|
|
|
# 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"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
filt_nom = {}
|
|
if ("nom" in diction.keys()):
|
|
filt_nom = {'nom': {'$regex': str(diction['nom']), "$options": "i"}}
|
|
|
|
filt_ref_interne = {}
|
|
if ("ref_interne" in diction.keys()):
|
|
filt_ref_interne = {
|
|
'ref_interne': {'$regex': str(diction['ref_interne']), "$options": "i"}}
|
|
|
|
filt_code_categorie = {}
|
|
if ("code_categorie" in diction.keys()):
|
|
filt_code_categorie = {
|
|
'code_categorie': {'$regex': str(diction['code_categorie']), "$options": "i"}}
|
|
|
|
# Sous Filter pour une formation
|
|
sub_filt_formation = {}
|
|
if ("formation" in diction.keys()):
|
|
sub_filt_formation = {
|
|
'external_code': {'$regex': str(diction['formation']), "$options": "i"}, 'partner_owner_recid':str(my_partner['recid'])}
|
|
|
|
# Sous Filter pour une session
|
|
sub_filt_session = {}
|
|
if ("session" in diction.keys()):
|
|
sub_filt_session = { 'code_session': {'$regex': str(diction['session']), "$options": "i"}, 'partner_owner_recid':str(my_partner['recid'])}
|
|
|
|
|
|
# Sous Filter pour un employe
|
|
sub_filt_employee = {}
|
|
if ("employe_email" in diction.keys()):
|
|
sub_filt_employee = {'email': {'$regex': str(diction['employe_email']), "$options": "i"},
|
|
'partner_recid': str(my_partner['recid'])}
|
|
|
|
"""
|
|
Recuperation des id des codes session pouvant correspondre a la valeur fournie par le user
|
|
(regexp bien sur)
|
|
"""
|
|
filt_session = {}
|
|
Lists_session_id = []
|
|
if ("session" in diction.keys()):
|
|
for Lists_session in MYSY_GV.dbname['session_formation'].find(sub_filt_session, {'_id':1}):
|
|
Lists_session_id.append(str(Lists_session['_id']))
|
|
|
|
if( len(Lists_session_id) > 0):
|
|
filt_session = {'related_target_collection_id': {'$in': Lists_session_id, },
|
|
'related_collection': 'ressource_materielle',
|
|
'related_target_collection': 'session_formation',
|
|
}
|
|
|
|
|
|
"""
|
|
Recuperation des id des formation pouvant correspondre a la valeur fournie par le user
|
|
(regexp bien sur)
|
|
"""
|
|
filt_formation = {}
|
|
Lists_formation_id = []
|
|
if ("formation" in diction.keys()):
|
|
for Lists_formation in MYSY_GV.dbname['myclass'].find(sub_filt_formation, {'_id': 1}):
|
|
Lists_formation_id.append(str(Lists_formation['_id']))
|
|
|
|
|
|
if(len(Lists_formation_id) > 0 ):
|
|
filt_formation = {'related_target_collection_id': {'$in': Lists_formation_id, },
|
|
'related_collection':'ressource_materielle',
|
|
'related_target_collection':'myclass',
|
|
}
|
|
|
|
"""
|
|
Recuperation des id des employées dont l'email corresponds en mode regexp
|
|
"""
|
|
filt_employee = {}
|
|
Lists_employee_id = []
|
|
if ("employe_email" in diction.keys()):
|
|
for Lists_employee in MYSY_GV.dbname['ressource_humaine'].find(sub_filt_employee, {'_id': 1}):
|
|
Lists_employee_id.append(str(Lists_employee['_id']))
|
|
|
|
if (len(Lists_employee_id) > 0):
|
|
filt_employee = {'related_target_collection_id': {'$in': Lists_employee_id, },
|
|
'related_collection': 'ressource_materielle',
|
|
'related_target_collection': 'ressource_humaine',
|
|
}
|
|
|
|
#print(" ### sub_filt_employee = ", sub_filt_employee)
|
|
#print(" ### Lists_employee_id = ", Lists_employee_id)
|
|
#print(" ### filt_employee = ", filt_employee)
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
no_salle_qry = {'code_categorie':{"$ne": "salle"}}
|
|
|
|
|
|
find_qry = {'$and':[{'partner_recid': str(my_partner['recid']), 'valide':'1', 'locked':'0' }, filt_nom,
|
|
filt_ref_interne, filt_code_categorie, no_salle_qry] }
|
|
|
|
|
|
new_myquery = [{'$match': find_qry},
|
|
{"$addFields": {"ressource_materielle_Id": {"$toString": "$_id"}}},
|
|
{'$lookup':
|
|
{
|
|
'from': 'ressource_materielle_affectation',
|
|
'localField': "ressource_materielle_Id",
|
|
'foreignField': 'related_collection_recid',
|
|
'pipeline': [{'$match':{ '$and' : [ filt_formation, filt_session, filt_employee, {'partner_owner_recid': str(my_partner['recid'])}, {'valide':'1'}] } }, {'$project': {'poste': 1,
|
|
'date_du': 1,
|
|
'date_au':1,
|
|
'related_target_collection':1
|
|
}}],
|
|
'as': 'ressource_materielle_affectation_collection'
|
|
}
|
|
}
|
|
]
|
|
|
|
|
|
|
|
New_RetObject = []
|
|
New_val_tmp = 1
|
|
|
|
|
|
""""
|
|
Si dans la requette on a les champ : 'formation' ou 'session' on utiliser la requete ci-dessous.
|
|
Cela veut dire qu'on cherche des ressources qui sont des affectation avec une formation ou une session.
|
|
"""
|
|
if( "formation" in diction.keys() or "session" in diction.keys() or "employe_email" in diction.keys() ):
|
|
for New_retVal in MYSY_GV.dbname['ressource_materielle'].aggregate(new_myquery):
|
|
if ('ressource_materielle_affectation_collection' in New_retVal.keys() and len(New_retVal['ressource_materielle_affectation_collection']) > 0):
|
|
print(" #### RESULT New_retVal for = ", New_retVal['nom'])
|
|
user = {}
|
|
user['id'] = str(New_val_tmp)
|
|
New_val_tmp = New_val_tmp + 1
|
|
|
|
|
|
user['_id'] = New_retVal['_id']
|
|
user['partner_recid'] = New_retVal['partner_recid']
|
|
user['ref_interne'] = New_retVal['ref_interne']
|
|
user['nom'] = New_retVal['nom']
|
|
|
|
|
|
if ("prix_achat_by" in New_retVal.keys()):
|
|
user['prix_achat_by'] = New_retVal['prix_achat_by']
|
|
else:
|
|
user['prix_achat_by'] = ""
|
|
|
|
|
|
if ("description" in New_retVal.keys()):
|
|
user['description'] = New_retVal['description']
|
|
else:
|
|
user['description'] = ""
|
|
|
|
if ("detail" in New_retVal.keys()):
|
|
user['detail'] = New_retVal['detail']
|
|
else:
|
|
user['detail'] = ""
|
|
|
|
if( "famille" in New_retVal.keys()):
|
|
user['famille'] = New_retVal['famille']
|
|
else:
|
|
user['famille'] = ""
|
|
|
|
if ("marque" in New_retVal.keys()):
|
|
user['marque'] = New_retVal['marque']
|
|
else:
|
|
user['marque'] = ""
|
|
|
|
if ("type" in New_retVal.keys()):
|
|
user['type'] = New_retVal['type']
|
|
else:
|
|
user['type'] = ""
|
|
|
|
if ("prix_achat" in New_retVal.keys()):
|
|
user['prix_achat'] = New_retVal['prix_achat']
|
|
else:
|
|
user['prix_achat'] = ""
|
|
|
|
if ("fournisseur" in New_retVal.keys()):
|
|
user['fournisseur'] = New_retVal['fournisseur']
|
|
else:
|
|
user['fournisseur'] = ""
|
|
|
|
if ("qty_stock" in New_retVal.keys()):
|
|
user['qty_stock'] = New_retVal['qty_stock']
|
|
else:
|
|
user['qty_stock'] = ""
|
|
|
|
site_formation_code_site = ""
|
|
if( "site_formation_id" in New_retVal.keys() and New_retVal['site_formation_id'] ):
|
|
local_site = MYSY_GV.dbname['site_formation'].find_one({'_id':ObjectId(str(New_retVal['site_formation_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( local_site and 'code_site' in local_site.keys() ):
|
|
site_formation_code_site = local_site['code_site']
|
|
|
|
user['site_formation_code_site'] = site_formation_code_site
|
|
|
|
|
|
|
|
user['affectation'] = []
|
|
for local_affectation in New_retVal['ressource_materielle_affectation_collection']:
|
|
affectation = {}
|
|
if ("poste" in local_affectation.keys()):
|
|
affectation['poste'] = local_affectation['poste']
|
|
else:
|
|
affectation['poste'] = ""
|
|
|
|
affectation['related_target_collection'] = local_affectation['related_target_collection']
|
|
affectation['date_du'] = local_affectation['date_du']
|
|
affectation['date_au'] = local_affectation['date_au']
|
|
|
|
|
|
#print(" ### AFFACTATION local_affectation = ", local_affectation)
|
|
|
|
New_RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, New_RetObject
|
|
else:
|
|
# Il s'agit d'une recherche sans lien avec des fonctions occupés dans une formation ou une session
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_materielle'].find(find_qry):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
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 contact "
|
|
|
|
|
|
"""
|
|
Cette fonction recuperer les ressources associées à une ressource materielle
|
|
Ex : les composants d'un salle
|
|
- projecteur
|
|
- table
|
|
- ordinateur
|
|
- etc
|
|
"""
|
|
def Get_List_Ressource_Materielle_Rattachement(diction):
|
|
try:
|
|
field_list_obligatoire = [ 'token', 'rm_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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'imprimer la fiche detaillée")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
|
|
|
|
qry_affectation = {'partner_owner_recid':str(my_partner_data['recid']),
|
|
'related_target_collection':'ressource_materielle', 'related_target_collection_id':str(diction['rm_id']),
|
|
'valide':'1', 'locked':'0'}
|
|
|
|
|
|
print(" ### qry_affectation = ",qry_affectation)
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_materielle_affectation'].find(qry_affectation):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
related_target_collection_id_nom = ""
|
|
related_target_collection_object = ""
|
|
|
|
# Si le rattachement a un 'related_target_collection_id', alors cela veut dire qu'il faut aller chercher
|
|
# la cible de cette affection.
|
|
if( "related_collection_recid" in retval.keys() and "related_collection" in retval.keys()):
|
|
if( retval["related_collection_recid"] and retval["related_collection"]):
|
|
|
|
|
|
# Si l'affectation concerne un salarié
|
|
if (retval["related_collection"] == "ressource_humaine"):
|
|
# Si l'affectation concerne un salarié
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_collection_recid"])),
|
|
'partner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
if (affectation_target_data is not None):
|
|
related_target_collection_id_nom = str(affectation_target_data["prenom"]+" "+affectation_target_data["nom"])
|
|
related_target_collection_object = "Employe"
|
|
|
|
|
|
# 11/01/2024 - Update : affectation d'un materiel a un materiel
|
|
# Si l'affectation concerne un materiel (oui car un materiel peut rattaché à un materiel)
|
|
elif (retval["related_collection"] == "ressource_materielle"):
|
|
# Si l'affectation concerne un materiel
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_collection_recid"])),
|
|
'partner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
if (affectation_target_data is not None):
|
|
related_target_collection_id_nom = str(
|
|
affectation_target_data["ref_interne"] + " " + affectation_target_data["nom"])
|
|
related_target_collection_object = "Materiel"
|
|
|
|
user['related_target_collection_id_nom'] = related_target_collection_id_nom
|
|
user['related_target_collection_object'] = related_target_collection_object
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
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 affectations de l'employé "
|
|
|
|
|
|
"""
|
|
Recuperation des types de ressources materielles (consommable, stockable ou autre)
|
|
"""
|
|
def Get_Type_Ressource_Materielle(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']
|
|
|
|
# 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"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = "default"
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_materielle_type'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
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 types de ressource materielle "
|
|
|
|
|
|
"""
|
|
Recuperation des catégories materiel
|
|
(salles, infomatique, autre, etc)
|
|
"""
|
|
def Get_Categorie_Ressource_Materielle(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']
|
|
|
|
# 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"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = "default"
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_materielle_categorie'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
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 catégories de ressource materielle "
|