Elyos_FI_Back_Office/crm_opportunite.py

887 lines
33 KiB
Python

"""
Ce fichier permet de gerer les opportunités CRM
Une opportunité est definie par :
partner_client_id (pas obligatoire)
contact :
civilite
Nom
email
telephone
titre
description
target_revenu
probailite
statut
priorite
commentaire
vendeur
date_fermeture
regle :
Si le client est connu, on remplie le contact avec les données venant du client.
On ne modifie pas les champs contact.
Si le partner_client_id est vide, alors l'utilisateur peut remplir les champs contact.
"""
import bson
import pymongo
from pymongo import MongoClient
import json
from bson import ObjectId
import re
from datetime import datetime
import prj_common as mycommon
import secrets
import inspect
import sys, os
import csv
import pandas as pd
from pymongo import ReturnDocument
import GlobalVariable as MYSY_GV
from math import isnan
import GlobalVariable as MYSY_GV
import ela_index_bdd_classes as eibdd
import email_mgt as email
import jinja2
from flask import send_file
from xhtml2pdf import pisa
from email.message import EmailMessage
from email.mime.text import MIMEText
from email import encoders
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
"""
Ajout d'une opportunite
"""
"""
Fonction d'ajout d'une étape (configuration) d'opportunité
"""
def Add_CRM_Opportunite(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'partner_client_id', 'contact_civilite', 'contact_nom', 'contact_email', 'contact_telephone',
'titre', 'description', 'revenu_cible', 'probabilite_gain', 'statut', 'priorite', 'commentaire',
'vendeur_id', 'date_fermeture']
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', 'contact_civilite', 'contact_nom', 'contact_email', 'contact_telephone',
'titre', ]
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Les informations fournies sont incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
mydata = {}
mydata = diction
del mydata['token']
# Initialisation des champs non envoyés à vide
for val in field_list:
if val not in diction.keys():
mydata[str(val)] = ""
# Verifier les valeurs de la probabilité de gain
if( "probabilite_gain" in diction.keys() ):
if( str(diction['probabilite_gain']).lower().strip() not in MYSY_GV.CRM_GAIN_PROBABILITE):
mycommon.myprint(str(inspect.stack()[0][3]) + " La probabilité de gain " + str(
diction['probabilite_gain']) + " n'est pas valide. Les valeurs autorisées "+str(MYSY_GV.CRM_GAIN_PROBABILITE))
return False, " La probabilité de gain " + str(
diction['probabilite_gain']) + " n'est pas valide. Les valeurs autorisées "+str(MYSY_GV.CRM_GAIN_PROBABILITE)
mydata['probabilite_gain'] = str(diction['probabilite_gain']).lower().strip()
partner_client_id = ""
if( "partner_client_id" in diction['partner_client_id'] and diction['partner_client_id']):
partner_client_id = diction['partner_client_id']
# Verifier la valididé du client id
is_client_id_valide = MYSY_GV.dbname["partner_client"].count_documents({'_id':ObjectId(str(partner_client_id)),
'valide':'1',
'locked':'0',
'partner_recid':str(my_partner['recid'])})
if( is_client_id_valide != 1):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant du client_id est invalide ")
return False, " L'identifiant du client_id est invalide "
# Verifier la validié de l'adress contact_email
if (mycommon.isEmailValide(str(diction['contact_email'])) is False ):
mycommon.myprint(str(inspect.stack()[0][3]) + " L'adresse email " + str(diction['contact_email']) + " n'est pas valide")
return False, " L'adresse email " + str(diction['contact_email']) + " n'est pas valide "
# Verifier la valide du vendeur_id
if( "vendeur_id" in diction.keys() and diction['vendeur_id']):
is_vendeur_id_valide = MYSY_GV.dbname['ressource_humaine'].count_documents({'_id':ObjectId(str(diction['vendeur_id'])),
'partner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'})
if( is_vendeur_id_valide != 1 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant du vendeur_id est invalide ")
return False, " L'identifiant du vendeur_id est invalide "
mydata['date_update'] = str(datetime.now())
mydata['update_by'] = str(my_partner['_id'])
mydata['partner_owner_recid'] = str(my_partner['recid'])
mydata['valide'] = "1"
mydata['locked'] = "0"
inserted_id = MYSY_GV.dbname['crm_opportunite'].insert_one(mydata).inserted_id
if (not inserted_id):
mycommon.myprint(" Impossible de créer l'opportunité (2) ")
return False, " Impossible de créer l'opportunité (2) "
return True, " L'opportunité a été correctement ajoutée "
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de créer l'étape "
"""
Fonction de mise à jour d'une opportunité
"""
def Update_CRM_Opportunite(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'partner_client_id', 'contact_civilite', 'contact_nom', 'contact_email', 'contact_telephone',
'titre', 'description', 'revenu_cible', 'probabilite_gain', 'statut', 'priorite', 'commentaire',
'vendeur_id', 'date_fermeture', 'opport_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', 'opport_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 liste ")
return False, " Les informations fournies sont incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
opport_id = ""
if ("opport_id" in diction.keys()):
if diction['opport_id']:
opport_id = diction['opport_id']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
# Verifier que l'opportunité existe et est valide
is_valide_opport = MYSY_GV.dbname['crm_opportunite'].count_documents({'_id':ObjectId(str(opport_id)),
'valide':'1',
'locked':'0',
'partner_owner_recid':str(my_partner['recid'])})
if( is_valide_opport != 1):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant de l'opportunité est invalide ")
return False, " L'identifiant de l'opportunité client_id est invalide "
mydata = {}
mydata = diction
del mydata['token']
del mydata['opport_id']
# Verifier les valeurs de la probabilité de gain
if ("probabilite_gain" in diction.keys()):
if (str(diction['probabilite_gain']).lower().strip() not in MYSY_GV.CRM_GAIN_PROBABILITE):
mycommon.myprint(str(inspect.stack()[0][3]) + " La probabilité de gain " + str(
diction['probabilite_gain']) + " n'est pas valide. Les valeurs autorisées " + str(
MYSY_GV.CRM_GAIN_PROBABILITE))
return False, " La probabilité de gain " + str(
diction['probabilite_gain']) + " n'est pas valide. Les valeurs autorisées " + str(
MYSY_GV.CRM_GAIN_PROBABILITE)
mydata['probabilite_gain'] = str(diction['probabilite_gain']).lower().strip()
partner_client_id = ""
if( "partner_client_id" in diction.keys() and diction['partner_client_id']):
partner_client_id = diction['partner_client_id']
# Verifier la valididé du client id
is_client_id_valide = MYSY_GV.dbname["partner_client"].count_documents({'_id':ObjectId(str(partner_client_id)),
'valide':'1',
'locked':'0',
'partner_recid':str(my_partner['recid'])})
if( is_client_id_valide != 1):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant du client_id est invalide ")
return False, " L'identifiant du client_id est invalide "
# Verifier la validié de l'adress contact_email
if( "contact_email" in diction.keys() ):
if (mycommon.isEmailValide(str(diction['contact_email'])) is False ):
mycommon.myprint(str(inspect.stack()[0][3]) + " L'adresse email " + str(diction['contact_email']) + " n'est pas valide")
return False, " L'adresse email " + str(diction['contact_email']) + " n'est pas valide "
# Verifier la valide du vendeur_id
if( "vendeur_id" in diction.keys() and diction['vendeur_id']):
is_vendeur_id_valide = MYSY_GV.dbname['ressource_humaine'].count_documents({'_id':ObjectId(str(diction['vendeur_id'])),
'partner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'})
if( is_vendeur_id_valide != 1 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant du vendeur_id est invalide ")
return False, " L'identifiant du vendeur_id est invalide "
mydata['date_update'] = str(datetime.now())
mydata['update_by'] = str(my_partner['_id'])
result = MYSY_GV.dbname['crm_opportunite'].find_one_and_update(
{'_id':ObjectId(str(opport_id)),
'partner_owner_recid':str(my_partner['recid'])},
{"$set": mydata},
upsert=False,
return_document=ReturnDocument.AFTER
)
if ("_id" not in result.keys()):
mycommon.myprint(
" Impossible de mettre à jour l'opportunité (2) ")
return False, " Impossible de mettre à jour l'opportunité (2) "
return True, " L'opportunité 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 l'opportunité "
"""
Recuperer la liste des opportunités d'un partenaire, avec des filtres
"""
def Get_List_CRM_Opportunite_with_filter(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'vendeur_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',]
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Les informations fournies sont incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
filt_vendeur_id = {}
if ("vendeur_id" in diction.keys()):
filt_vendeur_id = {'vendeur_id': str(diction['vendeur_id'])}
RetObject = []
val_tmp = 0
qry = {"partner_owner_recid":str(my_partner['recid']), 'valide':'1', 'locked':'0'}
query_with_filter = {'$and': [qry, filt_vendeur_id ]}
for New_retVal in MYSY_GV.dbname['crm_opportunite'].find(query_with_filter):
user = New_retVal
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
vendeur_nom = ""
vendeur_prenom = ""
if( "vendeur_id" in New_retVal.keys() and New_retVal['vendeur_id']):
Employee_data = MYSY_GV.dbname['ressource_humaine'].find_one(
{'_id': ObjectId(str(New_retVal['vendeur_id'])), 'valide': '1', 'locked': '0',
'partner_recid': str(my_partner['recid'])})
if( "nom" in Employee_data.keys()):
vendeur_nom = Employee_data['nom']
if ("prenom" in Employee_data.keys()):
vendeur_prenom = Employee_data['prenom']
user['vendeur_nom_prenom'] = vendeur_nom+" "+vendeur_prenom
if( "partner_client_id" not in New_retVal.keys() ):
user['partner_client_id'] = ""
if ("contact_civilite" not in New_retVal.keys()):
user['contact_civilite'] = ""
if ("contact_nom" not in New_retVal.keys()):
user['contact_nom'] = ""
if ("contact_email" not in New_retVal.keys()):
user['contact_email'] = ""
if ("contact_telephone" not in New_retVal.keys()):
user['contact_telephone'] = ""
if ("titre" not in New_retVal.keys()):
user['titre'] = ""
if ("description" not in New_retVal.keys()):
user['description'] = ""
if ("revenu_cible" not in New_retVal.keys()):
user['revenu_cible'] = ""
if ("probabilite_gain" not in New_retVal.keys()):
user['probabilite_gain'] = ""
if ("statut" not in New_retVal.keys()):
user['statut'] = ""
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 opportunités "
"""
Recuperer la liste des opportunités d'un partenaire, sans filtres
"""
def Get_List_CRM_Opportunite_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'est pas autorisé")
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 liste ")
return False, " Les informations fournies sont incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
RetObject = []
val_tmp = 0
qry = {"partner_owner_recid":str(my_partner['recid']), 'valide':'1', 'locked':'0'}
print(" ### qry 11 = ", qry)
for New_retVal in MYSY_GV.dbname['crm_opportunite'].find(qry):
user = New_retVal
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
vendeur_nom = ""
vendeur_prenom = ""
if( "vendeur_id" in New_retVal.keys() and New_retVal['vendeur_id']):
Employee_data = MYSY_GV.dbname['ressource_humaine'].find_one(
{'_id': ObjectId(str(New_retVal['vendeur_id'])), 'valide': '1', 'locked': '0',
'partner_recid': str(my_partner['recid'])})
if( "nom" in Employee_data.keys()):
vendeur_nom = Employee_data['nom']
if ("prenom" in Employee_data.keys()):
vendeur_prenom = Employee_data['prenom']
user['vendeur_nom_prenom'] = vendeur_nom+" "+vendeur_prenom
if ("partner_client_id" not in New_retVal.keys()):
user['partner_client_id'] = ""
if ("contact_civilite" not in New_retVal.keys()):
user['contact_civilite'] = ""
if ("contact_nom" not in New_retVal.keys()):
user['contact_nom'] = ""
if ("contact_email" not in New_retVal.keys()):
user['contact_email'] = ""
if ("contact_telephone" not in New_retVal.keys()):
user['contact_telephone'] = ""
if ("titre" not in New_retVal.keys()):
user['titre'] = ""
if ("description" not in New_retVal.keys()):
user['description'] = ""
if ("revenu_cible" not in New_retVal.keys()):
user['revenu_cible'] = ""
if ("probabilite_gain" not in New_retVal.keys()):
user['probabilite_gain'] = ""
if ("statut" not in New_retVal.keys()):
user['statut'] = ""
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 opportunités "
"""
Recuperer données d'une opportunité données
"""
def Get_Given_CRM_Opportunite(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'opport_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', 'opport_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 liste ")
return False, " Les informations fournies sont incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
RetObject = []
val_tmp = 0
qry = {"partner_owner_recid":str(my_partner['recid']), 'valide':'1', 'locked':'0', '_id':ObjectId(str(diction['opport_id']))}
for New_retVal in MYSY_GV.dbname['crm_opportunite'].find(qry):
user = New_retVal
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
vendeur_nom = ""
vendeur_prenom = ""
if( "vendeur_id" in New_retVal.keys() and New_retVal['vendeur_id']):
Employee_data = MYSY_GV.dbname['ressource_humaine'].find_one(
{'_id': ObjectId(str(New_retVal['vendeur_id'])), 'valide': '1', 'locked': '0',
'partner_recid': str(my_partner['recid'])})
if( "nom" in Employee_data.keys()):
vendeur_nom = Employee_data['nom']
if ("prenom" in Employee_data.keys()):
vendeur_prenom = Employee_data['prenom']
user['vendeur_nom_prenom'] = vendeur_nom+" "+vendeur_prenom
if ("partner_client_id" not in New_retVal.keys()):
user['partner_client_id'] = ""
if ("contact_civilite" not in New_retVal.keys()):
user['contact_civilite'] = ""
if ("contact_nom" not in New_retVal.keys()):
user['contact_nom'] = ""
if ("contact_email" not in New_retVal.keys()):
user['contact_email'] = ""
if ("contact_telephone" not in New_retVal.keys()):
user['contact_telephone'] = ""
if ("titre" not in New_retVal.keys()):
user['titre'] = ""
if ("description" not in New_retVal.keys()):
user['description'] = ""
if ("revenu_cible" not in New_retVal.keys()):
user['revenu_cible'] = ""
if ("probabilite_gain" not in New_retVal.keys()):
user['probabilite_gain'] = ""
if ("statut" not in New_retVal.keys()):
user['statut'] = ""
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 données de opportunité "
"""
Suppression d'un opportunité
"""
def Delete_Given_CRM_Opportunite(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'opport_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', 'opport_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 liste ")
return False, " Les informations fournies sont incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
# Verifier l'existance de l'opportunité
is_opportunit_valide = MYSY_GV.dbname['crm_opportunite'].count_documents({'_id':ObjectId(str(diction['opport_id'])),
'partner_owner_recid':str(my_partner['recid'])})
if (is_opportunit_valide != 1):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant de l'opportunité est invalide ")
return False, " L'identifiant de opportunité est invalide "
qry = {'_id':ObjectId(str(diction['opport_id'])), 'partner_owner_recid':str(my_partner['recid'])}
ret_site_formation = MYSY_GV.dbname['crm_opportunite'].delete_many(qry)
return True, "L'opportunité 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 récupérer les données de opportunité "
"""
Fonction d'ajout d'une étape (configuration) d'opportunité
"""
def Add_CRM_Opportunite_Etape(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'code', 'description', 'rang']
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', 'code', 'description', 'rang']
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Les informations fournies sont incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
# Verifier qu'il n'y pas deja un étape avec le meme code
is_opport_existe_etape = MYSY_GV.dbname['base_partner_opportunite_step'].count_documents({"code":str(diction['code']).lower(),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1'})
if( is_opport_existe_etape > 0 ):
mycommon.myprint(
" Il existe déjà une étape avec le code "+str(diction["code"]))
return False, " Il existe déjà une étape avec le code "+str(diction["code"])+" "
new_data = diction
del new_data['token']
new_data['code'] = str(diction['code']).lower()
new_data['date_update'] = str(datetime.now())
new_data['update_by'] = str(my_partner['recid'])
new_data['partner_owner_recid'] = str(my_partner['recid'])
new_data['valide'] = "1"
new_data['locked'] = "0"
val = MYSY_GV.dbname['base_partner_opportunite_step'].insert_one(new_data)
if( val is None ):
mycommon.myprint(
" Impossible de créer l'étape (2) ")
return False, " Impossible de créer l'étape (2) "
return True, " L'étape a été correctement créé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 créer l'étape "
"""
Recuperation de la liste des étapes d'un partenaire
"""
def Get_CRM_List_Opportunite_Etape(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'est pas autorisé")
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 liste ")
return False, " Les informations fournies sont incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
RetObject = []
val_tmp = 0
for retval in MYSY_GV.dbname['base_partner_opportunite_step'].find({
'valide': '1',
'locked': '0',
'partner_owner_recid': str(
my_partner['recid'])}).sort([("rang", pymongo.ASCENDING), ]):
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 recuperer les étapes des opportunité "