6/08/22 - 16h00
parent
399bafcc63
commit
b10e25eb7d
|
@ -20,6 +20,7 @@ from math import isnan
|
|||
import GlobalVariable as MYSY_GV
|
||||
|
||||
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
if isinstance(o, ObjectId):
|
||||
|
@ -481,7 +482,7 @@ def update_class(diction):
|
|||
mydata['indexed_obj'] = '0'
|
||||
|
||||
|
||||
coll_name = MYSY_GV.dbname['myclass']
|
||||
|
||||
coll_name = MYSY_GV.dbname['myclass']
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
"""
|
||||
Ce fichier permet de gerer les factures client
|
||||
"""
|
||||
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)
|
||||
|
||||
|
||||
def get_invoice_by_customer(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]) + " - 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 = ""
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_token = diction['token']
|
||||
|
||||
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_facture = MYSY_GV.dbname['factures']
|
||||
|
||||
for retVal in coll_facture.find({'client_recid':user_recid, 'valide': '1'} )\
|
||||
.sort([("date_facture", pymongo.ASCENDING), ("num_facture", pymongo.DESCENDING), ]):
|
||||
user = retVal
|
||||
if ("_id" in user.keys()):
|
||||
user['class_id'] = user.pop('_id')
|
||||
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 factures"
|
16
main.py
16
main.py
|
@ -24,7 +24,7 @@ import articles_avis as aa
|
|||
import GlobalVariable as MYSY_GV
|
||||
import youtubes_analyse as YTA
|
||||
import test_perso as TP
|
||||
|
||||
import ela_factures_mgt as invoice
|
||||
|
||||
app = Flask(__name__)
|
||||
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
|
||||
|
@ -1204,6 +1204,20 @@ def UpgradetoPro():
|
|||
|
||||
|
||||
|
||||
'''
|
||||
Cette API recupere les facture d'un client en prenant son tokek
|
||||
'''
|
||||
@app.route('/myclass/api/get_invoice_by_customer/', methods=['GET','POST'])
|
||||
@crossdomain(origin='*')
|
||||
def get_invoice_by_customer():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### payload = ", payload)
|
||||
status, result = invoice.get_invoice_by_customer(payload)
|
||||
return jsonify(status=status, message=result)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
context = SSL.Context(SSL.SSLv23_METHOD)
|
||||
|
|
Loading…
Reference in New Issue