05/06/22 - 14h30
parent
99fb1ddd77
commit
5ffbb1b45a
15
main.py
15
main.py
|
@ -25,6 +25,7 @@ import GlobalVariable as MYSY_GV
|
||||||
import youtubes_analyse as YTA
|
import youtubes_analyse as YTA
|
||||||
import test_perso as TP
|
import test_perso as TP
|
||||||
import ela_factures_mgt as invoice
|
import ela_factures_mgt as invoice
|
||||||
|
import product_service as PS
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
|
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
|
||||||
|
@ -1216,6 +1217,20 @@ def get_invoice_by_customer():
|
||||||
status, result = invoice.get_invoice_by_customer(payload)
|
status, result = invoice.get_invoice_by_customer(payload)
|
||||||
return jsonify(status=status, message=result)
|
return jsonify(status=status, message=result)
|
||||||
|
|
||||||
|
'''
|
||||||
|
Cette API recupere les produits et services d'un pack données.
|
||||||
|
Si le pack n'est pas defini, alors tous les produits valides sont
|
||||||
|
retournés
|
||||||
|
'''
|
||||||
|
@app.route('/myclass/api/get_product_service/', methods=['GET','POST'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def get_product_service():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
print(" ### payload = ", payload)
|
||||||
|
status, result = PS.get_product_service(payload)
|
||||||
|
return jsonify(status=status, message=result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
"""
|
||||||
|
Ce fichier permet de gerer les produits et service, les Packs vendu par MySy
|
||||||
|
"""
|
||||||
|
|
||||||
|
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
|
||||||
|
from math import isnan
|
||||||
|
import GlobalVariable as MYSY_GV
|
||||||
|
|
||||||
|
class JSONEncoder(json.JSONEncoder):
|
||||||
|
def default(self, o):
|
||||||
|
if isinstance(o, ObjectId):
|
||||||
|
return str(o)
|
||||||
|
return json.JSONEncoder.default(self, o)
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
Cette fonction recuperer produits et service avec possibilité de filtrer sur un pack'''
|
||||||
|
def get_product_service(diction):
|
||||||
|
try :
|
||||||
|
field_list = ['token', 'pack_name' ]
|
||||||
|
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " - Creation partner account : Le champ '" + val + "' n'existe pas, Creation formation annulée")
|
||||||
|
return False, " Impossible de recuperer les factures"
|
||||||
|
|
||||||
|
'''
|
||||||
|
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 liste ")
|
||||||
|
return False, " Impossible de recuperer les factures"
|
||||||
|
|
||||||
|
# recuperation des paramettre
|
||||||
|
|
||||||
|
my_token = ""
|
||||||
|
user_recid = ""
|
||||||
|
pack_name = ""
|
||||||
|
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
my_token = diction['token']
|
||||||
|
|
||||||
|
if ("pack_name" in diction.keys()):
|
||||||
|
if diction['pack_name']:
|
||||||
|
pack_name = str(diction['pack_name']).lower()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
user_recid = "None"
|
||||||
|
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||||
|
if (len(str(my_token)) > 0):
|
||||||
|
retval = mycommon.check_partner_token_validity("", my_token)
|
||||||
|
|
||||||
|
if retval is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
|
||||||
|
return False, " Impossible de recuperer les factures"
|
||||||
|
|
||||||
|
# Recuperation du recid de l'utilisateur
|
||||||
|
user_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||||
|
if user_recid is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le token de l'utilisateur")
|
||||||
|
return False, " Impossible de recuperer les factures"
|
||||||
|
|
||||||
|
if (len(str(my_token)) <= 0):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide")
|
||||||
|
return False, " Impossible de recuperer les factures"
|
||||||
|
|
||||||
|
RetObject = []
|
||||||
|
coll_db = MYSY_GV.dbname['produit_service']
|
||||||
|
|
||||||
|
if(len(str(pack_name)) > 0 ):
|
||||||
|
for retVal in coll_db.find({ 'valide': '1', 'packs':pack_name}) \
|
||||||
|
.sort([("date_facture", pymongo.ASCENDING), ("num_facture", pymongo.DESCENDING), ]):
|
||||||
|
user = retVal
|
||||||
|
|
||||||
|
RetObject.append(JSONEncoder().encode(user))
|
||||||
|
|
||||||
|
else:
|
||||||
|
for retVal in coll_db.find({'valide': '1'}) \
|
||||||
|
.sort([("date_facture", pymongo.ASCENDING), ("num_facture", pymongo.DESCENDING), ]):
|
||||||
|
user = retVal
|
||||||
|
|
||||||
|
RetObject.append(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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||||
|
return False, "Impossible de recuperer les produits et service"
|
Loading…
Reference in New Issue