1226 lines
48 KiB
Python
1226 lines
48 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_id', 'priorite', 'commentaire',
|
|
'vendeur_id', 'date_fermeture', 'raison_perte', 'raison_gain' ]
|
|
|
|
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( "contact_email" in diction.keys() and diction['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_id', 'priorite', 'commentaire',
|
|
'vendeur_id', 'date_fermeture', 'opport_id', 'date_fermeture', 'raison_perte', 'raison_gain',]
|
|
|
|
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() and diction['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', 'revenu_cible_superieur', 'revenu_cible_inferieur','date_fermeture_avant',
|
|
'date_fermeture_apres', 'partner_client_nom', 'titre']
|
|
|
|
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_titre = {}
|
|
if ("titre" in diction.keys()):
|
|
filt_titre = {'titre': {'$regex': str(diction['titre']), "$options": "i"}}
|
|
|
|
filt_vendeur_id = {}
|
|
if ("vendeur_id" in diction.keys()):
|
|
filt_vendeur_id = {'vendeur_id': str(diction['vendeur_id'])}
|
|
|
|
# Recuperer les client dont le nom contient 'partner_client_nom'
|
|
filt_partner_client_id = {}
|
|
list_client_id = []
|
|
if ("partner_client_nom" in diction.keys() and diction['partner_client_nom']):
|
|
|
|
qry_sub_filter_client = {'nom': {'$regex': str(diction['partner_client_nom']), "$options": "i"},
|
|
'partner_recid':my_partner['recid'], 'valide':'1', 'locked':'0'}
|
|
for tmp_val in MYSY_GV.dbname['partner_client'].find(qry_sub_filter_client):
|
|
list_client_id.append(str(tmp_val['_id']))
|
|
|
|
filt_partner_client_id = { 'partner_client_id': { '$in': list_client_id } }
|
|
|
|
|
|
filt_revenu_cible_superieur = {}
|
|
if ("revenu_cible_superieur" in diction.keys() and diction['revenu_cible_superieur']):
|
|
val_revenu_cible_superieur = diction['revenu_cible_superieur']
|
|
local_status, local_val = mycommon.IsFloat(val_revenu_cible_superieur)
|
|
if( local_status is False) :
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le revenu cible superieur " + str(
|
|
val) + " n'est pas valide ")
|
|
return False, " Le revenu cible superieur " + str(
|
|
val) + " n'est pas valide "
|
|
|
|
|
|
filt_revenu_cible_superieur = { '$expr': { '$gte': [{ '$toDouble': '$revenu_cible'}, local_val]}}
|
|
|
|
filt_revenu_cible_inferieur = {}
|
|
if ("revenu_cible_inferieur" in diction.keys() and diction['revenu_cible_inferieur']):
|
|
val_revenu_cible_inferieur = diction['revenu_cible_inferieur']
|
|
local_status, local_val = mycommon.IsFloat(val_revenu_cible_inferieur)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le revenu cible superieur " + str(
|
|
val) + " n'est pas valide ")
|
|
return False, " Le revenu cible superieur " + str(
|
|
val) + " n'est pas valide "
|
|
|
|
|
|
filt_revenu_cible_inferieur = { '$expr': { '$lte': [{ '$toDouble': '$revenu_cible'}, local_val]}}
|
|
|
|
|
|
filter_date_fermeture_avant = {}
|
|
if ("date_fermeture_avant" in diction.keys()):
|
|
if diction['date_fermeture_avant']:
|
|
filter_date_fermeture_avant = str(diction['date_fermeture_avant'])[0:10]
|
|
local_status = mycommon.CheckisDate(filter_date_fermeture_avant)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fermeture " + str(filter_date_fermeture_avant) + " n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, " La date de fermeture " + str(filter_date_fermeture_avant) + " n'est pas au format 'jj/mm/aaaa'"
|
|
|
|
|
|
filter_date_fermeture_apres = {}
|
|
if ("date_fermeture_apres" in diction.keys()):
|
|
if diction['date_fermeture_apres']:
|
|
filter_date_fermeture_apres = str(diction['date_fermeture_apres'])[0:10]
|
|
local_status = mycommon.CheckisDate(filter_date_fermeture_apres)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fermeture " + str(
|
|
filter_date_fermeture_apres) + " n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, " La date de fermeture " + str(
|
|
filter_date_fermeture_apres) + " n'est pas au format 'jj/mm/aaaa'"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
qry = {"partner_owner_recid":str(my_partner['recid']), 'valide':'1', 'locked':'0'}
|
|
query_with_filter = {'$and': [qry, filt_titre, filt_vendeur_id, filt_revenu_cible_superieur,
|
|
filt_revenu_cible_inferieur, filt_partner_client_id, filt_partner_client_id ]}
|
|
|
|
print(" #### query_with_filter ttt = ", query_with_filter)
|
|
|
|
for New_retVal in MYSY_GV.dbname['crm_opportunite'].find(query_with_filter).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = New_retVal
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
""" Recuperer les données du statut """
|
|
statut = ""
|
|
if ('statut_id' in New_retVal.keys()):
|
|
statut_data = MYSY_GV.dbname['base_partner_opportunite_step'].find_one(
|
|
{'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'_id': ObjectId(str(New_retVal['statut_id']))})
|
|
|
|
if (statut_data and 'code' in statut_data.keys()):
|
|
statut = statut_data['code']
|
|
|
|
user['statut'] = statut
|
|
|
|
client_nom = ""
|
|
if ("partner_client_id" in New_retVal.keys() and New_retVal['partner_client_id']):
|
|
partner_client_data = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(str(New_retVal['partner_client_id'])), 'valide': '1', 'locked': '0',
|
|
'partner_recid': str(my_partner['recid'])})
|
|
|
|
if ("nom" in partner_client_data.keys()):
|
|
client_nom = partner_client_data['nom']
|
|
|
|
user['client_nom'] = client_nom
|
|
|
|
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'] = ""
|
|
|
|
New_retVal_date_fermeture = datetime.strptime(str(New_retVal['date_fermeture'])[0:10], '%d/%m/%Y').strftime("%d/%m/%Y")
|
|
|
|
|
|
if (filter_date_fermeture_avant and filter_date_fermeture_apres):
|
|
|
|
if (datetime.strptime(str(New_retVal_date_fermeture)[0:10], '%d/%m/%Y') <= datetime.strptime(str(filter_date_fermeture_avant)[0:10], '%d/%m/%Y') and
|
|
datetime.strptime(str(New_retVal_date_fermeture)[0:10], '%d/%m/%Y') >= datetime.strptime(
|
|
str(filter_date_fermeture_apres)[0:10], '%d/%m/%Y')
|
|
|
|
):
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
elif (filter_date_fermeture_avant):
|
|
if ( datetime.strptime(str(New_retVal_date_fermeture)[0:10], '%d/%m/%Y') <= datetime.strptime(str(filter_date_fermeture_avant)[0:10], '%d/%m/%Y')):
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
elif (filter_date_fermeture_apres):
|
|
if ( datetime.strptime(str(New_retVal_date_fermeture)[0:10], '%d/%m/%Y') >= datetime.strptime(str(filter_date_fermeture_apres)[0:10], '%d/%m/%Y')):
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
else:
|
|
|
|
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'}
|
|
|
|
|
|
|
|
for New_retVal in MYSY_GV.dbname['crm_opportunite'].find(qry).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = New_retVal
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
|
|
""" Recuperer les données du statut """
|
|
statut = ""
|
|
if( 'statut_id' in New_retVal.keys() ):
|
|
statut_data = MYSY_GV.dbname['base_partner_opportunite_step'].find_one({'partner_owner_recid':my_partner['recid'],
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'_id':ObjectId(str(New_retVal['statut_id']))})
|
|
|
|
if( statut_data and 'code' in statut_data.keys()):
|
|
statut = statut_data['code']
|
|
|
|
user['statut'] = statut
|
|
|
|
|
|
client_nom = ""
|
|
if ("partner_client_id" in New_retVal.keys() and New_retVal['partner_client_id']):
|
|
partner_client_data = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(str(New_retVal['partner_client_id'])), 'valide': '1', 'locked': '0',
|
|
'partner_recid': str(my_partner['recid'])})
|
|
|
|
if ("nom" in partner_client_data.keys()):
|
|
client_nom = partner_client_data['nom']
|
|
|
|
user['client_nom'] = client_nom
|
|
|
|
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'] = ""
|
|
|
|
|
|
|
|
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).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = New_retVal
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
""" Recuperer les données du statut """
|
|
statut = ""
|
|
if ('statut_id' in New_retVal.keys()):
|
|
statut_data = MYSY_GV.dbname['base_partner_opportunite_step'].find_one(
|
|
{'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'_id': ObjectId(str(New_retVal['statut_id']))})
|
|
|
|
if (statut_data and 'code' in statut_data.keys()):
|
|
statut = statut_data['code']
|
|
|
|
user['statut'] = statut
|
|
|
|
|
|
client_nom = ""
|
|
if ("partner_client_id" in New_retVal.keys() and New_retVal['partner_client_id']):
|
|
partner_client_data = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(str(New_retVal['partner_client_id'])), 'valide': '1', 'locked': '0',
|
|
'partner_recid': str(my_partner['recid'])})
|
|
|
|
if ("nom" in partner_client_data.keys()):
|
|
client_nom = partner_client_data['nom']
|
|
|
|
user['client_nom'] = client_nom
|
|
|
|
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'] = ""
|
|
|
|
|
|
|
|
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 supprimer 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é "
|
|
|
|
|
|
"""
|
|
Supprimer une étape d'opportunité.
|
|
/!\ Ceci n'est possible que si aucune opportunité n'a cette étape
|
|
"""
|
|
def Delete_CRM_List_Opportunite_Etape(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'est pas autorisé")
|
|
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 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
|
|
|
|
"""
|
|
Verifier que cette étape n'est utilisé par aucune opportunité
|
|
"""
|
|
is_etape_used = MYSY_GV.dbname['crm_opportunite'].count_documents({"partner_owner_recid":str(my_partner['recid']),
|
|
'valide':'1',
|
|
'statut_id':diction['_id']})
|
|
if( is_etape_used > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Cette étape est actuellement utilisée par "+str(is_etape_used)+" opportunités")
|
|
return False, " Cette étape est actuellement utilisée par "+str(is_etape_used)+" opportunités "
|
|
|
|
|
|
# Supression à faire
|
|
MYSY_GV.dbname['base_partner_opportunite_step'].delete_one(
|
|
{"partner_owner_recid": str(my_partner['recid']),
|
|
|
|
'_id': ObjectId(str(diction['_id']))})
|
|
|
|
|
|
return True, " L'étape 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 recuperer les étapes des opportunité "
|
|
|
|
|
|
"""
|
|
Mettre à jour une étape d'opportunité
|
|
"""
|
|
|
|
def Update_CRM_List_Opportunite_Etape(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', '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', '_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
|
|
|
|
"""
|
|
Verifier que cette étape existe
|
|
"""
|
|
is_etape_used = MYSY_GV.dbname['base_partner_opportunite_step'].count_documents({"partner_owner_recid":str(my_partner['recid']),
|
|
'valide':'1',
|
|
'_id':ObjectId(str(diction['_id']))})
|
|
if( is_etape_used < 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'étape est invalide ")
|
|
return False, " L'identifiant de l'étape est invalide "
|
|
|
|
|
|
new_data = {}
|
|
local_id = diction['_id']
|
|
|
|
new_data = diction
|
|
del diction['_id']
|
|
del diction['token']
|
|
|
|
data_cle = {'_id': ObjectId(str(local_id)), 'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid']), }
|
|
|
|
inserted_id = ""
|
|
result = MYSY_GV.dbname['base_partner_opportunite_step'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if (result is None or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour l'étape (2) ")
|
|
return False, " Impossible de mettre à jour l'étape (2) "
|
|
|
|
|
|
|
|
|
|
return True, " L'étape 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'étape "
|
|
|