02/09/22 - 16h00

master
ChérifBALDE 2022-09-02 16:18:48 +02:00 committed by cherif
parent 943a4b5fc8
commit 31e54f0c13
3 changed files with 72 additions and 40 deletions

View File

@ -145,8 +145,22 @@ Taux de TVA
TVA_TAUX = 0.2
"""
Connexion SFTP
"""
MYSY_FTP_HOST = "192.168.1.21"
MYSY_FTP_LOGIN = "cherif"
MYSY_FTP_PWD = "liambalde"
"""
Repertoire de depot des factures
"""
#INVOICE_DIRECTORY = "/tmp/Invoices/"
INVOICE_DIRECTORY = "C:/Users/ChérifBALDE/Desktop/Tmp_New/"
#INVOICE_DIRECTORY = "/var/www/html/sftp_iexercice/mysy_invoices"
INVOICE_DIRECTORY = "./Invoices/"
"""
Repertoire racine du ftp ou sont stocké les factures
"""
INVOICE_FTP_DIRECTORY = "https://sftp.iexercice.com/mysy_invoices/"
INVOICE_FTP_LOCAL_STORAGE_DIRECTORY = "/var/www/html/sftp_iexercice/mysy_invoices/"

View File

@ -22,7 +22,8 @@ from dateutil import tz
import pytz
from xhtml2pdf import pisa
import jinja2
import ftplib
import pysftp
class JSONEncoder(json.JSONEncoder):
def default(self, o):
@ -93,8 +94,12 @@ def get_invoice_by_customer(diction):
user = retVal
if ("_id" in user.keys()):
user['class_id'] = user.pop('_id')
user['lien_pdf'] = str(MYSY_GV.INVOICE_FTP_DIRECTORY)+str("invoice_")+str(user['invoice_id'])+str(".pdf")
RetObject.append(JSONEncoder().encode(user))
print(" les facture du client = "+str(RetObject))
#print(" les facture du client = "+str(RetObject))
return True, RetObject
except Exception as e:
@ -475,16 +480,16 @@ def createOrder(diction):
i = 0
while (i < nb_line):
print("PRODUIT N° " + str((i + 1)) + " : " )
#print("PRODUIT N° " + str((i + 1)) + " : " )
line_dict = json.loads(diction[str(i)])
print(" line = "+str(line_dict)+" -- le type est : "+str(type(line_dict)))
print(" code = "+str( line_dict['code'] ))
print(" prix = " + str(line_dict['prix']))
print(" qty = " + str(line_dict['qty']))
print(" les produits du pack = " + str(line_dict['pack_products']))
#print(" line = "+str(line_dict)+" -- le type est : "+str(type(line_dict)))
#print(" code = "+str( line_dict['code'] ))
#print(" prix = " + str(line_dict['prix']))
#print(" qty = " + str(line_dict['qty']))
#print(" les produits du pack = " + str(line_dict['pack_products']))
montant_line = mycommon.tryFloat(str(line_dict['prix'])) * mycommon.tryInt(str(line_dict['qty']))
print(" montant_line = " + str(montant_line))
#print(" montant_line = " + str(montant_line))
total_ht = total_ht + montant_line
@ -505,7 +510,7 @@ def createOrder(diction):
new_data['total_ttc'] = mycommon.tryFloat(str(total_ht)) + mycommon.tryFloat(str(new_data['total_tva']))
total_ttc_float = mycommon.tryFloat(str(new_data['total_ttc']))
print("str(new_data['total_ttc']) === " + str(total_ttc_float))
#print("str(new_data['total_ttc']) === " + str(total_ttc_float))
if (part_account.count() <= 0 and total_ttc_float > 0):
mycommon.myprint(
@ -513,8 +518,8 @@ def createOrder(diction):
return False, " Aucune donnée de payement,, Impossible de créer la commande ", None
print(" new_data['total_ht'] = "+str(new_data['total_ht']) + " -- new_data['total_tva'] "
+str(new_data['total_tva'])+ " -- new_data['total_ttc'] = "+ str(new_data['total_ttc']))
#print(" new_data['total_ht'] = "+str(new_data['total_ht']) + " -- new_data['total_tva'] "
# +str(new_data['total_tva'])+ " -- new_data['total_ttc'] = "+ str(new_data['total_ttc']))
# Les données de payement ne sont utilisées que si le montant > 0
if (total_ttc_float > 0):
@ -559,7 +564,7 @@ def createOrder(diction):
new_data['order_id'] = "MySy_00"+str(mycommon.create_order_id())
print(" la line à facturer est ::::: "+str(new_data))
#print(" la line à facturer est ::::: "+str(new_data))
# Enregistrement de la commande dans la systeme
@ -567,7 +572,7 @@ def createOrder(diction):
ret_val = coll_order.insert_one(new_data)
if ret_val and ret_val.inserted_id:
print( "str(new_data['invoice_email']) = "+str(new_data['invoice_email']))
#print( "str(new_data['invoice_email']) = "+str(new_data['invoice_email']))
# Envoie de l'email
email.SalesOrderConfirmationEmail(str(new_data['invoice_email']), new_data )
@ -584,7 +589,7 @@ def createOrder(diction):
)
# Facturation de la commande
print(" ######## lancement de la facturation total_ttc_float = " + str(total_ttc_float))
#print(" ######## lancement de la facturation total_ttc_float = " + str(total_ttc_float))
if (total_ttc_float > 0):
CreateInvoice(new_data)
@ -639,7 +644,7 @@ def CreateInvoice(diction):
3]) + " Impossible de recuperer Get_Last_Invoice_ID ")
return False, " Impossible de créer la facture"
print(" ######## last_invoice_id = "+str(last_invoice_id))
#print(" ######## last_invoice_id = "+str(last_invoice_id))
last_invoice_id = last_invoice_id + 1
Order_Invoice = "MySy_0000"+str(last_invoice_id)
diction['invoice_id']= str(Order_Invoice)
@ -648,7 +653,7 @@ def CreateInvoice(diction):
diction['invoice_date'] = str(now.strftime("%d/%m/%Y"))
diction['printed'] = "0"
print(" collection de facture = "+str(diction))
#print(" collection de facture = "+str(diction))
coll_facture = MYSY_GV.dbname['factures']
ret_val = coll_facture.insert_one(diction)
@ -747,7 +752,8 @@ def convertHtmlToPdf(diction):
}
sourceHtml = template.render(json_data=body["data"])
outputFilename = "invoice_"+str(diction['invoice_id'])+"_.pdf"
orig_file_name = "invoice_"+str(diction['invoice_id'])+".pdf"
outputFilename = str(MYSY_GV.INVOICE_DIRECTORY)+str(orig_file_name)
# open output file for writing (truncated binary)
resultFile = open(outputFilename, "w+b")
@ -761,17 +767,29 @@ def convertHtmlToPdf(diction):
resultFile.close()
mycommon.myprint(
str(inspect.stack()[0][3]) +" debut envoie de la factureeee "+diction['invoice_id'])
#mycommon.myprint(str(inspect.stack()[0][3]) +" debut envoie de la factureeee "+diction['invoice_id'])
email.SendInvoiceEmail(str(diction['invoice_email']), diction )
# On deplace la facture vers le serveur ftp
mycommon.myprint(
str(inspect.stack()[0][3]) + " deplacement de la facture vers " + str(MYSY_GV.INVOICE_DIRECTORY) + str(
'''mycommon.myprint(
str(inspect.stack()[0][3]) + " deplacement de la facture vers " + str(
outputFilename))
'''
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 ... ")
localFilePath = outputFilename
remoteFilePath = str(MYSY_GV.INVOICE_FTP_LOCAL_STORAGE_DIRECTORY)+str(orig_file_name)
#print(" DEPLACEMENT DE " + str(localFilePath) + " VERS " + str(remoteFilePath) + " AVANTTT TRAITEMENT")
# Use put method to upload a file
session.put(localFilePath, remoteFilePath)
# Switch to a remote directory
mycommon.myprint(
str(inspect.stack()[0][3])+" DEPLACEMENT DE "+str(localFilePath)+" VERS "+str(remoteFilePath)+" EST OKKKK")
os.rename(outputFilename, MYSY_GV.INVOICE_DIRECTORY + outputFilename)
# return True on success and False on errors

View File

@ -403,14 +403,14 @@ def SalesOrderConfirmationEmail(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("client_name = "+str(client_name))
print("client_address = " + str(client_address))
print("client_zip_ville = " + str(client_zip_ville))
print("client_pays = " + str(client_pays))
print("order_id = " + str(order_id))
print("date_order = " + str(date_order))
print("nb_line = " + str(nb_line))
print("End Date = " + str(my_end_date))
#print("client_name = "+str(client_name))
#print("client_address = " + str(client_address))
#print("client_zip_ville = " + str(client_zip_ville))
#print("client_pays = " + str(client_pays))
#print("order_id = " + str(order_id))
#print("date_order = " + str(date_order))
#print("nb_line = " + str(nb_line))
#print("End Date = " + str(my_end_date))
# Recuperation des produits (max 3 produits)
# produit 1
@ -421,7 +421,7 @@ def SalesOrderConfirmationEmail(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()):
@ -445,14 +445,14 @@ def SalesOrderConfirmationEmail(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(" mail enoye à toaddrs : " + toaddrs)
print("debut envoi mail de test ")
#print(" mail enoye à toaddrs : " + toaddrs)
#print("debut envoi mail de test ")
# on rentre les renseignements pris sur le site du fournisseur
msg = MIMEMultipart("alternative")
@ -464,7 +464,7 @@ def SalesOrderConfirmationEmail(account_mail, diction):
to = [{"email": str(account_mail)}]
print(" ############# to = "+str(to))
#print(" ############# to = "+str(to))
bcc = [{"email": "contact@mysy-training.com"}]
@ -614,7 +614,7 @@ def SendInvoiceEmail(account_mail, diction):
to = [{"email": str(account_mail)}]
print(" Facture ############# to = "+str(to))
#print(" Facture ############# to = "+str(to))
bcc = [{"email": "contact@mysy-training.com"}]
@ -639,7 +639,7 @@ def SendInvoiceEmail(account_mail, diction):
"orign_order":orign_order,
}, to=to, bcc=bcc)
api_response = api_instance.send_transac_email(send_smtp_email)
print("Facture "+str(api_response))
#print("Facture "+str(api_response))
return True
except Exception as e: