parent
7bf9051417
commit
5818122cf1
|
|
@ -4,17 +4,18 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="21/02/26 - 20h">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="22/02/26 - 20h">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/E_Sign_Document.py" beforeDir="false" afterPath="$PROJECT_DIR$/E_Sign_Document.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Job_Cron.py" beforeDir="false" afterPath="$PROJECT_DIR$/Job_Cron.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Session_Formation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/competence_pedagogique.py" beforeDir="false" afterPath="$PROJECT_DIR$/competence_pedagogique.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/apprenant_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/apprenant_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/email_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/lms_chamilo/mysy_lms.py" beforeDir="false" afterPath="$PROJECT_DIR$/lms_chamilo/mysy_lms.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_client.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_client.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_invoice.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_invoice.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partners.py" beforeDir="false" afterPath="$PROJECT_DIR$/partners.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
@ -458,7 +459,7 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1747251650255</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="536" />
|
||||
<option name="localTasksCounter" value="538" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
|
@ -500,7 +501,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="12/11/2025 - 22h30" />
|
||||
<MESSAGE value="13/11/2025 - 22h30" />
|
||||
<MESSAGE value="15/11/2025 - 22h30" />
|
||||
<MESSAGE value="16/11/25 - 16h30" />
|
||||
|
|
@ -525,6 +525,7 @@
|
|||
<MESSAGE value="16/02/26 - 18h30" />
|
||||
<MESSAGE value="18/02/2026 - 18h" />
|
||||
<MESSAGE value="21/02/26 - 20h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="21/02/26 - 20h" />
|
||||
<MESSAGE value="22/02/26 - 20h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="22/02/26 - 20h" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -15500,6 +15500,220 @@ def Get_Insription_From_Session_id_Reduice_Fields_With_Filter(diction):
|
|||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction prend l'_id d'une session et retourne les inscriptions qui sont validé et celle en cours de validation
|
||||
(statut IN [0, 1, 2]
|
||||
avec un nombre de champs limité ET SURTOUT pour qui il reste des paiement à faire
|
||||
(inscription.invoiced != 1)
|
||||
"""
|
||||
def Get_Insription_From_Session_id_Reduice_Fields_With_Filter_With_To_Paie(diction):
|
||||
try:
|
||||
field_list = ['token', 'session_id', 'tab_statut_ids']
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " - Le champ '" + val + "' n'est pas autorisé, Creation partenaire annulée")
|
||||
return False, "de récupérer la liste des stagiaires . Toutes les informations fournies ne sont pas valables"
|
||||
|
||||
"""
|
||||
Verification de la liste des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'session_id']
|
||||
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 la liste des arguments ")
|
||||
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']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", mytoken)
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
||||
if (partner_recid is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer la liste des stagiaires, ")
|
||||
return False, "Impossible de récupérer la liste des stagiaires, Les informations d'identification sont incorrectes "
|
||||
|
||||
class_internal_url = ""
|
||||
if ("class_internal_url" in diction.keys()):
|
||||
if diction['class_internal_url']:
|
||||
class_internal_url = diction['class_internal_url']
|
||||
|
||||
session_id = ""
|
||||
if ("session_id" in diction.keys()):
|
||||
if diction['session_id']:
|
||||
session_id = diction['session_id']
|
||||
|
||||
tab_statut_ids = ""
|
||||
tab_statut_ids_filter = {}
|
||||
if ("tab_statut_ids" in diction.keys()):
|
||||
if diction['tab_statut_ids']:
|
||||
tab_statut_ids = diction['tab_statut_ids']
|
||||
|
||||
tab_statut_ids_splited = []
|
||||
tab_statut_ids_splited_work = str(tab_statut_ids).split(",")
|
||||
for tmp in tab_statut_ids_splited_work:
|
||||
if( tmp ):
|
||||
tab_statut_ids_splited.append(tmp)
|
||||
|
||||
|
||||
## Recuperation de toutes les stagiaire rattaché à cette session
|
||||
|
||||
myquery = {}
|
||||
myquery['session_id'] = session_id
|
||||
myquery['status'] = "1"
|
||||
myquery['valide'] = "1"
|
||||
myquery['invoiced'] = {'$ne':'1'}
|
||||
|
||||
if (len(tab_statut_ids_splited) > 0):
|
||||
myquery['status'] = {'$in': tab_statut_ids_splited}
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
#print(" #### myquery 01111 = "+str(myquery))
|
||||
|
||||
|
||||
for retval in MYSY_GV.dbname['inscription'].find(myquery,
|
||||
{'_id':1, 'email':1,
|
||||
'session_id':1,
|
||||
'apprenant_id':1,
|
||||
'nom':1,
|
||||
'prenom':1,
|
||||
|
||||
}).sort([("_id", pymongo.DESCENDING), ]):
|
||||
val_tmp = val_tmp + 1
|
||||
user = retval
|
||||
user['id'] = str(val_tmp)
|
||||
|
||||
apprenant_nom = str(retval['nom'])
|
||||
apprenant_prenom = str(retval['prenom'])
|
||||
apprenant_email = str(retval['email'])
|
||||
|
||||
# Si il a un apprenant_id
|
||||
# print(" ### retVal = ", retVal )
|
||||
if ("apprenant_id" in retval.keys()):
|
||||
if (retval['apprenant_id'] and str(retval['apprenant_id']) != 'undefined'):
|
||||
apprenant_retval = MYSY_GV.dbname['apprenant'].find_one(
|
||||
{'_id': ObjectId(retval['apprenant_id']),
|
||||
'valide': '1', 'locked': '0'})
|
||||
|
||||
if (apprenant_retval is not None):
|
||||
apprenant_nom = apprenant_retval['nom']
|
||||
apprenant_prenom = apprenant_retval['prenom']
|
||||
apprenant_email = apprenant_retval['email']
|
||||
|
||||
user['apprenant_nom'] = apprenant_nom
|
||||
user['apprenant_prenom'] = apprenant_prenom
|
||||
user['apprenant_email'] = apprenant_email
|
||||
|
||||
user['groupe'] = ""
|
||||
|
||||
RetObject.append(mycommon.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 récupérer la liste des stagiaires de la formation"
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction retourne le nombre de lignes completement
|
||||
facturée sur une session / promo
|
||||
"""
|
||||
def Get_Nb_Insription_From_Session_Full_Invoiced(diction):
|
||||
try:
|
||||
field_list = ['token', 'session_id']
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " - Le champ '" + val + "' n'est pas autorisé, Creation partenaire annulée")
|
||||
return False, "de récupérer la liste des stagiaires . Toutes les informations fournies ne sont pas valables"
|
||||
|
||||
"""
|
||||
Verification de la liste des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'session_id']
|
||||
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 la liste des arguments ")
|
||||
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']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", mytoken)
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
||||
if (partner_recid is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer la liste des stagiaires, ")
|
||||
return False, "Impossible de récupérer la liste des stagiaires, Les informations d'identification sont incorrectes "
|
||||
|
||||
|
||||
|
||||
## Recuperation de toutes les stagiaire rattaché à cette session
|
||||
|
||||
myquery = {}
|
||||
myquery['session_id'] = str(diction['session_id'])
|
||||
myquery['status'] = "1"
|
||||
myquery['valide'] = "1"
|
||||
myquery['invoiced'] = '1'
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
#print(" #### myquery 01111 = "+str(myquery))
|
||||
|
||||
nb_fully_invoiced_inscrit = MYSY_GV.dbname['inscription'].count_documents(myquery)
|
||||
|
||||
|
||||
myquery_nb_inscrit = {}
|
||||
myquery_nb_inscrit['session_id'] = str(diction['session_id'])
|
||||
myquery_nb_inscrit['status'] = "1"
|
||||
myquery_nb_inscrit['valide'] = "1"
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
# print(" #### myquery 01111 = "+str(myquery))
|
||||
|
||||
session_nb_inscrit = MYSY_GV.dbname['inscription'].count_documents(myquery_nb_inscrit)
|
||||
user = {"nb_fully_invoiced_inscrit":str(nb_fully_invoiced_inscrit), "session_nb_inscrit": str(session_nb_inscrit)}
|
||||
|
||||
RetObject.append(mycommon.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 récupérer le nombre d'inscription facturé "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction retourne la liste des UE aux quelles un apprenant est inscrit
|
||||
|
|
@ -17540,3 +17754,4 @@ def Get_Inscrit_By_Invoice_Status_For_List_Session(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer la liste des inscrits facturés "
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -435,7 +435,7 @@ def Cron_Monthly_Invoice_Inscription():
|
|||
|
||||
|
||||
"""
|
||||
1 - Recuprer la liste des client facturation mensuelle automatique
|
||||
1 - Recuprer la liste des clients facturation mensuelle automatique
|
||||
"""
|
||||
list_clients = []
|
||||
for client_data in MYSY_GV.dbname['partner_client'].find({'valide':'1',
|
||||
|
|
@ -513,8 +513,6 @@ def Cron_Monthly_Invoice_Inscription():
|
|||
for val in MYSY_GV.dbname['session_formation'].aggregate(pipe_qry):
|
||||
#print(" #### val = ", val)
|
||||
|
||||
|
||||
|
||||
if( str(client_data['_id']) not in list_client ):
|
||||
list_client.append(str(client_data['_id']))
|
||||
|
||||
|
|
@ -563,7 +561,7 @@ def Cron_Monthly_Invoice_Inscription():
|
|||
print(" Cette inscription a a déjà ete facturé le "+str(last_invoiced_date))
|
||||
|
||||
"""
|
||||
# On va aller prendre toutes les incriptions qui n'ont pas été facturées le mois en cours
|
||||
# On va aller prendre toutes les inscriptions qui n'ont pas été facturées le mois en cours
|
||||
"""
|
||||
if( inscription_allready_invoiced == "0"):
|
||||
local_node = {}
|
||||
|
|
|
|||
9329
Log/log_file.log
9329
Log/log_file.log
File diff suppressed because one or more lines are too long
|
|
@ -12134,6 +12134,10 @@ C'est a dire que ligne d'inscription dispose d'un champ : "invoice_split" qui es
|
|||
Pour etre valide, ce champs est de type :
|
||||
'invoice_split':{split_type : fixe/percent, tab_split : [{partner_client:cccc, invoice_part:40}, {partner_client:eeeeee, invoice_part:60} ....] }},
|
||||
|
||||
regles de concernant l'entité à facturer :
|
||||
- si l'inscrit n'a ni client_rattachement, ni client facturé, alors je créer le client lien a apprenant et je mets ce dernier comme client facturé
|
||||
- si j'ai un client de rattachement mais pas de client de facturation, alors je met le client_rattachement comme client facturé
|
||||
- si non si j'ai un client facturé, alors c'est ce dernier qui est facturé
|
||||
"""
|
||||
def Invoice_Inscrption_With_Split_Session_By_Inscription_Id( tab_files, diction):
|
||||
try:
|
||||
|
|
|
|||
182
apprenant_mgt.py
182
apprenant_mgt.py
|
|
@ -3601,3 +3601,185 @@ def Add_Update_Apprenant_Invoice_Data(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de mettre à jour les données de facturation "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Recuperer la liste des factures qui concerne un apprenant apprenant
|
||||
"""
|
||||
def Get_Tab_Apprenant_List_Invoices(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'tab_apprenant_ids']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'tab_apprenant_ids']
|
||||
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 la liste des arguments ")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
tab_apprenant_ids_work = str(diction['tab_apprenant_ids']).split(",")
|
||||
tab_apprenant_ids = []
|
||||
|
||||
for tmp in tab_apprenant_ids_work:
|
||||
if( tmp ):
|
||||
tab_apprenant_ids.append(tmp)
|
||||
|
||||
for val in tab_apprenant_ids :
|
||||
is_valide_apprenant = MYSY_GV.dbname['apprenant'].count_documents({'_id':ObjectId(str(val)),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( is_valide_apprenant != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de l'apprenant "+str(val)+" est invalide ")
|
||||
return False, " L'identifiant de l'apprenant "+str(val)+" est invalide "
|
||||
|
||||
|
||||
"""
|
||||
Récuperer la liste des inscriptions des apprenants
|
||||
"""
|
||||
tab_inscription = []
|
||||
for inscrip_tmp in MYSY_GV.dbname['inscription'].find({'valide':'1', 'partner_owner_recid':str(my_partner['recid']),
|
||||
'apprenant_id':{'$in':tab_apprenant_ids }}):
|
||||
tab_inscription.append(str(inscrip_tmp['_id']))
|
||||
|
||||
|
||||
"""
|
||||
Recuperer les factures concernant nos inscits depuis la collection
|
||||
"""
|
||||
tab_invoice_header_id = []
|
||||
tab_invoice_header_id_ObjectId = []
|
||||
for tmp in MYSY_GV.dbname['partner_invoice_line_detail'].find({'valide':'1', 'partner_owner_recid':str(my_partner['recid']),
|
||||
'order_line_inscription_id':{'$in':tab_inscription }}):
|
||||
tab_invoice_header_id.append(tmp['invoice_header_id'])
|
||||
tab_invoice_header_id_ObjectId.append(ObjectId(str(tmp['invoice_header_id'])))
|
||||
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
somme_header_ca_ht = 0
|
||||
nb_header_invoice = 0
|
||||
|
||||
for New_retVal in MYSY_GV.dbname['partner_invoice_header'].find({'valide':'1', 'partner_owner_recid':str(my_partner['recid']),
|
||||
'_id':{'$in':tab_invoice_header_id_ObjectId }} ).sort([("_id", pymongo.DESCENDING), ]):
|
||||
|
||||
user = New_retVal
|
||||
user['id'] = str(val_tmp)
|
||||
val_tmp = val_tmp + 1
|
||||
|
||||
"""
|
||||
recuperer le CA globale et le nombre de factures
|
||||
"""
|
||||
if ("total_header_hors_taxe_before_header_reduction" in New_retVal.keys()):
|
||||
somme_header_ca_ht = somme_header_ca_ht + mycommon.tryFloat(
|
||||
str(New_retVal['total_header_hors_taxe_before_header_reduction']))
|
||||
nb_header_invoice = nb_header_invoice + 1
|
||||
|
||||
# Convertir la date facture en jj/mm/aaaa
|
||||
if ('invoice_date' in New_retVal.keys()):
|
||||
date_jjmmaaa = str(New_retVal['invoice_date'])[0:10]
|
||||
# print(" ### date_jjmmaaa = ", date_jjmmaaa)
|
||||
# date_jjmmaaa = datetime.strptime(date_jjmmaaa, '%d/%m/%Y')
|
||||
# New_retVal['invoice_date'] = str(date_jjmmaaa)
|
||||
|
||||
# Si le champ 'order_header_condition_paiement_id' alors on va chercher le code de la condition de paiement
|
||||
paiement_ction_code = ""
|
||||
if ('order_header_condition_paiement_id' in New_retVal.keys() and New_retVal[
|
||||
'order_header_condition_paiement_id']):
|
||||
paiement_ction_data = MYSY_GV.dbname['base_partner_paiement_condition'].find_one(
|
||||
{'_id': ObjectId(str(New_retVal['order_header_condition_paiement_id'])), 'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (paiement_ction_data and 'code' in paiement_ction_data.keys()):
|
||||
paiement_ction_code = str(paiement_ction_data['code'])
|
||||
user['order_header_paiement_condition_code'] = paiement_ction_code
|
||||
|
||||
# Si le champ 'order_header_client_id' alors on va chercher le nom du client
|
||||
if ('order_header_client_id' in New_retVal.keys()):
|
||||
Client_data = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'_id': ObjectId(str(New_retVal['order_header_client_id'])), 'valide': '1', 'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (Client_data and 'nom' in Client_data.keys()):
|
||||
user['order_header_client_nom'] = str(Client_data['nom'])
|
||||
|
||||
# Si le champ 'order_header_vendeur_id' alors on va chercher le nom et prenom du vendeur (employe)
|
||||
if ('order_header_vendeur_id' in New_retVal.keys() and New_retVal['order_header_vendeur_id']):
|
||||
Employee_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
||||
{'_id': ObjectId(str(New_retVal['order_header_vendeur_id'])), 'valide': '1', 'locked': '0',
|
||||
'partner_recid': str(my_partner['recid'])})
|
||||
|
||||
order_header_vendeur_nom_prenom = ""
|
||||
if (Employee_data and 'nom' in Employee_data.keys()):
|
||||
order_header_vendeur_nom_prenom = str(Employee_data['nom'])
|
||||
|
||||
if (Employee_data and 'prenom' in Employee_data.keys()):
|
||||
order_header_vendeur_nom_prenom = str(order_header_vendeur_nom_prenom) + " " + str(
|
||||
Employee_data['prenom'])
|
||||
|
||||
user['order_header_vendeur_nom_prenom'] = str(order_header_vendeur_nom_prenom)
|
||||
|
||||
|
||||
|
||||
if ("credit_note_ref" not in New_retVal.keys()):
|
||||
user['credit_note_ref'] = ""
|
||||
|
||||
if ("invoice_header_origin" not in New_retVal.keys()):
|
||||
user['invoice_header_origin'] = ""
|
||||
|
||||
if ("reste_to_paye" not in New_retVal.keys()):
|
||||
user['reste_to_paye'] = str(user['total_header_toutes_taxes'])
|
||||
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
total_data = []
|
||||
node = {}
|
||||
node['somme_header_ca_ht'] = str(somme_header_ca_ht)
|
||||
node['nb_header_invoice'] = str(nb_header_invoice)
|
||||
|
||||
total_data.append(node)
|
||||
|
||||
total_data = mycommon.JSONEncoder().encode(total_data)
|
||||
|
||||
# print(" ### RetObject = ", RetObject)
|
||||
|
||||
return True, RetObject, total_data
|
||||
|
||||
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 récupérer la liste des factures de l'apprenant "
|
||||
|
||||
|
|
|
|||
96
email_mgt.py
96
email_mgt.py
|
|
@ -2684,6 +2684,102 @@ def ManualSendInvoiceEmailRIB_CIC_Xcelia(diction):
|
|||
|
||||
|
||||
|
||||
"""
|
||||
Creation manuelle d'une facture avec RIB ICOSS
|
||||
"""
|
||||
def ManualSendInvoiceEmailRIB_ICOSS(diction):
|
||||
try:
|
||||
'''
|
||||
Verification des données obligatoires
|
||||
'''
|
||||
'''
|
||||
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
|
||||
'''
|
||||
|
||||
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
|
||||
tomorrow_day = tomorrow.strftime("%A")
|
||||
|
||||
print("debut envoi mail de test ")
|
||||
# on rentre les renseignements pris sur le site du fournisseur
|
||||
|
||||
#smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
||||
|
||||
# msg = MIMEMultipart("alternative")
|
||||
#msg = EmailMessage()
|
||||
|
||||
# JINJA2
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath="./")
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
TEMPLATE_FILE = "Template/invoice_RIB_ICOSS_tpl.html"
|
||||
template = templateEnv.get_template(TEMPLATE_FILE)
|
||||
body = {
|
||||
"params": {"order_id": "N/A",
|
||||
"date_order": ": 29/10/2025",
|
||||
"periode":"",
|
||||
"total_ht": "1 500",
|
||||
"tva": "TVA non applicable",
|
||||
"total_ttc": "1 500",
|
||||
"client_name": "MySy Training Technology",
|
||||
"client_address": "Place des magnolias",
|
||||
"client_zip_ville": "77680 Roissy en brie",
|
||||
"client_pays": "France",
|
||||
"packs": " Qualification base de données Client (2 000 contacts)",
|
||||
"detail_packs": "Qualification Contact, Poste, Email, Téléphone",
|
||||
"qty": "1",
|
||||
"unit_price": "1 500 €",
|
||||
"montant": "1 500 €",
|
||||
|
||||
"invoice_id": "202602-005",
|
||||
"invoice_date": "01/02/2026",
|
||||
"due_date": "01/02/2026",
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#print(" ### body 1 = ", body)
|
||||
#sourceHtml = template.render(params=body["params"])
|
||||
sourceHtml = template.render(json_data=body["params"])
|
||||
|
||||
|
||||
### CREATION DE LA FACTION PDF
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath="./")
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
#TEMPLATE_FILE = "Template/MySy_Invoice_RIB_tpl.html"
|
||||
TEMPLATE_FILE = "Template/invoice_RIB_ICOSS_tpl.html"
|
||||
|
||||
template = templateEnv.get_template(TEMPLATE_FILE)
|
||||
# This data can come from database query
|
||||
|
||||
#print(" ### body 22 = ", body)
|
||||
|
||||
sourceHtml = template.render(json_data=body["params"])
|
||||
orig_file_name = "ICOSS_FACTURE_202602-005.pdf"
|
||||
outputFilename = str(MYSY_GV.INVOICE_DIRECTORY) + str(orig_file_name)
|
||||
|
||||
# open output file for writing (truncated binary)
|
||||
resultFile = open(outputFilename, "w+b")
|
||||
|
||||
# convert HTML to PDF
|
||||
pisaStatus = pisa.CreatePDF(
|
||||
src=sourceHtml, # the HTML to convert
|
||||
dest=resultFile) # file handle to receive result
|
||||
|
||||
# close output file
|
||||
resultFile.close()
|
||||
|
||||
return True, " facture envoyée"
|
||||
|
||||
|
||||
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, " impossible d'envoyer la facure"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Creation manuelle d'une facture avec RIB CIC pour France Active - perso
|
||||
"""
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
126
main.py
126
main.py
|
|
@ -3285,6 +3285,18 @@ def ManualSendInvoiceEmailRIB_CIC_Xcelia():
|
|||
|
||||
|
||||
|
||||
"""
|
||||
API Creation manuelle d'une facture avec RIB CIC pour ICOSS - perso
|
||||
"""
|
||||
@app.route('/myclass/api/ManualSendInvoiceEmailRIB_ICOSS/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def ManualSendInvoiceEmailRIB_ICOSS():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### ManualSendInvoiceEmailRIB_ICOSS : payload = ",str(payload))
|
||||
localStatus, message= emails.ManualSendInvoiceEmailRIB_ICOSS(payload)
|
||||
return jsonify(status=localStatus, message=message )
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -5524,6 +5536,38 @@ def Get_Insription_From_Session_id_Reduice_Fields_With_Filter():
|
|||
|
||||
|
||||
|
||||
"""
|
||||
API qui prend l'_id d'une session et retourne les inscriptions qui sont validé et celle en cours de validation
|
||||
(statut IN [0, 1, 2]
|
||||
avec un nombre de champs limité ET SURTOUT pour qui il reste des paiement à faire
|
||||
(inscription.invoiced != 1)
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Insription_From_Session_id_Reduice_Fields_With_Filter_With_To_Paie/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Insription_From_Session_id_Reduice_Fields_With_Filter_With_To_Paie():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Insription_From_Session_id_Reduice_Fields_With_Filter_With_To_Paie payload = ",payload)
|
||||
status, retval = inscription.Get_Insription_From_Session_id_Reduice_Fields_With_Filter_With_To_Paie(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API retourne le nombre de lignes completement
|
||||
facturée sur une session / promo
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Nb_Insription_From_Session_Full_Invoiced/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Nb_Insription_From_Session_Full_Invoiced():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Nb_Insription_From_Session_Full_Invoiced payload = ",payload)
|
||||
status, retval = inscription.Get_Nb_Insription_From_Session_Full_Invoiced(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
|
@ -6351,6 +6395,59 @@ def Disable_MySy_LMS_Account():
|
|||
|
||||
|
||||
|
||||
"""
|
||||
API qui recupre la liste de connexion d'une liste d'inscrits LMS
|
||||
"""
|
||||
@app.route('/myclass/api/Get_LMS_Connexion_List_Inscrit/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_LMS_Connexion_List_Inscrit():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_LMS_Connexion_List_Inscrit payload = ",payload)
|
||||
status, retval = mysy_lms.Get_LMS_Connexion_List_Inscrit(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API qui recupre la progression LMS d'une liste d'inscrit
|
||||
"""
|
||||
@app.route('/myclass/api/Get_LMS_Progress_List_Inscrit/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_LMS_Progress_List_Inscrit():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_LMS_Progress_List_Inscrit payload = ",payload)
|
||||
status, retval = mysy_lms.Get_LMS_Progress_List_Inscrit(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API qui retourne un suivi globale LMS
|
||||
(Liste des connexions et la progressions)
|
||||
"""
|
||||
@app.route('/myclass/api/Get_LMS_Connexion_List_And_Progress_Inscrit/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_LMS_Connexion_List_And_Progress_Inscrit():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_LMS_Connexion_List_And_Progress_Inscrit payload = ",payload)
|
||||
status, retval = mysy_lms.Get_LMS_Connexion_List_And_Progress_Inscrit(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
@app.route('/myclass/api/Get_LMS_Connexion_List_And_Progress_Inscrit_localhost/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_LMS_Connexion_List_And_Progress_Inscrit_localhost():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_LMS_Connexion_List_And_Progress_Inscrit_localhost payload = ",payload)
|
||||
status, retval = mysy_lms.Get_LMS_Connexion_List_And_Progress_Inscrit_localhost(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API qui ajoute une ressource materielles
|
||||
"""
|
||||
|
|
@ -10833,6 +10930,18 @@ def Get_Given_Inscrit_Invoices():
|
|||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API permet de créer la facture d'un inscrit
|
||||
input : inscription_id, montant à facturer
|
||||
"""
|
||||
@app.route('/myclass/api/Create_Inscrit_Invoice/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Create_Inscrit_Invoice():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Create_Inscrit_Invoice payload = ",payload)
|
||||
status, retval, ref_invoice= partner_invoice.Create_Inscrit_Invoice(payload)
|
||||
return jsonify(status=status, message=retval, ref_invoice=ref_invoice)
|
||||
|
||||
|
||||
"""
|
||||
|
|
@ -14949,6 +15058,23 @@ def Add_Update_Apprenant_Invoice_Data():
|
|||
|
||||
|
||||
|
||||
"""
|
||||
API pour Recuperer la liste des factures qui concerne un apprenant apprenant
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Tab_Apprenant_List_Invoices/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Tab_Apprenant_List_Invoices():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Tab_Apprenant_List_Invoices payload = ",payload)
|
||||
status, retval, total_data = apprenant_mgt.Get_Tab_Apprenant_List_Invoices(payload)
|
||||
return jsonify(status=status, message=retval, total_data=total_data)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API de creation d'un graphique et sauvegade en PNG
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ def Add_Partner_Client(diction):
|
|||
adr_pays = ""
|
||||
if ("adr_pays" in diction.keys()):
|
||||
if diction['adr_pays']:
|
||||
adr_pays = diction['siret']
|
||||
adr_pays = diction['adr_pays']
|
||||
data['adr_pays'] = adr_pays
|
||||
|
||||
tva = ""
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ from datetime import datetime, timedelta, date
|
|||
|
||||
import Session_Formation
|
||||
import invoice_paiement_mgt
|
||||
import module_editique
|
||||
import partner_base_setup
|
||||
import partner_client
|
||||
import partners
|
||||
import prj_common as mycommon
|
||||
import secrets
|
||||
|
|
@ -5270,6 +5273,8 @@ def Create_Invoice_Avoir_Total(diction):
|
|||
|
||||
"""
|
||||
Cette fonction permet de créer une facture depuis l'ecran des factures
|
||||
|
||||
|
||||
"""
|
||||
|
||||
def Add_Partner_Draft_Invoice(diction):
|
||||
|
|
@ -6588,7 +6593,7 @@ def Add_Update_Partner_Draft_Invoice_Line(diction):
|
|||
'invoice_header_id', 'invoice_line_status', 'invoice_line_type', 'order_line_comment',
|
||||
'order_line_montant_hors_taxes', 'order_line_tax_amount', 'order_line_montant_toutes_taxes',
|
||||
'order_line_type_article', 'order_line_taux_taxe', 'order_line_type_apprenant',
|
||||
'tab_inscription_ids', 'tab_inscription_ids_json', 'order_header_id']
|
||||
'tab_inscription_ids', 'order_header_id']
|
||||
|
||||
|
||||
incom_keys = diction.keys()
|
||||
|
|
@ -6639,8 +6644,6 @@ def Add_Update_Partner_Draft_Invoice_Line(diction):
|
|||
data[str(val)] = ""
|
||||
|
||||
|
||||
print(" ### data 011 = ", data)
|
||||
|
||||
invoice_header_id = ""
|
||||
if ("invoice_header_id" in diction.keys() and diction['invoice_header_id']):
|
||||
invoice_header_id = diction['invoice_header_id']
|
||||
|
|
@ -6726,10 +6729,10 @@ def Add_Update_Partner_Draft_Invoice_Line(diction):
|
|||
if diction['invoice_line_type']:
|
||||
invoice_line_type = diction['invoice_line_type']
|
||||
data['invoice_line_type'] = invoice_line_type
|
||||
if( invoice_line_type not in ['facture']):
|
||||
if( invoice_line_type not in ['facture', 'brouillon']):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur du champ 'invoice_line_type' est invalide. Les valeurs acceptées : 'facture' ")
|
||||
return False, " La valeur du champ 'invoice_line_type' est invalide. Les valeurs acceptées : 'facture' "
|
||||
str(inspect.stack()[0][3]) + " - La valeur du champ 'invoice_line_type' est invalide. Les valeurs acceptées : 'facture', 'brouillon' ")
|
||||
return False, " La valeur du champ 'invoice_line_type' est invalide. Les valeurs acceptées : 'facture', 'brouillon' "
|
||||
|
||||
invoice_line_status = ""
|
||||
if ("invoice_line_status" in diction.keys()):
|
||||
|
|
@ -6777,15 +6780,13 @@ def Add_Update_Partner_Draft_Invoice_Line(diction):
|
|||
|
||||
tab_inscrit_id = []
|
||||
tab_inscrit_id_work = []
|
||||
if( "tab_inscription_ids_json" in diction.keys() and diction['tab_inscription_ids_json']):
|
||||
for inscrit_data in diction['tab_inscription_ids_json']:
|
||||
tab_inscrit_id.append(inscrit_data)
|
||||
|
||||
elif ("tab_inscription_ids" in diction.keys() and diction['tab_inscription_ids']):
|
||||
tab_inscrit_id_JSON = ast.literal_eval(diction['tab_inscription_ids'])
|
||||
for inscrit_data in tab_inscrit_id_JSON:
|
||||
|
||||
|
||||
if ("tab_inscription_ids" in diction.keys() and diction['tab_inscription_ids']):
|
||||
for inscrit_data in diction['tab_inscription_ids']:
|
||||
tab_inscrit_id.append(inscrit_data)
|
||||
|
||||
print(" tab_inscrit_idtab_inscrit_id = ", tab_inscrit_id)
|
||||
|
||||
data['tab_inscription_ids'] = tab_inscrit_id
|
||||
|
||||
|
|
@ -7190,6 +7191,10 @@ def Delete_Partner_Draft_Invoice_Line(diction):
|
|||
"""
|
||||
Confirmation d'un brouillon de facture et transformation en facture reelle.
|
||||
La facture doit etre au statut 'Draft', puis passer au statut confirmé
|
||||
|
||||
Important :
|
||||
A la confirmation, on va aller créer le detail "partner_invoice_line_detail"
|
||||
|
||||
"""
|
||||
def Confirm_Partner_Invoice_Header_And_Lines(diction):
|
||||
try:
|
||||
|
|
@ -7317,9 +7322,6 @@ def Confirm_Partner_Invoice_Header_And_Lines(diction):
|
|||
data['update_date'] = now
|
||||
data['update_by'] = str(my_partner['_id'])
|
||||
|
||||
|
||||
print(" ### Update_partner_order data = ", data)
|
||||
|
||||
inserted_data = MYSY_GV.dbname['partner_invoice_header'].find_one_and_update(
|
||||
{'partner_owner_recid': str(my_partner['recid']),
|
||||
'valide': '1', 'locked': '0',
|
||||
|
|
@ -7365,6 +7367,185 @@ def Confirm_Partner_Invoice_Header_And_Lines(diction):
|
|||
if( local_retval is False) :
|
||||
mycommon.myprint(" WARNING : Apres la confirmation, La fonction compute pour la facture : "+str(comput_diction)+" n'a pas fonctionnée, ")
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Apres le compute, on va aller créer / update me contenu de la collection
|
||||
partner_invoice_line_detail
|
||||
"""
|
||||
tab_inscription = []
|
||||
|
||||
for new_invoice_data_line in MYSY_GV.dbname['partner_invoice_line'].find(
|
||||
{'partner_owner_recid': str(my_partner['recid']),
|
||||
'valide': '1', 'locked': '0',
|
||||
'invoice_header_id': str(invoice_header_id),
|
||||
}):
|
||||
|
||||
|
||||
if( "tab_inscription_ids" in new_invoice_data_line.keys()):
|
||||
for local_inscrit in new_invoice_data_line['tab_inscription_ids']:
|
||||
|
||||
inscrit_data = MYSY_GV.dbname['inscription'].find_one(
|
||||
{'_id': ObjectId(str(local_inscrit)), 'partner_owner_recid': my_partner['recid']})
|
||||
|
||||
tab_inscription.append(str(inscrit_data['_id']))
|
||||
|
||||
partner_invoice_line_data_detail = {}
|
||||
partner_invoice_line_data_detail['order_line_inscription_id'] = str(inscrit_data['_id'])
|
||||
partner_invoice_line_data_detail['order_line_inscription_type_apprenant'] = str( inscrit_data['type_apprenant'])
|
||||
partner_invoice_line_data_detail['order_line_inscription_modefinancement'] = str( inscrit_data['modefinancement'])
|
||||
partner_invoice_line_data_detail['order_line_formation'] = str( new_invoice_data_line['order_line_formation'])
|
||||
|
||||
"""
|
||||
27/07/25 : aller recuperer le 'class_id'
|
||||
"""
|
||||
local_class_id = ""
|
||||
if ("order_line_formation" in new_invoice_data_line.keys() and new_invoice_data_line[
|
||||
'order_line_formation']):
|
||||
class_data = MYSY_GV.dbname['myclass'].find_one(
|
||||
{'internal_url': str(new_invoice_data_line['order_line_formation']),
|
||||
'partner_owner_recid': str(my_partner['recid'])}, {'_id': 1})
|
||||
|
||||
if (class_data and '_id' in class_data.keys()):
|
||||
local_class_id = str(class_data['_id'])
|
||||
|
||||
partner_invoice_line_data_detail['order_line_class_id'] = local_class_id
|
||||
|
||||
partner_invoice_line_data_detail['order_line_prix_unitaire'] = str(inscrit_data['price'])
|
||||
partner_invoice_line_data_detail['order_line_montant_hors_taxes'] = str( new_invoice_data_line['order_line_montant_hors_taxes'])
|
||||
partner_invoice_line_data_detail['order_line_invoiced_amount'] = str(new_invoice_data_line['order_line_montant_hors_taxes'])
|
||||
partner_invoice_line_data_detail['order_line_qty'] = "1"
|
||||
|
||||
if ("order_line_tab_inscrit_id" in new_invoice_data_line.keys()):
|
||||
del new_invoice_data_line['order_line_tab_inscrit_id']
|
||||
|
||||
partner_invoice_line_data_detail['tab_inscription_ids'] = [ObjectId(str(inscrit_data['_id']))]
|
||||
|
||||
partner_invoice_line_data_detail['order_line_comment'] = ""
|
||||
partner_invoice_line_data_detail['invoice_header_id'] = str(new_invoice_data_line['invoice_header_id'])
|
||||
partner_invoice_line_data_detail['invoice_line_type'] = "facture"
|
||||
partner_invoice_line_data_detail['invoice_header_ref_interne'] = str(new_invoice_data_line['invoice_header_ref_interne'])
|
||||
|
||||
order_line_is_include_bpf = ""
|
||||
if ("order_header_inclus_bpf" in inserted_data.keys()):
|
||||
order_line_is_include_bpf = inserted_data['order_header_inclus_bpf']
|
||||
|
||||
partner_invoice_line_data_detail['order_line_is_include_bpf'] = order_line_is_include_bpf
|
||||
|
||||
partner_invoice_line_data_detail['update_by'] = str(my_partner['_id'])
|
||||
partner_invoice_line_data_detail['valide'] = "1"
|
||||
partner_invoice_line_data_detail['locked'] = "0"
|
||||
partner_invoice_line_data_detail['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
inserted_detail_invoice_line_id = MYSY_GV.dbname['partner_invoice_line_detail'].insert_one(
|
||||
partner_invoice_line_data_detail).inserted_id
|
||||
|
||||
ret_val = MYSY_GV.dbname['partner_invoice_line_detail'].find_one_and_update(
|
||||
{'order_line_inscription_id': str(inscrit_data['_id']), 'invoice_header_id': str(new_invoice_data_line['invoice_header_id']), },
|
||||
{"$set": partner_invoice_line_data_detail},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=True,
|
||||
)
|
||||
|
||||
if( ret_val and '_id' in ret_val.keys()):
|
||||
# On va aller mettre à jour l'inscription
|
||||
"""
|
||||
Recuperer le reste à facturer pour cette inscription
|
||||
"""
|
||||
local_diction = {'token': diction['token'], 'inscription_id': str(inscrit_data['_id'])}
|
||||
local_status, local_retval_invoices = Internal_Get_Given_Inscrit_Invoices(local_diction)
|
||||
if (local_status ):
|
||||
|
||||
reste_a_facturer = local_retval_invoices[0]['reste_a_facturer']
|
||||
frais_inscription = local_retval_invoices[0]['frais_inscription']
|
||||
|
||||
update_data = {}
|
||||
update_data['reste_a_facturer'] = reste_a_facturer
|
||||
|
||||
if("invoiced_ref" in inscrit_data.keys() ):
|
||||
update_data['invoiced_ref'] = str(new_invoice_data_line['invoice_header_ref_interne'])+", "+str(inscrit_data['invoiced_ref'])
|
||||
else:
|
||||
update_data['invoiced_ref'] = str(new_invoice_data_line['invoice_header_ref_interne'])
|
||||
|
||||
if(float(reste_a_facturer) <= 0 ):
|
||||
update_data['invoiced'] = "1"
|
||||
|
||||
|
||||
update2 = MYSY_GV.dbname['inscription'].find_one_and_update(
|
||||
{'_id': ObjectId(str(inscrit_data['_id'])), 'partner_owner_recid':str(my_partner['recid']) },
|
||||
{"$set": update_data},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=False,
|
||||
)
|
||||
|
||||
"""
|
||||
Si toutes les lignes sont facturé, alors on met l'entete à facturer
|
||||
ok
|
||||
"""
|
||||
is_all_session_line_not_invoiced = MYSY_GV.dbname['inscription'].count_documents({'session_id':str(inscrit_data['session_id']),
|
||||
'status':'1',
|
||||
'invoiced':{'$ne':'1'}})
|
||||
|
||||
is_all_session_line_invoiced = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'session_id': str(inscrit_data['session_id']),
|
||||
'status': '1',
|
||||
'invoiced': '1'})
|
||||
|
||||
|
||||
if( is_all_session_line_not_invoiced > 0 ):
|
||||
print(" QRYY = ", {'_id': ObjectId(str(inscrit_data['session_id'])),
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if( is_all_session_line_invoiced > 0 ):
|
||||
update_session_header = MYSY_GV.dbname['session_formation'].find_one_and_update(
|
||||
{'_id': ObjectId(str(inscrit_data['session_id'])),
|
||||
'partner_owner_recid': str(my_partner['recid'])},
|
||||
{"$set": {'invoiced_statut':'1'}},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=False,
|
||||
)
|
||||
else:
|
||||
update_session_header = MYSY_GV.dbname['session_formation'].find_one_and_update(
|
||||
{'_id': ObjectId(str(inscrit_data['session_id'])),
|
||||
'partner_owner_recid': str(my_partner['recid'])},
|
||||
{"$set": {'invoiced_statut': ''}},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=False,
|
||||
)
|
||||
|
||||
|
||||
else:
|
||||
print(" QRYY = ", {'_id': ObjectId(str(inscrit_data['session_id'])),
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
update_session_header = MYSY_GV.dbname['session_formation'].find_one_and_update(
|
||||
{'_id': ObjectId(str(inscrit_data['session_id'])),
|
||||
'partner_owner_recid': str(my_partner['recid'])},
|
||||
{"$set": {'invoiced_statut': '2'}},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=False,
|
||||
)
|
||||
|
||||
|
||||
|
||||
for local_inscrit in tab_inscription :
|
||||
inscrit_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(local_inscrit), 'partner_owner_recid':my_partner['recid']})
|
||||
|
||||
ref_facture = ""
|
||||
if ("invoice_header_ref_interne" in my_order_data_previous_information.keys()):
|
||||
ref_facture = my_order_data_previous_information['invoice_header_ref_interne']
|
||||
|
||||
local_status, local_retval = module_editique.Editic_Log_History_Action_From_courrier_template_type_document_ref_interne(
|
||||
my_partner, "FACTURATION_SESSION", str(inscrit_data['session_id']), 'inscription',
|
||||
str(inscrit_data['_id']),
|
||||
"",
|
||||
"Facture : " + str(ref_facture)
|
||||
)
|
||||
|
||||
if (local_status is False):
|
||||
mycommon.myprint(" WARNING : Impossible de logguer l'historique l'inscription_id : " + str(val['_id']))
|
||||
|
||||
|
||||
|
||||
# Gestion de l'historique
|
||||
# pour la collection 'partner_order_header'
|
||||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||||
|
|
@ -7734,13 +7915,13 @@ def Get_Given_Inscrit_Invoices(diction):
|
|||
"""
|
||||
Recuperer les données d'entete de facture
|
||||
"""
|
||||
|
||||
|
||||
invoice_header_data = MYSY_GV.dbname['partner_invoice_header'].find_one({'_id':ObjectId(str(retval['invoice_header_id'])),
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( invoice_header_data ):
|
||||
local_node = {}
|
||||
|
||||
|
||||
local_node['invoice_header_ref_interne'] = invoice_header_data['invoice_header_ref_interne']
|
||||
local_node['invoice_date'] = invoice_header_data['invoice_date']
|
||||
local_node['total_header_hors_taxe_before_header_reduction'] = invoice_header_data['total_header_hors_taxe_before_header_reduction']
|
||||
|
|
@ -7778,3 +7959,523 @@ def Get_Given_Inscrit_Invoices(diction):
|
|||
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 récupérer les données de facture "
|
||||
|
||||
|
||||
"""
|
||||
Interne Récuprer toutes les factures qui concernent un inscrit
|
||||
"""
|
||||
def Internal_Get_Given_Inscrit_Invoices(diction):
|
||||
try:
|
||||
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'inscription_id']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'inscription_id']
|
||||
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 la liste des arguments ")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
|
||||
"""
|
||||
Verifier la validité de l'inscription
|
||||
"""
|
||||
is_valid_inscription = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(diction['inscription_id'])),
|
||||
'valide':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if(is_valid_inscription != 1 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de l'inscription est invalide ")
|
||||
return False, " L'identifiant de l'inscription est invalide "
|
||||
|
||||
inscription_data = MYSY_GV.dbname['inscription'].find_one(
|
||||
{'_id': ObjectId(str(diction['inscription_id'])),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
total_frais_inscription = 0
|
||||
if( "price" in inscription_data.keys()):
|
||||
total_frais_inscription = mycommon.tryFloat(str(inscription_data['price']))
|
||||
|
||||
reste_a_facturer = 0
|
||||
|
||||
|
||||
"""
|
||||
Clés de mise à jour
|
||||
"""
|
||||
data_cle = {}
|
||||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||||
data_cle['order_line_inscription_id'] = str(diction['inscription_id'])
|
||||
|
||||
data_cle['valide'] = "1"
|
||||
data_cle['locked'] = "0"
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
||||
tab_detail_facture = []
|
||||
total_fature = 0
|
||||
|
||||
|
||||
for retval in MYSY_GV.dbname['partner_invoice_line_detail'].find(data_cle):
|
||||
|
||||
"""
|
||||
Recuperer les données d'entete de facture
|
||||
"""
|
||||
|
||||
invoice_header_data = MYSY_GV.dbname['partner_invoice_header'].find_one({'_id':ObjectId(str(retval['invoice_header_id'])),
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( invoice_header_data ):
|
||||
local_node = {}
|
||||
local_node['invoice_header_ref_interne'] = invoice_header_data['invoice_header_ref_interne']
|
||||
local_node['invoice_date'] = invoice_header_data['invoice_date']
|
||||
local_node['total_header_hors_taxe_before_header_reduction'] = invoice_header_data['total_header_hors_taxe_before_header_reduction']
|
||||
local_node['order_header_tax_amount'] = invoice_header_data['order_header_tax_amount']
|
||||
local_node['total_header_toutes_taxes'] = invoice_header_data['total_header_toutes_taxes']
|
||||
|
||||
local_node['order_line_prix_unitaire'] = retval['order_line_prix_unitaire']
|
||||
local_node['order_line_qty'] = retval['order_line_qty']
|
||||
local_node['order_line_montant_hors_taxes'] = retval['order_line_montant_hors_taxes']
|
||||
local_node['inscription_id'] = diction['inscription_id']
|
||||
|
||||
total_fature = total_fature + float(retval['order_line_montant_hors_taxes'])
|
||||
tab_detail_facture.append(local_node)
|
||||
|
||||
|
||||
|
||||
|
||||
final_data = {}
|
||||
final_data['liste_facture'] = tab_detail_facture
|
||||
final_data['total_facture_line'] = str(round(total_fature, 2))
|
||||
|
||||
reste_a_facturer = round(float(total_frais_inscription) - float(total_fature), 2)
|
||||
|
||||
final_data['reste_a_facturer'] = str(reste_a_facturer)
|
||||
final_data['frais_inscription'] = str(total_frais_inscription)
|
||||
|
||||
|
||||
RetObject.append(final_data)
|
||||
|
||||
#print(" ### RetObject = ", RetObject)
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer les données de facture "
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permet créer la facture d'un inscrit
|
||||
input : inscription_id, montant à facturer
|
||||
|
||||
regles de concernant l'entité à facturer :
|
||||
- si l'inscrit n'a ni client_rattachement, ni client facturé, alors je créer le client lien a apprenant et je mets ce dernier comme client facturé
|
||||
- si j'ai un client de rattachement mais pas de client de facturation, alors je met le client_rattachement comme client facturé
|
||||
- si non si j'ai un client facturé, alors c'est ce dernier qui est facturé
|
||||
|
||||
on met en commentaire le nom de l'inscrit
|
||||
|
||||
"""
|
||||
def Create_Inscrit_Invoice(diction):
|
||||
try:
|
||||
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'inscription_id', 'invoice_amount', 'session_id', 'invoice_date']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
||||
return False, " Les informations fournies sont incorrectes", False
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'inscription_id', 'invoice_amount', 'session_id']
|
||||
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 la liste des arguments ")
|
||||
return False, " Les informations fournies sont incorrectes", False
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner, False
|
||||
|
||||
"""
|
||||
Verifier la date de facturation
|
||||
"""
|
||||
invoice_date = ""
|
||||
if("invoice_date" in diction.keys() and diction['invoice_date']):
|
||||
# Controle de cohérence sur les dates
|
||||
local_status = mycommon.CheckisDate(str(diction['invoice_date'])[0:10])
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " La date de facturation n'est pas au format jj/mm/aaaa ")
|
||||
return False, " La date de facturation n'est pas au format jj/mm/aaaa "
|
||||
|
||||
invoice_date = str(diction['invoice_date'])[0:10]
|
||||
else:
|
||||
invoice_date = str(datetime.now().strftime("%d/%m/%Y"))
|
||||
|
||||
|
||||
# Recupération de la TVA de l'entité qui facture
|
||||
taux_tva_statuts, taux_tva_retval = partner_base_setup.Get_Given_Partner_Basic_Setup(
|
||||
{'token': str(diction['token']), 'config_name': 'tva'})
|
||||
|
||||
if (taux_tva_statuts is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de récupérer le taux de TVA ")
|
||||
return False, " Impossible de récupérer le taux de TVA ", False
|
||||
|
||||
tmp = ast.literal_eval(taux_tva_retval[0])
|
||||
taux_tva_retval = tmp['config_value']
|
||||
print(" ### taux_tva_retval = ", taux_tva_retval)
|
||||
tva_status, tva_value = mycommon.IsFloat(str(taux_tva_retval))
|
||||
if (tva_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " Le taux de TVA est invalide ")
|
||||
return False, " Le taux de TVA est invalide ", False
|
||||
|
||||
|
||||
"""
|
||||
Verifier la validité de la session
|
||||
"""
|
||||
is_valide_session = MYSY_GV.dbname['session_formation'].count_documents({"_id":ObjectId(str(diction['session_id'])),
|
||||
'valide':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( is_valide_session != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de la session/promo est invalide ")
|
||||
return False, " L'identifiant de la session/promo est invalide ", False
|
||||
|
||||
session_data = MYSY_GV.dbname['session_formation'].find_one(
|
||||
{"_id": ObjectId(str(diction['session_id'])),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
"""
|
||||
Verifier la validité de la formation
|
||||
"""
|
||||
|
||||
is_valide_class = MYSY_GV.dbname['myclass'].count_documents({'_id':ObjectId(str(session_data['class_id'])),
|
||||
'valide':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( is_valide_class != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de la formation est invalide ")
|
||||
return False, " L'identifiant de la formation est invalide ", False
|
||||
|
||||
class_data = MYSY_GV.dbname['myclass'].find_one({'_id': str(session_data['class_id']),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
"""
|
||||
Verifier la validité de l'inscription
|
||||
"""
|
||||
is_valid_inscription = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(diction['inscription_id'])),
|
||||
'valide':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if(is_valid_inscription != 1 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de l'inscription est invalide ")
|
||||
return False, " L'identifiant de l'inscription est invalide ", False
|
||||
|
||||
inscription_data = MYSY_GV.dbname['inscription'].find_one(
|
||||
{'_id': ObjectId(str(diction['inscription_id'])),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
apprenant_data = None
|
||||
if( "apprenant_id" in inscription_data.keys() and inscription_data['apprenant_id']):
|
||||
apprenant_data = MYSY_GV.dbname['apprenant'].find_one({'_id':ObjectId(str(inscription_data['apprenant_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( not apprenant_data):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de l'apprenant associé à l'inscrit est invalide ")
|
||||
return False, " L'identifiant de l'apprenant associé à l'inscrit est invalide ", False
|
||||
|
||||
|
||||
"""
|
||||
Important :
|
||||
regles de concernant l'entité à facturer :
|
||||
- si l'inscrit n'a ni client_rattachement, ni client facturé, alors je créer le client lien a apprenant et je mets ce dernier comme client facturé
|
||||
- si j'ai un client de rattachement mais pas de client de facturation, alors je met le client_rattachement comme client facturé
|
||||
- si non si j'ai un client facturé, alors c'est ce dernier qui est facturé
|
||||
"""
|
||||
bon_client_facturation = None
|
||||
# check du facture_client_rattachement_id
|
||||
if ("facture_client_rattachement_id" in inscription_data.keys() and inscription_data['facture_client_rattachement_id']):
|
||||
facture_client_rattachement_data = MYSY_GV.dbname['partner_client'].count_documents({'_id':ObjectId(str(inscription_data['facture_client_rattachement_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( facture_client_rattachement_data != 1 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de l'entité à facturer est invalide ")
|
||||
return False, " L'identifiant de l'entité à facturer est invalide ", False
|
||||
|
||||
bon_client_facturation = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'_id': ObjectId(str(inscription_data['facture_client_rattachement_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
|
||||
elif ("client_rattachement_id" in inscription_data.keys() and inscription_data['client_rattachement_id']):
|
||||
# check du client_rattachement_id
|
||||
client_rattachement_count = MYSY_GV.dbname['partner_client'].count_documents(
|
||||
{'_id': ObjectId(str(inscription_data['client_rattachement_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (client_rattachement_count != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de l'entité à facturer (2) est invalide ")
|
||||
return False, " L'identifiant de l'entité à facturer (2) est invalide ", False
|
||||
|
||||
bon_client_facturation = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'_id': ObjectId(str(inscription_data['client_rattachement_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
else:
|
||||
# enfin check de l'apprenant lui meme
|
||||
inscrit_as_client_count = MYSY_GV.dbname['partner_client'].count_documents(
|
||||
{'email': str(inscription_data['email']),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if( inscrit_as_client_count > 1 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Plusieurs clients ont la même adresse email principale "+str(inscription_data['email']) )
|
||||
return False, " Plusieurs clients ont la même adresse email principale "+str(inscription_data['email'])+" ", False
|
||||
|
||||
if( inscrit_as_client_count <= 0 ):
|
||||
# Cet inscrit n'inscrit n'existe pas comme client, on va le créer
|
||||
new_client_data = {}
|
||||
new_client_data['token'] = diction['token']
|
||||
new_client_data['raison_sociale'] = inscription_data['nom']
|
||||
new_client_data['nom'] = inscription_data['nom']
|
||||
new_client_data['email'] = inscription_data['email']
|
||||
new_client_data['telephone'] = inscription_data['telephone']
|
||||
new_client_data['adr_adresse'] = inscription_data['adresse']
|
||||
new_client_data['adr_code_postal'] = inscription_data['code_postal']
|
||||
new_client_data['adr_ville'] = inscription_data['ville']
|
||||
new_client_data['adr_pays'] = inscription_data['pays']
|
||||
new_client_data['invoice_email'] = inscription_data['email']
|
||||
new_client_data['invoice_nom'] = inscription_data['nom']
|
||||
new_client_data['invoice_condition_paiement_id'] = ""
|
||||
new_client_data['is_client'] = "1"
|
||||
|
||||
new_client_data['contact_nom'] = inscription_data['nom']
|
||||
new_client_data['contact_prenom'] = inscription_data['prenom']
|
||||
new_client_data['contact_email'] = inscription_data['email']
|
||||
new_client_data['is_contact_communication'] = "1"
|
||||
new_client_data['contact_phone'] = inscription_data['telephone']
|
||||
new_client_data['contact_adresse'] = inscription_data['adresse']
|
||||
new_client_data['contact_code_postal'] = inscription_data['code_postal']
|
||||
new_client_data['contact_ville'] = inscription_data['ville']
|
||||
new_client_data['contact_pays'] = inscription_data['pays']
|
||||
new_client_data['siret'] = ""
|
||||
|
||||
new_client_status, new_client_retval = partner_client.Add_Partner_Client(new_client_data)
|
||||
if (new_client_status is False):
|
||||
mycommon.myprint(" Facturation : Impossible de créer un client associé à l'adresse email : " + str(
|
||||
inscription_data['email']) + " ")
|
||||
return False, " Facturation : Impossible de créer un client associé à l'adresse email : " + str(
|
||||
inscription_data['email']) + " ", False
|
||||
|
||||
bon_client_facturation = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'email': str(inscription_data['email']),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
|
||||
|
||||
if( "price" in inscription_data.keys()):
|
||||
total_frais_inscription = mycommon.tryFloat(str(inscription_data['price']))
|
||||
|
||||
|
||||
"""
|
||||
Verifier le montant à facturer
|
||||
"""
|
||||
is_float_status, is_float_retaval = mycommon.IsFloat(str(diction['invoice_amount']))
|
||||
|
||||
if (is_float_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Le montant à facturer est invalide ")
|
||||
return False, " Le montant à facturer est invalide ", False
|
||||
|
||||
"""
|
||||
Recuperer le reste à facturer pour cette inscription
|
||||
"""
|
||||
local_diction = {'token':diction['token'], 'inscription_id':diction['inscription_id']}
|
||||
local_status, local_retval_invoices = Internal_Get_Given_Inscrit_Invoices(local_diction)
|
||||
if( local_status is False):
|
||||
return local_status, local_retval_invoices
|
||||
|
||||
|
||||
reste_a_facturer = local_retval_invoices[0]['reste_a_facturer']
|
||||
frais_inscription = local_retval_invoices[0]['frais_inscription']
|
||||
|
||||
if( float(reste_a_facturer) < float(str(diction['invoice_amount'])) ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Le montant à facturer "+str(diction['invoice_amount']) +" est supérieur au reste à facturer "+str(reste_a_facturer) +" ")
|
||||
return False, " Le montant à facturer "+str(diction['invoice_amount']) +" est supérieur au reste à facturer "+str(reste_a_facturer), False
|
||||
|
||||
|
||||
|
||||
"""
|
||||
A présent on va créer l'entete de facture
|
||||
"""
|
||||
|
||||
local_diction_entete = {}
|
||||
|
||||
local_diction_entete['token'] = diction['token']
|
||||
local_diction_entete['order_header_client_id'] = str(bon_client_facturation['_id'])
|
||||
local_diction_entete['order_header_description'] = ""
|
||||
local_diction_entete['order_header_comment'] = " Inscrit : "+str(inscription_data['nom'])+" "+str(inscription_data['prenom'])+ " "+str(inscription_data['email'])
|
||||
local_diction_entete['order_header_lieu_formation'] = ""
|
||||
local_diction_entete['order_header_date_cmd'] = ""
|
||||
local_diction_entete['invoice_date'] = invoice_date
|
||||
|
||||
local_diction_entete['order_header_condition_paiement_id'] = str(bon_client_facturation['invoice_condition_paiement_id'])
|
||||
local_diction_entete['order_header_ref_client'] = ""
|
||||
local_diction_entete['order_header_vendeur_id'] = ""
|
||||
|
||||
|
||||
|
||||
|
||||
local_statut_entete, local_retval, local_entete_ref_interne = Add_Partner_Draft_Invoice(local_diction_entete)
|
||||
|
||||
if( local_statut_entete is False):
|
||||
return local_statut_entete, local_retval, False
|
||||
|
||||
|
||||
invoice_header_data = MYSY_GV.dbname['partner_invoice_header'].find_one({'invoice_header_ref_interne': str(local_entete_ref_interne),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid']),
|
||||
'invoice_header_type':'brouillon'})
|
||||
|
||||
if( not invoice_header_data or '_id' not in invoice_header_data.keys()):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Une erreur s'est produite lors de la création de la facture ")
|
||||
return False, " Une erreur s'est produite lors de la création de la facture ", False
|
||||
|
||||
local_diction_ligne = {}
|
||||
local_diction_ligne['token'] = str(diction['token'])
|
||||
local_diction_ligne['order_line_formation'] = str(session_data['class_internal_url'])
|
||||
local_diction_ligne['order_line_qty'] = "1"
|
||||
local_diction_ligne['order_line_prix_unitaire'] = str(diction['invoice_amount'])
|
||||
local_diction_ligne['invoice_line_id'] = ""
|
||||
local_diction_ligne['invoice_header_id'] = str(invoice_header_data['_id'])
|
||||
local_diction_ligne['invoice_line_status'] = ""
|
||||
local_diction_ligne['order_line_type_article'] = "formation"
|
||||
local_diction_ligne['invoice_line_type'] = "brouillon"
|
||||
|
||||
local_diction_ligne['order_line_session_id'] = str(diction['session_id'])
|
||||
|
||||
local_diction_ligne['order_line_comment'] = " Inscrit : "+str(inscription_data['nom'])+" "+str(inscription_data['prenom'])+ " "+str(inscription_data['email'])
|
||||
|
||||
local_diction_ligne['order_line_montant_hors_taxes'] = str(float(str(diction['invoice_amount'])))
|
||||
local_diction_ligne['order_line_tax_amount'] = str(str(round(tva_value * float(str(diction['invoice_amount'])) /100, 2)))
|
||||
local_diction_ligne['order_line_montant_toutes_taxes'] = str(round( (float(str(diction['invoice_amount'])) + (tva_value * float(str(diction['invoice_amount'])) /100)), 2))
|
||||
local_diction_ligne['order_line_taux_taxe'] = str(tva_value)
|
||||
|
||||
|
||||
local_diction_ligne['tab_inscription_ids'] = [str(diction['inscription_id'])]
|
||||
|
||||
local_statut_line, local_retval = Add_Update_Partner_Draft_Invoice_Line(local_diction_ligne)
|
||||
if( local_statut_line is False ):
|
||||
return local_statut_line, local_retval
|
||||
|
||||
## Add to log history pour la commande
|
||||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||||
history_event_dict = {}
|
||||
history_event_dict['token'] = diction['token']
|
||||
history_event_dict['related_collection'] = "partner_invoice_header"
|
||||
history_event_dict['related_collection_recid'] = str(invoice_header_data['_id'])
|
||||
history_event_dict['action_date'] = str(now)
|
||||
history_event_dict['action_description'] = " Création "
|
||||
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
||||
|
||||
return True, "La facture a été correctement créée, vous pouvez la confirmer ", local_entete_ref_interne
|
||||
|
||||
|
||||
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 récupérer les données de facture ", False
|
||||
|
|
|
|||
Loading…
Reference in New Issue