03/09/22 - 14h30

master
ChérifBALDE 2022-09-03 14:43:58 +02:00 committed by cherif
parent 31e54f0c13
commit ef776922b9
4 changed files with 107 additions and 14 deletions

View File

@ -150,8 +150,8 @@ TVA_TAUX = 0.2
Connexion SFTP
"""
MYSY_FTP_HOST = "192.168.1.21"
MYSY_FTP_LOGIN = "cherif"
MYSY_FTP_PWD = "liambalde"
MYSY_FTP_LOGIN = "mysysftpuser"
MYSY_FTP_PWD = "JvMysedrBsDMy01!+"
"""
Repertoire de depot des factures

View File

@ -24,6 +24,7 @@ from xhtml2pdf import pisa
import jinja2
import ftplib
import pysftp
from flask import send_file
class JSONEncoder(json.JSONEncoder):
def default(self, o):
@ -801,3 +802,79 @@ def convertHtmlToPdf(diction):
str(inspect.stack()[0][3]) +"Exception when calling SMTPApi->send_transac_email: %s\n" % e)
return False
"""
Cette fonction la facture PDF d'un client
"""
def GetCustomerInvoice(diction):
try:
'''
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', 'invoiceid']
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 la facture"
user_recid = "None"
my_token = ""
my_invoiceid = ""
my_invoice_name = ""
if ("token" in diction.keys()):
if diction['token']:
my_token = diction['token']
if ("invoiceid" in diction.keys()):
if diction['invoiceid']:
my_invoiceid = diction['invoiceid']
my_invoice_name = 'invoice_'+str(my_invoiceid)+".pdf"
#print(" on cherche la facure :"+my_invoice_name)
# 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 la formation"
# 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 la formation"
if (len(str(my_token)) <= 0):
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide")
return False, " Impossible de recuperer la facture"
# Recuperation de la facture depuis le serveur sFTP
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection(host=MYSY_GV.MYSY_FTP_HOST, username=MYSY_GV.MYSY_FTP_LOGIN,
password=MYSY_GV.MYSY_FTP_PWD, cnopts=cnopts) as session:
#print("Connection successfully established ... ")
session.chdir(MYSY_GV.INVOICE_FTP_LOCAL_STORAGE_DIRECTORY)
#print('our current working directory is: ', session.pwd)
session.get(my_invoice_name, './temp_direct/'+str(my_invoice_name))
if os.path.exists("./temp_direct/"+str(my_invoice_name)):
path = "./temp_direct/"+str(my_invoice_name)
return send_file(path, as_attachment=True)
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, "KO"

View File

@ -553,14 +553,14 @@ def SendInvoiceEmail(account_mail, diction):
mycommon.myprint(str(inspect.stack()[0][3]) + " - nb_line = '" + nb_line + "' : Aucun produit à facturer")
return False, " Impossible d'envoyer l'email de confirmation"
print("Facture client_name = "+str(client_name))
print("Facture client_address = " + str(client_address))
print("Facture client_zip_ville = " + str(client_zip_ville))
print("Facture client_pays = " + str(client_pays))
print("Facture order_id = " + str(order_id))
print("Facture date_order = " + str(date_order))
print("Facture nb_line = " + str(nb_line))
print("Facture End Date = " + str(my_end_date))
#print("Facture client_name = "+str(client_name))
#print("Facture client_address = " + str(client_address))
#print("Facture client_zip_ville = " + str(client_zip_ville))
#print("Facture client_pays = " + str(client_pays))
#print("Facture order_id = " + str(order_id))
#print("Facture date_order = " + str(date_order))
#print("Facture nb_line = " + str(nb_line))
#print("Facture End Date = " + str(my_end_date))
# Recuperation des produits (max 3 produits)
# produit 1
@ -571,7 +571,7 @@ def SendInvoiceEmail(account_mail, diction):
unit_price = diction["item_0"]['prix']
montant = diction["item_0"]['amount']
detail_packs = diction["item_0"]['pack_products']
print("diction['item_0']['pack_products'] = "+str(diction["item_0"]['pack_products']))
#print("diction['item_0']['pack_products'] = "+str(diction["item_0"]['pack_products']))
# produit 2
if ("item_1" in diction.keys()):
@ -595,14 +595,14 @@ def SendInvoiceEmail(account_mail, diction):
i = 0
while (i < nb_line):
row = "item_" + str(i)
print(" product = "+ str(diction[str(row)]))
#print(" product = "+ str(diction[str(row)]))
i = i + 1
receiver = [str(account_mail)]
toaddrs = ", ".join(receiver)
print("Facture mail enoye à toaddrs : " + toaddrs)
print("Facture debut envoi mail de test ")
#print("Facture mail enoye à toaddrs : " + toaddrs)
#print("Facture debut envoi mail de test ")
# on rentre les renseignements pris sur le site du fournisseur
msg = MIMEMultipart("alternative")

16
main.py
View File

@ -1342,6 +1342,22 @@ def PutClassNote():
status, message = mycommon.PutClassNote()
return jsonify(status=status, message=message)
"""
Cette API envoie la facture d'un client
"""
@app.route('/myclass/api/GetCustomerInvoice/<token>/<invoiceid>', methods=['GET','POST'])
@crossdomain(origin='*')
def GetCustomerInvoice(invoiceid, token):
# On recupere le corps (payload) de la requete
payload = request.form.to_dict()
payload = {}
payload['token'] = str(token)
payload['invoiceid'] = str(invoiceid)
print(" ### payload facture = ", str(invoiceid), " token = ",str(token))
return factures.GetCustomerInvoice(payload)
if __name__ == '__main__':