613 lines
25 KiB
Python
613 lines
25 KiB
Python
'''
|
|
Ce fichier traite tout ce qui est liée à la gestion des codes promo
|
|
'''
|
|
|
|
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
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction créer un code promo
|
|
Elle verifie que ce code n'existe pas deja
|
|
- controle sur les date de validé
|
|
- controle sur le type de code
|
|
"""
|
|
def Add_Code_Promo(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
'''
|
|
# 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 = [ 'code', 'type', 'description', 'valeur', 'date_debut', 'date_fin' ]
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, mise à jour logo lms annulée")
|
|
return False, " Les informations fournies sont incorrecte",
|
|
|
|
'''
|
|
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 = ['code', 'type', 'description', 'valeur', 'date_debut', 'date_fin' ]
|
|
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 incorrecte",
|
|
|
|
|
|
code = ""
|
|
if ("code" in diction.keys()):
|
|
if diction['code']:
|
|
code = diction['code']
|
|
|
|
if (len(code) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'description' fait plus de 255 caracteres ")
|
|
|
|
return False, " - Le champ 'description' fait plus de 255 caracteres "
|
|
|
|
my_type = ""
|
|
if ("type" in diction.keys()):
|
|
if diction['type']:
|
|
my_type = diction['type']
|
|
|
|
if( my_type not in ['fix', 'percent'] ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - La valeur du type = "+str(my_type)+" n'est pas accepté. Les valeurs autorisées sont : 'fix' ou 'percent'")
|
|
return False, str(inspect.stack()[0][
|
|
3]) + " - La valeur du type = "+str(my_type)+" n'est pas accepté. Les valeurs autorisées sont : 'fix' ou 'percent'",
|
|
|
|
|
|
description = ""
|
|
if ("description" in diction.keys()):
|
|
if diction['description']:
|
|
description = diction['description']
|
|
|
|
if(len(description) > 255 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'description' fait plus de 255 caracteres ")
|
|
|
|
return False, " - Le champ 'description' fait plus de 255 caracteres "
|
|
|
|
|
|
valeur = ""
|
|
if ("valeur" in diction.keys()):
|
|
if diction['valeur']:
|
|
valeur = diction['valeur']
|
|
|
|
local_status, valeur = mycommon.IsFloat(valeur)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'valeur' est incorrecte. la veleur attendue est un entier ou un decimal.")
|
|
return False, " Le champ 'valeur' est incorrecte. la veleur attendue est un entier ou un decimal. "
|
|
|
|
date_debut = ""
|
|
if ("date_debut" in diction.keys()):
|
|
if diction['date_debut']:
|
|
date_debut = diction['date_debut']
|
|
|
|
# Controle de cohérence sur date_debut
|
|
local_status = mycommon.CheckisDate(str(date_debut)[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La date de debut n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " - La date de debut n'est pas au format jj/mm/aaaa "
|
|
|
|
|
|
date_fin = ""
|
|
if ("date_fin" in diction.keys()):
|
|
if diction['date_fin']:
|
|
date_fin = diction['date_fin']
|
|
|
|
# Controle de cohérence sur date_fin
|
|
local_status = mycommon.CheckisDate(str(date_fin)[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La date de fin n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " - La date de fin n'est pas au format jj/mm/aaaa "
|
|
|
|
# Controle de cohérence des dates entre elles
|
|
if (datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La date debut " + str(
|
|
diction['date_debut']) + " est postérieure à la date de fin " + str(diction['date_fin']) )
|
|
|
|
return False, " La date debut " + str(diction['date_debut']) + \
|
|
" est postérieure à la date de fin " + str(diction['date_fin']) + " "
|
|
|
|
"""
|
|
Verification un tel code promo n'existe pas deja
|
|
"""
|
|
tmp_count = MYSY_GV.dbname['code_promo'].count_documents({'code': str(code), 'valide': '1'})
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
" Le code promo '" + str(code) + "' existe deja, impossible d'ajouter la promotion ")
|
|
return False, " Le code promo '" + str(code) + "' existe deja, impossible d'ajouter la promotion "
|
|
|
|
data = {}
|
|
data['code'] = code
|
|
data['type'] = my_type
|
|
data['description'] = description
|
|
data['valeur'] = valeur
|
|
data['date_debut'] = date_debut
|
|
data['date_fin'] = date_fin
|
|
|
|
inserted_id = ""
|
|
inserted_id = MYSY_GV.dbname['code_promo'].insert_one(data).inserted_id
|
|
if( not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le code promo o '" + str(code) + "' ")
|
|
return False, " Impossible de créer le code promo o '" + str(code) + "' "
|
|
|
|
return True, " Le code promo " + str(code) +" 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 de créer le code promo "
|
|
|
|
|
|
"""
|
|
Cette fonction retourne les code promo valides
|
|
- valide = 1
|
|
- Date debut et Date fin sont ok
|
|
"""
|
|
def Get_Valide_Code_Promo(diction):
|
|
try:
|
|
|
|
field_list = ['token',]
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Le champ '" + val + "' n'est pas autorisé, Creation partenaire annulée")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste 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, "Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
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, " Les données de connexion sont incorrectes "
|
|
|
|
coll_session = MYSY_GV.dbname['code_promo']
|
|
myquery = {}
|
|
myquery['valide'] = "1"
|
|
myquery['locked'] = "0"
|
|
|
|
print(" ##### myquery = " + str(myquery))
|
|
RetObject = []
|
|
|
|
for retval in coll_session.find(myquery):
|
|
# print(" ##### retval = " + str(retval))
|
|
debut_debut = datetime.strptime(str(retval['date_debut']).strip(), '%d/%m/%Y')
|
|
date_fin = datetime.strptime(str(retval['date_fin']).strip(), '%d/%m/%Y')
|
|
if (debut_debut <= datetime.now() and date_fin >= datetime.now() and retval['type'] in ['fix', 'percent'] ):
|
|
RetObject.append(mycommon.JSONEncoder().encode(retval))
|
|
|
|
|
|
|
|
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de récupérer la liste des codes promo"
|
|
|
|
|
|
"""
|
|
Cette fonction retourne tous les codes promo, peut importe la validité
|
|
"""
|
|
def Get_All_Code_Promo(diction):
|
|
try:
|
|
|
|
field_list = ['token',]
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Le champ '" + val + "' n'est pas autorisé, Creation partenaire annulée")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste 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, "Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
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, " Les données de connexion sont incorrectes "
|
|
|
|
coll_session = MYSY_GV.dbname['code_promo']
|
|
|
|
RetObject = []
|
|
|
|
for retval in coll_session.find({}):
|
|
# print(" ##### retval = " + str(retval))
|
|
debut_debut = datetime.strptime(str(retval['date_debut']).strip(), '%d/%m/%Y')
|
|
date_fin = datetime.strptime(str(retval['date_fin']).strip(), '%d/%m/%Y')
|
|
if (debut_debut <= datetime.now() and date_fin >= datetime.now()):
|
|
RetObject.append(mycommon.JSONEncoder().encode(retval))
|
|
|
|
|
|
|
|
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de récupérer la liste des codes promo"
|
|
|
|
|
|
"""
|
|
Cette fonction met à jour un code promo.
|
|
|
|
Un code promo est modifiable tant qu'il n'est pas "is_used"
|
|
"""
|
|
def Update_Code_Promo(diction):
|
|
try:
|
|
'''
|
|
# 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 = [ 'code', 'type', 'description', 'valeur', 'date_debut', 'date_fin' ]
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, mise à jour logo lms annulée")
|
|
return False, " Les informations fournies sont incorrecte",
|
|
|
|
'''
|
|
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 = ['code', 'type', 'description', 'valeur', 'date_debut', 'date_fin' ]
|
|
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 incorrecte",
|
|
|
|
|
|
code = ""
|
|
if ("code" in diction.keys()):
|
|
if diction['code']:
|
|
code = diction['code']
|
|
|
|
my_type = ""
|
|
if ("type" in diction.keys()):
|
|
if diction['type']:
|
|
my_type = diction['type']
|
|
|
|
if( my_type not in ['fix', 'percent'] ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - La valeur du type = "+str(my_type)+" n'est pas accepté. Les valeurs autorisées sont : 'fix' ou 'percent'")
|
|
return False, str(inspect.stack()[0][
|
|
3]) + " - La valeur du type = "+str(my_type)+" n'est pas accepté. Les valeurs autorisées sont : 'fix' ou 'percent'",
|
|
|
|
|
|
description = ""
|
|
if ("description" in diction.keys()):
|
|
if diction['description']:
|
|
description = diction['description']
|
|
|
|
if(len(description) > 255 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le champ 'description' fait plus de 255 caracteres ")
|
|
|
|
return False, " - Le champ 'description' fait plus de 255 caracteres "
|
|
|
|
|
|
valeur = ""
|
|
if ("valeur" in diction.keys()):
|
|
if diction['valeur']:
|
|
valeur = diction['valeur']
|
|
|
|
local_status, valeur = mycommon.IsFloat(valeur)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'valeur' est incorrecte. la veleur attendue est un entier ou un decimal.")
|
|
return False, " Le champ 'valeur' est incorrecte. la veleur attendue est un entier ou un decimal. "
|
|
|
|
date_debut = ""
|
|
if ("date_debut" in diction.keys()):
|
|
if diction['date_debut']:
|
|
date_debut = diction['date_debut']
|
|
|
|
# Controle de cohérence sur date_debut
|
|
local_status = mycommon.CheckisDate(str(date_debut)[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La date de debut n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " - La date de debut n'est pas au format jj/mm/aaaa "
|
|
|
|
|
|
date_fin = ""
|
|
if ("date_fin" in diction.keys()):
|
|
if diction['date_fin']:
|
|
date_fin = diction['date_fin']
|
|
|
|
# Controle de cohérence sur date_fin
|
|
local_status = mycommon.CheckisDate(str(date_fin)[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La date de fin n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " - La date de fin n'est pas au format jj/mm/aaaa "
|
|
|
|
# Controle de cohérence des dates entre elles
|
|
if (datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La date debut " + str(
|
|
diction['date_debut']) + " est postérieure à la date de fin " + str(diction['date_fin']) )
|
|
|
|
return False, " La date debut " + str(diction['date_debut']) + \
|
|
" est postérieure à la date de fin " + str(diction['date_fin']) + " "
|
|
|
|
"""
|
|
Verification un tel code promo n'existe pas deja
|
|
"""
|
|
tmp_count = MYSY_GV.dbname['code_promo'].count_documents({'code': str(code), 'valide': '1'})
|
|
if (tmp_count < 0):
|
|
mycommon.myprint(
|
|
" Le code promo '" + str(code) + "' existe pas")
|
|
return False, " Le code promo '" + str(code) + "' existe pas "
|
|
|
|
tmp_count = MYSY_GV.dbname['code_promo'].count_documents({'code': str(code), 'valide': '1', 'is_used':'1'})
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
" Le code promo '" + str(code) + "' est déjà utilisé")
|
|
return False, " Le code promo '" + str(code) + "' est déjà utilisé "
|
|
|
|
|
|
data = {}
|
|
data['code'] = code
|
|
data['type'] = my_type
|
|
data['description'] = description
|
|
data['valeur'] = valeur
|
|
data['date_debut'] = date_debut
|
|
data['date_fin'] = date_fin
|
|
|
|
inserted_id = ""
|
|
result = MYSY_GV.dbname['code_promo'].find_one_and_update(
|
|
{'code': str(code), 'locked': '0', 'valide': '1'},
|
|
{"$set": data},
|
|
upsert= False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if( not result):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le code promo '" + str(code) + "' ")
|
|
return False, " Impossible de mettre à jour le code promo '" + str(code) + "' "
|
|
|
|
return True, " Le code promo " + str(code) +" 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 le code promo "
|
|
|
|
"""
|
|
Cette fonction prend un code promo, verifie sa validité et retourne les valeurs / type associées
|
|
"""
|
|
def Get_Given_Code_Promo(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
field_list = ['token','code_promo']
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Le champ '" + val + "' n'est pas autorisé, Creation partenaire annulée")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token','code_promo']
|
|
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, "Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
code_promo = ""
|
|
if ("code_promo" in diction.keys()):
|
|
if diction['code_promo']:
|
|
code_promo = diction['code_promo']
|
|
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
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, " Les données de connexion sont incorrectes "
|
|
|
|
coll_session = MYSY_GV.dbname['code_promo']
|
|
myquery = {}
|
|
myquery['valide'] = "1"
|
|
myquery['locked'] = "0"
|
|
|
|
myquery['code'] = code_promo
|
|
|
|
print(" ##### myquery = " + str(myquery))
|
|
RetObject = []
|
|
nb_val = 0
|
|
is_code_promo_expired = "0"
|
|
for retval in coll_session.find(myquery):
|
|
print(" ##### retval = " + str(retval))
|
|
debut_debut = datetime.strptime(str(retval['date_debut']).strip(), '%d/%m/%Y')
|
|
date_fin = datetime.strptime(str(retval['date_fin']).strip(), '%d/%m/%Y')
|
|
if (debut_debut <= datetime.now() and date_fin >= datetime.now() and retval['type'] in ['fix', 'percent'] ):
|
|
RetObject.append(mycommon.JSONEncoder().encode(retval))
|
|
nb_val = nb_val + 1
|
|
elif ( debut_debut > datetime.now() or date_fin < datetime.now() ):
|
|
is_code_promo_expired = "1"
|
|
nb_val = -1
|
|
|
|
|
|
# Si aucun code valide trouvé, on retourne false aussi.
|
|
if( is_code_promo_expired == "0" and nb_val == 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le code promo '"+str(code_promo)+"' n'existe pas ")
|
|
return False, "Le code promo n'existe pas "
|
|
|
|
|
|
# Si le code promo existe mais que la date de validité est incorrecte
|
|
if( is_code_promo_expired != "0" ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Les dates du code promo '" + str(code_promo) + "' ne sont pas valides ")
|
|
return False, " Les dates du code promo ne sont pas valides "
|
|
|
|
|
|
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de récupérer le code promo"
|
|
|
|
"""
|
|
Cette fonction verifie si un code promo est valide
|
|
"""
|
|
def Is_Valide_Code_Promo(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
field_list = ['token','code_promo']
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Le champ '" + val + "' n'est pas autorisé, Creation partenaire annulée")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token','code_promo']
|
|
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, "Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
code_promo = ""
|
|
if ("code_promo" in diction.keys()):
|
|
if diction['code_promo']:
|
|
code_promo = diction['code_promo']
|
|
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
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, " Les données de connexion sont incorrectes "
|
|
|
|
coll_session = MYSY_GV.dbname['code_promo']
|
|
myquery = {}
|
|
myquery['valide'] = "1"
|
|
myquery['locked'] = "0"
|
|
|
|
myquery['code'] = code_promo
|
|
|
|
RetObject = []
|
|
nb_val = 0
|
|
for retval in coll_session.find(myquery):
|
|
debut_debut = datetime.strptime(str(retval['date_debut']).strip(), '%d/%m/%Y')
|
|
date_fin = datetime.strptime(str(retval['date_fin']).strip(), '%d/%m/%Y')
|
|
if (debut_debut <= datetime.now() and date_fin >= datetime.now() and retval['type'] in ['fix', 'percent'] ):
|
|
RetObject.append(mycommon.JSONEncoder().encode(retval))
|
|
nb_val = nb_val + 1
|
|
|
|
# Si aucun code valide trouvé, on retourne false aussi.
|
|
if( nb_val == 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le code promo '"+str(code_promo)+"' n'est pas valide ")
|
|
return False, " - Le code promo '"+str(code_promo)+"' n'est pas valide "
|
|
|
|
return True, "- Le code promo '"+str(code_promo)+"' est valide "
|
|
|
|
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 de verifier la validité du code le code promo" |