dddqsd
parent
6ac94e5a56
commit
a0c26d856e
|
@ -2,9 +2,13 @@
|
|||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="ddd">
|
||||
<change afterPath="$PROJECT_DIR$/notes_apprenant.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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$/categorie_formation_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/categorie_formation_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_invoice.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_invoice.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -75,13 +79,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00253" summary="01/04/24 - 23h50">
|
||||
<created>1712009802358</created>
|
||||
<option name="number" value="00253" />
|
||||
<option name="presentableId" value="LOCAL-00253" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1712009802359</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00254" summary="2/04/24 - 20h30">
|
||||
<created>1712082670296</created>
|
||||
<option name="number" value="00254" />
|
||||
|
@ -418,7 +415,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1715857414079</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="302" />
|
||||
<task id="LOCAL-00302" summary="ddd">
|
||||
<created>1715884005756</created>
|
||||
<option name="number" value="00302" />
|
||||
<option name="presentableId" value="LOCAL-00302" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1715884005756</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="303" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
|
|
@ -3022,7 +3022,7 @@ def AddStagiairetoClass_mass_for_many_session(file=None, Folder=None, diction=No
|
|||
'''
|
||||
field_list = ['formation_code_externe', 'code_session', 'prenom', 'nom', 'employeur',
|
||||
'telephone', 'email', 'modefinancement', 'opco', 'status', 'prix', 'adresse', 'code_postal',
|
||||
'ville', 'pays', 'client_rattachement_email', 'client_rattachement_nom','facture_client_rattachement_email'
|
||||
'ville', 'pays', 'client_rattachement_email', 'client_rattachement_nom','facture_client_rattachement_email',
|
||||
'facture_client_rattachement_nom']
|
||||
|
||||
|
||||
|
@ -3244,9 +3244,14 @@ def AddStagiairetoClass_mass_for_many_session(file=None, Folder=None, diction=No
|
|||
client_rattachement_nom) + " et email : " + str(client_rattachement_email)
|
||||
|
||||
local_client_retval_data = MYSY_GV.dbname['partner_client'].find_one(local_client_retval_qry)
|
||||
|
||||
if( local_client_retval_data is not None ):
|
||||
mydata['client_rattachement_id'] = str(local_client_retval_data['_id'])
|
||||
|
||||
# /!\ : Par defaut, ont que le client de facturation = au client principale. comme ca
|
||||
# Si il y un client de facturation plus bas, on l'ecrase
|
||||
mydata['facture_client_rattachement_id'] = str(local_client_retval_data['_id'])
|
||||
|
||||
""""
|
||||
Gestion du client dà facturer/
|
||||
Avec l'email et le nom, on va aller récupérer l'_id du client
|
||||
|
@ -3391,7 +3396,8 @@ def Controle_AddStagiairetoClass_mass_for_many_session(saved_file=None, Folder=N
|
|||
'''
|
||||
field_list = ['formation_code_externe', 'code_session', 'prenom', 'nom', 'employeur',
|
||||
'telephone', 'email', 'modefinancement', 'opco', 'status', 'prix', 'adresse', 'code_postal',
|
||||
'ville', 'pays', 'client_rattachement_email', 'client_rattachement_nom']
|
||||
'ville', 'pays', 'client_rattachement_email', 'client_rattachement_nom',
|
||||
'facture_client_rattachement_email', 'facture_client_rattachement_nom']
|
||||
|
||||
|
||||
# Controle du nombre de lignes dans le fichier.
|
||||
|
|
|
@ -488,7 +488,7 @@ def Cron_Monthly_Invoice_Inscription():
|
|||
{'$eq': ['$session_id', '$$session_id']},
|
||||
{'$eq': ['$partner_owner_recid', '$$session_partner_owner_recid']},
|
||||
{'$eq': ['$status', '1']},
|
||||
{'$eq': ["$client_rattachement_id", str(client_data['_id'])]}
|
||||
{'$eq': ["facture_client_rattachement_id", str(client_data['_id'])]}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ def Cron_Monthly_Invoice_Inscription():
|
|||
if( local_invoice_status is False):
|
||||
return local_invoice_status, local_invoice_retval
|
||||
else:
|
||||
print(" FACTURATION REUSSI")
|
||||
print(" FACTURATION REUSSIE")
|
||||
|
||||
return True, ""
|
||||
|
||||
|
@ -656,7 +656,7 @@ def Cron_Monthly_Invoice_Inscription():
|
|||
|
||||
|
||||
"""
|
||||
Cette fonction prend le tableau des data à factuer et créer les facture dans les
|
||||
Cette fonction prend le tableau des data à facturer et créer les facture dans les
|
||||
tables et met à jour les inscriptions
|
||||
"""
|
||||
def Invoice_Data_From_Tab(diction):
|
||||
|
|
2675
Log/log_file.log
2675
Log/log_file.log
File diff suppressed because one or more lines are too long
|
@ -6978,9 +6978,405 @@ on vient mettre à jour inscription.
|
|||
|
||||
Infiné, apres la facturation, toutes les lignes d'inscription on bel et bien un 'client_rattachement_id'
|
||||
|
||||
17/05/2024 : /!\
|
||||
Maintenant on facture à partir du champs "facture_client_rattachement_id" et non
|
||||
"client_rattachement_id" qui lui est concerné par les convention et autre documents
|
||||
administratifs
|
||||
|
||||
"""
|
||||
def Prepare_and_Send_Facture_From_Session_By_Email(tab_files, Folder, diction):
|
||||
try:
|
||||
|
||||
field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'email_test', 'email_production']
|
||||
|
||||
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, " La valeur '" + val + "' n'est pas presente dans liste", False
|
||||
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_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 que la session est valide
|
||||
is_session_valide = MYSY_GV.dbname['session_formation'].count_documents(
|
||||
{'_id': ObjectId(str(diction['session_id'])),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (is_session_valide != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de la session est invalide ")
|
||||
return False, " L'identifiant de la session est invalide ", False
|
||||
|
||||
"""
|
||||
Gestion des inscriptions n'ayant pas de client ID
|
||||
"""
|
||||
liste_inscription_no_client = MYSY_GV.dbname['inscription'].find(
|
||||
{"$or": [{'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
"facture_client_rattachement_id": '',
|
||||
"invoiced": {'$ne': '1'}
|
||||
},
|
||||
{'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'facture_client_rattachement_id': {'$exists': False},
|
||||
"invoiced": {'$ne': '1'}
|
||||
}]
|
||||
}
|
||||
)
|
||||
|
||||
# CONTROLE : Verification des data client (si tous les clients 'particuliers' sont ok
|
||||
for local_inscription_no_client in liste_inscription_no_client:
|
||||
print(" ### List des inscrit n'ayant pas de 'client_id': ", local_inscription_no_client)
|
||||
|
||||
"""
|
||||
- Verifier s'il y a un client avec la même adresse email,
|
||||
si non, créer le client
|
||||
"""
|
||||
is_inscription_no_client_exist = MYSY_GV.dbname['partner_client'].count_documents(
|
||||
{'partner_recid': str(my_partner['recid']),
|
||||
'email': str(local_inscription_no_client['email'])})
|
||||
|
||||
# S'il ya plusieurs clients avec la meme adresse email, alors il y a un bin's
|
||||
if (is_inscription_no_client_exist > 1):
|
||||
mycommon.myprint(" Facturation : L'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " correspond à plusieurs clients")
|
||||
return False, " Facturation : L'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " correspond à plusieurs clients ", False
|
||||
|
||||
# Si le client existe, verifier qu'il est valide et pas locké
|
||||
if (is_inscription_no_client_exist == 1):
|
||||
is_inscription_no_client_valide_no_locked = MYSY_GV.dbname['partner_client'].count_documents(
|
||||
{'partner_recid': str(my_partner['recid']),
|
||||
'email': str(local_inscription_no_client['email']),
|
||||
'valide': "1",
|
||||
'locked': '0'})
|
||||
|
||||
if (is_inscription_no_client_valide_no_locked == 0):
|
||||
mycommon.myprint(" Facturation : L'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " correspond à un client non valide")
|
||||
return False, " Facturation : L'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " correspond à un client non valide ", False
|
||||
|
||||
# Mise à jour de l'inscription avec l'_id du client
|
||||
inscription_no_client_valide_no_locked_data = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'partner_recid': str(my_partner['recid']),
|
||||
'email': str(local_inscription_no_client['email']),
|
||||
'valide': "1",
|
||||
'locked': '0'})
|
||||
|
||||
MYSY_GV.dbname['inscription'].update_one({'partner_owner_recid': str(my_partner['recid']),
|
||||
'_id': ObjectId(local_inscription_no_client['_id'])},
|
||||
{'$set': {'facture_client_rattachement_id': str(
|
||||
inscription_no_client_valide_no_locked_data['_id'])}})
|
||||
|
||||
# Si il n'y a pas de client associé à cette adresse email, alors on crée le client
|
||||
if (is_inscription_no_client_exist == 0):
|
||||
|
||||
new_client_contact_data = {}
|
||||
new_client_data = {}
|
||||
new_partner_all_list = ['token', "raison_sociale", "nom", "siret", "tva", "email",
|
||||
"telephone", "website", "comment", "address",
|
||||
'adr_adresse', 'adr_code_postal', 'adr_ville', 'adr_pays',
|
||||
'invoice_email', 'invoice_nom', 'invoice_siret',
|
||||
'invoice_tva', 'invoice_condition_paiement_id', 'invoice_adresse', 'invoice_ville',
|
||||
'invoice_code_postal', 'invoice_pays', "client_type_id",
|
||||
'is_fournisseur', 'is_client', 'is_financeur', 'is_client']
|
||||
|
||||
# Pre Remplir les champs à vide
|
||||
for tmp in new_partner_all_list:
|
||||
new_client_data[str(tmp)] = ""
|
||||
|
||||
|
||||
new_client_data['token'] = diction['token']
|
||||
new_client_contact_data['token'] = diction['token']
|
||||
|
||||
if ("nom" in local_inscription_no_client.keys()):
|
||||
new_client_data['raison_sociale'] = local_inscription_no_client['nom']
|
||||
new_client_data['nom'] = local_inscription_no_client['nom']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['nom'] = local_inscription_no_client['nom']
|
||||
|
||||
if ("prenom" in local_inscription_no_client.keys()):
|
||||
# Pour le contact
|
||||
new_client_contact_data['prenom'] = local_inscription_no_client['prenom']
|
||||
|
||||
if ("civilite" in local_inscription_no_client.keys()):
|
||||
# Pour le contact
|
||||
new_client_contact_data['civilite'] = local_inscription_no_client['civilite']
|
||||
|
||||
|
||||
if( "email" in local_inscription_no_client.keys() ):
|
||||
new_client_data['email'] = local_inscription_no_client['email']
|
||||
new_client_data['invoice_email'] = local_inscription_no_client['email']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['email'] = local_inscription_no_client['email']
|
||||
|
||||
if ("telephone" in local_inscription_no_client.keys()):
|
||||
new_client_data['telephone'] = local_inscription_no_client['telephone']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['telephone'] = local_inscription_no_client['telephone']
|
||||
|
||||
if ("adresse" in local_inscription_no_client.keys()):
|
||||
new_client_data['adr_adresse'] = local_inscription_no_client['adresse']
|
||||
new_client_data['invoice_adresse'] = local_inscription_no_client['adresse']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['adr_adresse'] = local_inscription_no_client['adresse']
|
||||
|
||||
|
||||
if("code_postal" in local_inscription_no_client.keys()):
|
||||
new_client_data['adr_code_postal'] = local_inscription_no_client['code_postal']
|
||||
new_client_data['invoice_code_postal'] = local_inscription_no_client['code_postal']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['adr_code_postal'] = local_inscription_no_client['code_postal']
|
||||
|
||||
if ("ville" in local_inscription_no_client.keys()):
|
||||
new_client_data['adr_ville'] = local_inscription_no_client['ville']
|
||||
new_client_data['invoice_ville'] = local_inscription_no_client['ville']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['adr_ville'] = local_inscription_no_client['ville']
|
||||
|
||||
if ("pays" in local_inscription_no_client.keys()):
|
||||
new_client_data['adr_pays'] = local_inscription_no_client['pays']
|
||||
new_client_data['invoice_pays'] = local_inscription_no_client['pays']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['adr_pays'] = local_inscription_no_client['pays']
|
||||
|
||||
|
||||
new_client_data['is_client'] = "1"
|
||||
new_client_data['is_company'] = "0"
|
||||
|
||||
|
||||
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(
|
||||
local_inscription_no_client['email']) + " ")
|
||||
return False, " Facturation : Impossible de créer un client associé à l'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " ", False
|
||||
|
||||
|
||||
|
||||
inscription_no_client_valide_no_locked_data = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'partner_recid': str(my_partner['recid']),
|
||||
'email': str(local_inscription_no_client['email']),
|
||||
'valide': "1",
|
||||
'locked': '0'})
|
||||
|
||||
# Créer le contact de communication du client
|
||||
new_client_contact_data['include_com'] = "1"
|
||||
new_client_contact_data['related_collection'] = "partner_client"
|
||||
new_client_contact_data['related_collection_owner_id'] = str(inscription_no_client_valide_no_locked_data['_id'])
|
||||
local_add_contact_status, local_add_contact_retval = Contact.Add_Contact(new_client_contact_data)
|
||||
if( local_add_contact_status is False ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " WARNING : Impossible de créer le contact "+str(local_add_contact_retval))
|
||||
|
||||
# Mise à jour de l'inscription avec l'_id du client
|
||||
MYSY_GV.dbname['inscription'].update_one({'partner_owner_recid': str(my_partner['recid']),
|
||||
'_id': ObjectId(local_inscription_no_client['_id'])},
|
||||
{'$set': {'facture_client_rattachement_id': str(
|
||||
inscription_no_client_valide_no_locked_data['_id'])}})
|
||||
|
||||
|
||||
# Verifier qu'il ya bien des inscriptions valides dans la session pour le client
|
||||
liste_client_rattachement_id = MYSY_GV.dbname['inscription'].distinct("facture_client_rattachement_id",
|
||||
{'session_id':str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(
|
||||
my_partner['recid']),
|
||||
"facture_client_rattachement_id": { '$ne': ''},
|
||||
"invoiced": {'$ne': '1'}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
print(" ### la liste des liste_client_rattachement_id = ", liste_client_rattachement_id)
|
||||
|
||||
# Sauvegarde des fichiers joints depuis le front
|
||||
tab_saved_file_full_path = []
|
||||
for file in tab_files:
|
||||
status, saved_file_full_path = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
||||
if (status is False):
|
||||
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
||||
return False, "Impossible de récupérer correctement le fichier à importer", False
|
||||
|
||||
tab_saved_file_full_path.append(saved_file_full_path)
|
||||
|
||||
print(" #### tab_saved_file_full_path = ", tab_saved_file_full_path)
|
||||
|
||||
# Recupération des données du modèle de document
|
||||
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one(
|
||||
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])}
|
||||
)
|
||||
|
||||
|
||||
tab_local_invoice_ref_interne = []
|
||||
# Envoie des factures pour les inscrits AVEC client_id (conventions d'entreprise)
|
||||
for single_client in liste_client_rattachement_id:
|
||||
print(" Traitement du client_id = ", single_client)
|
||||
|
||||
# Recuperation des contacts de communication du client
|
||||
local_diction = {}
|
||||
local_diction['token'] = diction['token']
|
||||
local_diction['_id'] = str(single_client)
|
||||
|
||||
print(" ##### local_diction = ", local_diction)
|
||||
local_status, partner_client_contact_communication = partner_client.Get_Partner_Client_Communication_Contact(
|
||||
local_diction)
|
||||
|
||||
if (local_status is False):
|
||||
mycommon.myprint(" Impossible de récupérer les contacts de communication du client ")
|
||||
return False, " Impossible de récupérer les contacts de communication du client ", False
|
||||
|
||||
print(" ### partner_client_contact_communication = ", partner_client_contact_communication)
|
||||
tab_local_email_production = []
|
||||
for tmp in partner_client_contact_communication:
|
||||
tmp_JSON = ast.literal_eval(tmp)
|
||||
if ("email" in tmp_JSON.keys()):
|
||||
tab_local_email_production.append(str(tmp_JSON["email"]))
|
||||
|
||||
list_local_email_production = ",".join(tab_local_email_production)
|
||||
|
||||
new_diction_client = {}
|
||||
new_diction_client['partner_client_id'] = single_client
|
||||
new_diction_client['token'] = diction['token']
|
||||
new_diction_client['courrier_template_id'] = diction['courrier_template_id']
|
||||
new_diction_client['email_test'] = diction['email_test']
|
||||
new_diction_client['email_production'] = str(list_local_email_production)
|
||||
new_diction_client['session_id'] = diction['session_id']
|
||||
|
||||
print(" ##### new_diction_client 0102 = ", new_diction_client)
|
||||
|
||||
|
||||
# Creation de la facture du client
|
||||
diction_invoice = {}
|
||||
diction_invoice['token'] = diction['token']
|
||||
diction_invoice['partner_client_id'] = single_client
|
||||
diction_invoice['session_id'] = diction['session_id']
|
||||
#print(" ##### diction_invoice 0202 = ", diction_invoice)
|
||||
local_create_invoice_status, local_create_invoice_retval, local_invoice_ref_interne = Invoice_Partner_From_Session(diction_invoice)
|
||||
if( local_create_invoice_status is False ):
|
||||
return local_create_invoice_status, local_create_invoice_retval, False
|
||||
|
||||
|
||||
"""
|
||||
Mettre à jour les lignes associées à ce client pour dire que la ligne est facturé
|
||||
"""
|
||||
now = str(datetime.now())
|
||||
update_data = {}
|
||||
update_data['invoiced'] = "1"
|
||||
update_data['invoiced_ref'] = str(local_invoice_ref_interne)
|
||||
update_data['invoiced_date'] = now
|
||||
update_data['date_update'] = now
|
||||
update_data['update_by'] = str(my_partner['_id'])
|
||||
|
||||
update = MYSY_GV.dbname['inscription'].update_many({'partner_owner_recid':str(my_partner['recid']),
|
||||
'session_id':diction['session_id'],
|
||||
'facture_client_rattachement_id':str(single_client)},
|
||||
{'$set':update_data})
|
||||
|
||||
|
||||
tab_local_invoice_ref_interne.append(str(local_invoice_ref_interne))
|
||||
|
||||
"""
|
||||
07/03/20204 : mettre un statut de facturation sur la session afin de voir
|
||||
tout de suite quel session est entièrement facturée ou partiellement.
|
||||
|
||||
regles :
|
||||
Si toutes les inscription associées à une session sont facturée ==> invoiced_statut de la session = 2
|
||||
Si au moins une inscription associée à une session est facturé ==> invoiced_statut de la session = 1
|
||||
Si non invoiced_statut de la session =0
|
||||
"""
|
||||
nb_inscription_facture = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'partner_owner_recid': my_partner['recid'],
|
||||
'session_id': diction['session_id'],
|
||||
'invoiced': '1'})
|
||||
|
||||
|
||||
nb_inscription_non_facture = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'partner_owner_recid': my_partner['recid'],
|
||||
'session_id': diction['session_id'],
|
||||
'invoiced': {'$ne': '1'}})
|
||||
|
||||
nb_inscription_valide = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'partner_owner_recid': my_partner['recid'],
|
||||
'session_id': diction['session_id'],
|
||||
'status': '1'})
|
||||
|
||||
|
||||
invoiced_statut = "0"
|
||||
if (nb_inscription_facture == nb_inscription_valide):
|
||||
# toutes les inscription valides ont été facturée
|
||||
invoiced_statut = "2"
|
||||
elif (nb_inscription_facture > 0):
|
||||
# Au moins une ligne a été facturée
|
||||
invoiced_statut = "1"
|
||||
|
||||
# Mise à jour du statut de facturation de la session
|
||||
MYSY_GV.dbname['session_formation'].update_one({'partner_owner_recid': my_partner['recid'],
|
||||
'valide': '1',
|
||||
'_id': ObjectId(str(diction['session_id']))
|
||||
},
|
||||
{'$set': {'invoiced_statut': invoiced_statut}})
|
||||
|
||||
|
||||
# Creation de l'historique dans les action 'courrier_template_tracking_history'
|
||||
local_qry = {'partner_owner_recid':str(my_partner['recid']), 'session_id':str(diction['session_id']),
|
||||
'invoiced_ref': {'$in': tab_local_invoice_ref_interne} }
|
||||
|
||||
#print(" ### local_qry = ", local_qry)
|
||||
|
||||
for val in MYSY_GV.dbname['inscription'].find({'partner_owner_recid':str(my_partner['recid']),
|
||||
'session_id':str(diction['session_id']),
|
||||
'invoiced_ref': {'$in': tab_local_invoice_ref_interne} }):
|
||||
|
||||
ref_facture = ""
|
||||
if( "invoiced_ref" in val.keys() ):
|
||||
ref_facture = val['invoiced_ref']
|
||||
|
||||
local_status, local_retval = module_editique.Editic_Log_History_Action_From_courrier_template_type_document_ref_interne(
|
||||
my_partner, "FACTURATION_SESSION", str(diction['session_id']), 'inscription',
|
||||
str(val['_id']),
|
||||
str(diction['courrier_template_id']),
|
||||
"Facture : "+str(ref_facture)
|
||||
)
|
||||
|
||||
if( local_status is False ):
|
||||
mycommon.myprint(" WARNING : Impossible de logguer l'historique l'inscription_id : " + str(val['_id']))
|
||||
|
||||
|
||||
return_message = " La session a été correctement facturée.\nListe des factures : "
|
||||
for tmp in tab_local_invoice_ref_interne:
|
||||
return_message += "\n - "+str(tmp)
|
||||
|
||||
return True, str(return_message), tab_local_invoice_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 créer et d'envoyer les factures par email ", False
|
||||
|
||||
def Prepare_and_Send_Facture_From_Session_By_Email_SAVE_ORIG(tab_files, Folder, diction):
|
||||
try:
|
||||
|
||||
field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'email_test', 'email_production']
|
||||
|
@ -7373,7 +7769,6 @@ def Prepare_and_Send_Facture_From_Session_By_Email(tab_files, Folder, diction):
|
|||
return False, " Impossible de créer et d'envoyer les factures par email ", False
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction va créer une facture pour un client
|
||||
lié à des apprenants sur une session de formation
|
||||
|
@ -7413,7 +7808,7 @@ def Invoice_Partner_From_Session( diction):
|
|||
|
||||
# Verifier que ce client a bien des inscriptions valide pour cette session
|
||||
nb_valide_inscription_pr_client = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'client_rattachement_id': str(diction['partner_client_id']),
|
||||
{'facture_client_rattachement_id': str(diction['partner_client_id']),
|
||||
'session_id': str(diction['session_id']),
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'status': '1'})
|
||||
|
@ -7435,7 +7830,7 @@ def Invoice_Partner_From_Session( diction):
|
|||
inscription_data = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'client_rattachement_id':str(diction['partner_client_id'])})
|
||||
'facture_client_rattachement_id':str(diction['partner_client_id'])})
|
||||
tab_apprenant = []
|
||||
tab_participant = []
|
||||
for val in inscription_data:
|
||||
|
@ -8222,6 +8617,11 @@ C'est a dire le cas ou on souhaite facturer que les lignes selectionnées
|
|||
Cette fonction est identique à la fonction : "Prepare_and_Send_Facture_From_Session_By_Email"
|
||||
a l'exception qu'elle prend en compte les inscription_id à facturer
|
||||
|
||||
17/05/2024 : /!\
|
||||
Maintenant on facture à partir du champs "facture_client_rattachement_id" et non
|
||||
"client_rattachement_id" qui lui est concerné par les convention et autre documents
|
||||
administratifs
|
||||
|
||||
"""
|
||||
def Prepare_and_Send_Facture_From_Session_By_Inscription_Id(tab_files, Folder, diction):
|
||||
try:
|
||||
|
@ -8289,10 +8689,437 @@ def Prepare_and_Send_Facture_From_Session_By_Inscription_Id(tab_files, Folder, d
|
|||
{"$or": [{'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
"client_rattachement_id": '',
|
||||
"facture_client_rattachement_id": '',
|
||||
"invoiced": {'$ne': '1'},
|
||||
"_id": {'$in': tab_my_inscription_ids_Object},
|
||||
},
|
||||
{'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'facture_client_rattachement_id': {'$exists': False},
|
||||
"invoiced": {'$ne': '1'},
|
||||
"_id": {'$in': tab_my_inscription_ids_Object},
|
||||
}]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# CONTROLE : Verification des data client (si tous les clients 'particuliers' sont ok
|
||||
for local_inscription_no_client in liste_inscription_no_client:
|
||||
print(" ### List des inscrit n'ayant pas de 'client_id': ", local_inscription_no_client)
|
||||
|
||||
"""
|
||||
- Verifier s'il y a un client avec la même adresse email,
|
||||
si non, créer le client
|
||||
"""
|
||||
is_inscription_no_client_exist = MYSY_GV.dbname['partner_client'].count_documents(
|
||||
{'partner_recid': str(my_partner['recid']),
|
||||
'email': str(local_inscription_no_client['email'])})
|
||||
|
||||
# S'il ya plusieurs clients avec la meme adresse email, alors il y a un bin's
|
||||
if (is_inscription_no_client_exist > 1):
|
||||
mycommon.myprint(" Facturation : L'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " correspond à plusieurs clients")
|
||||
return False, " Facturation : L'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " correspond à plusieurs clients ", False
|
||||
|
||||
# Si le client existe, verifier qu'il est valide et pas locké
|
||||
if (is_inscription_no_client_exist == 1):
|
||||
is_inscription_no_client_valide_no_locked = MYSY_GV.dbname['partner_client'].count_documents(
|
||||
{'partner_recid': str(my_partner['recid']),
|
||||
'email': str(local_inscription_no_client['email']),
|
||||
'valide': "1",
|
||||
'locked': '0'})
|
||||
|
||||
if (is_inscription_no_client_valide_no_locked == 0):
|
||||
mycommon.myprint(" Facturation : L'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " correspond à un client non valide")
|
||||
return False, " Facturation : L'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " correspond à un client non valide ", False
|
||||
|
||||
# Mise à jour de l'inscription avec l'_id du client
|
||||
inscription_no_client_valide_no_locked_data = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'partner_recid': str(my_partner['recid']),
|
||||
'email': str(local_inscription_no_client['email']),
|
||||
'valide': "1",
|
||||
'locked': '0'})
|
||||
|
||||
MYSY_GV.dbname['inscription'].update_one({'partner_owner_recid': str(my_partner['recid']),
|
||||
'_id': ObjectId(local_inscription_no_client['_id'])},
|
||||
{'$set': {
|
||||
'facture_client_rattachement_id': str(inscription_no_client_valide_no_locked_data['_id']),
|
||||
'client_rattachement_id': str(
|
||||
inscription_no_client_valide_no_locked_data['_id']),
|
||||
}
|
||||
})
|
||||
|
||||
# Si il n'y a pas de client associé à cette adresse email, alors on crée le client
|
||||
if (is_inscription_no_client_exist == 0):
|
||||
|
||||
new_client_contact_data = {}
|
||||
new_client_data = {}
|
||||
new_partner_all_list = ['token', "raison_sociale", "nom", "siret", "tva", "email",
|
||||
"telephone", "website", "comment", "address",
|
||||
'adr_adresse', 'adr_code_postal', 'adr_ville', 'adr_pays',
|
||||
'invoice_email', 'invoice_nom', 'invoice_siret',
|
||||
'invoice_tva', 'invoice_condition_paiement_id', 'invoice_adresse',
|
||||
'invoice_ville',
|
||||
'invoice_code_postal', 'invoice_pays', "client_type_id",
|
||||
'is_fournisseur', 'is_client', 'is_financeur', 'is_client']
|
||||
|
||||
# Pre Remplir les champs à vide
|
||||
for tmp in new_partner_all_list:
|
||||
new_client_data[str(tmp)] = ""
|
||||
|
||||
new_client_data['token'] = diction['token']
|
||||
new_client_contact_data['token'] = diction['token']
|
||||
|
||||
if ("nom" in local_inscription_no_client.keys()):
|
||||
new_client_data['raison_sociale'] = local_inscription_no_client['nom']
|
||||
new_client_data['nom'] = local_inscription_no_client['nom']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['nom'] = local_inscription_no_client['nom']
|
||||
|
||||
if ("prenom" in local_inscription_no_client.keys()):
|
||||
# Pour le contact
|
||||
new_client_contact_data['prenom'] = local_inscription_no_client['prenom']
|
||||
|
||||
if ("civilite" in local_inscription_no_client.keys()):
|
||||
# Pour le contact
|
||||
new_client_contact_data['civilite'] = local_inscription_no_client['civilite']
|
||||
|
||||
if ("email" in local_inscription_no_client.keys()):
|
||||
new_client_data['email'] = local_inscription_no_client['email']
|
||||
new_client_data['invoice_email'] = local_inscription_no_client['email']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['email'] = local_inscription_no_client['email']
|
||||
|
||||
if ("telephone" in local_inscription_no_client.keys()):
|
||||
new_client_data['telephone'] = local_inscription_no_client['telephone']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['telephone'] = local_inscription_no_client['telephone']
|
||||
|
||||
if ("adresse" in local_inscription_no_client.keys()):
|
||||
new_client_data['adr_adresse'] = local_inscription_no_client['adresse']
|
||||
new_client_data['invoice_adresse'] = local_inscription_no_client['adresse']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['adr_adresse'] = local_inscription_no_client['adresse']
|
||||
|
||||
if ("code_postal" in local_inscription_no_client.keys()):
|
||||
new_client_data['adr_code_postal'] = local_inscription_no_client['code_postal']
|
||||
new_client_data['invoice_code_postal'] = local_inscription_no_client['code_postal']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['adr_code_postal'] = local_inscription_no_client['code_postal']
|
||||
|
||||
if ("ville" in local_inscription_no_client.keys()):
|
||||
new_client_data['adr_ville'] = local_inscription_no_client['ville']
|
||||
new_client_data['invoice_ville'] = local_inscription_no_client['ville']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['adr_ville'] = local_inscription_no_client['ville']
|
||||
|
||||
if ("pays" in local_inscription_no_client.keys()):
|
||||
new_client_data['adr_pays'] = local_inscription_no_client['pays']
|
||||
new_client_data['invoice_pays'] = local_inscription_no_client['pays']
|
||||
|
||||
# Pour le contact
|
||||
new_client_contact_data['adr_pays'] = local_inscription_no_client['pays']
|
||||
|
||||
new_client_data['is_client'] = "1"
|
||||
new_client_data['is_company'] = "0"
|
||||
|
||||
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(
|
||||
local_inscription_no_client['email']) + " ")
|
||||
return False, " Facturation : Impossible de créer un client associé à l'adresse email : " + str(
|
||||
local_inscription_no_client['email']) + " ", False
|
||||
|
||||
inscription_no_client_valide_no_locked_data = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'partner_recid': str(my_partner['recid']),
|
||||
'email': str(local_inscription_no_client['email']),
|
||||
'valide': "1",
|
||||
'locked': '0'})
|
||||
|
||||
# Créer le contact de communication du client
|
||||
new_client_contact_data['include_com'] = "1"
|
||||
new_client_contact_data['related_collection'] = "partner_client"
|
||||
new_client_contact_data['related_collection_owner_id'] = str(
|
||||
inscription_no_client_valide_no_locked_data['_id'])
|
||||
local_add_contact_status, local_add_contact_retval = Contact.Add_Contact(new_client_contact_data)
|
||||
if (local_add_contact_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " WARNING : Impossible de créer le contact " + str(
|
||||
local_add_contact_retval))
|
||||
|
||||
# Mise à jour de l'inscription avec l'_id du client
|
||||
MYSY_GV.dbname['inscription'].update_one({'partner_owner_recid': str(my_partner['recid']),
|
||||
'_id': ObjectId(local_inscription_no_client['_id'])},
|
||||
{'$set':
|
||||
{
|
||||
'facture_client_rattachement_id': str(
|
||||
inscription_no_client_valide_no_locked_data['_id']),
|
||||
'client_rattachement_id': str(
|
||||
inscription_no_client_valide_no_locked_data['_id'])
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
# Verifier qu'il ya bien des inscriptions valides dans la session pour le client
|
||||
liste_client_rattachement_id = MYSY_GV.dbname['inscription'].distinct("facture_client_rattachement_id",
|
||||
{'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(
|
||||
my_partner['recid']),
|
||||
"facture_client_rattachement_id": {'$ne': ''},
|
||||
"invoiced": {'$ne': '1'},
|
||||
"_id": {'$in': tab_my_inscription_ids_Object},
|
||||
}
|
||||
)
|
||||
|
||||
print(" ### la liste des liste_client_rattachement_id = ", liste_client_rattachement_id)
|
||||
|
||||
# Sauvegarde des fichiers joints depuis le front
|
||||
tab_saved_file_full_path = []
|
||||
for file in tab_files:
|
||||
status, saved_file_full_path = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
||||
if (status is False):
|
||||
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
||||
return False, "Impossible de récupérer correctement le fichier à importer", False
|
||||
|
||||
tab_saved_file_full_path.append(saved_file_full_path)
|
||||
|
||||
print(" #### tab_saved_file_full_path = ", tab_saved_file_full_path)
|
||||
|
||||
# Recupération des données du modèle de document
|
||||
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one(
|
||||
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])}
|
||||
)
|
||||
|
||||
tab_local_invoice_ref_interne = []
|
||||
# Envoie des factures pour les inscrits AVEC client_id (conventions d'entreprise)
|
||||
for single_client in liste_client_rattachement_id:
|
||||
print(" Traitement du client_id = ", single_client)
|
||||
|
||||
# Recuperation des contacts de communication du client
|
||||
local_diction = {}
|
||||
local_diction['token'] = diction['token']
|
||||
local_diction['_id'] = str(single_client)
|
||||
|
||||
print(" ##### local_diction = ", local_diction)
|
||||
local_status, partner_client_contact_communication = partner_client.Get_Partner_Client_Communication_Contact(
|
||||
local_diction)
|
||||
|
||||
if (local_status is False):
|
||||
mycommon.myprint(" Impossible de récupérer les contacts de communication du client ")
|
||||
return False, " Impossible de récupérer les contacts de communication du client ", False
|
||||
|
||||
print(" ### partner_client_contact_communication = ", partner_client_contact_communication)
|
||||
tab_local_email_production = []
|
||||
for tmp in partner_client_contact_communication:
|
||||
tmp_JSON = ast.literal_eval(tmp)
|
||||
if ("email" in tmp_JSON.keys()):
|
||||
tab_local_email_production.append(str(tmp_JSON["email"]))
|
||||
|
||||
list_local_email_production = ",".join(tab_local_email_production)
|
||||
|
||||
new_diction_client = {}
|
||||
new_diction_client['partner_client_id'] = single_client
|
||||
new_diction_client['token'] = diction['token']
|
||||
new_diction_client['courrier_template_id'] = diction['courrier_template_id']
|
||||
new_diction_client['email_test'] = diction['email_test']
|
||||
new_diction_client['email_production'] = str(list_local_email_production)
|
||||
new_diction_client['session_id'] = diction['session_id']
|
||||
|
||||
print(" ##### new_diction_client 0102 = ", new_diction_client)
|
||||
|
||||
# Creation de la facture du client
|
||||
diction_invoice = {}
|
||||
diction_invoice['token'] = diction['token']
|
||||
diction_invoice['partner_client_id'] = single_client
|
||||
diction_invoice['session_id'] = diction['session_id']
|
||||
diction_invoice['tab_inscription_ids'] = tab_my_inscription_ids_Object
|
||||
print(" ##### diction_invoice 0202 = ", diction_invoice)
|
||||
local_create_invoice_status, local_create_invoice_retval, local_invoice_ref_interne = Invoice_Partner_From_Session_By_Inscription_Id(
|
||||
diction_invoice)
|
||||
if (local_create_invoice_status is False):
|
||||
return local_create_invoice_status, local_create_invoice_retval, False
|
||||
|
||||
"""
|
||||
Mettre à jour les lignes associées à ce client pour dire que la ligne est facturé
|
||||
"""
|
||||
now = str(datetime.now())
|
||||
update_data = {}
|
||||
update_data['invoiced'] = "1"
|
||||
update_data['invoiced_ref'] = str(local_invoice_ref_interne)
|
||||
update_data['invoiced_date'] = now
|
||||
update_data['date_update'] = now
|
||||
update_data['update_by'] = str(my_partner['_id'])
|
||||
|
||||
update = MYSY_GV.dbname['inscription'].update_many({'partner_owner_recid': str(my_partner['recid']),
|
||||
'session_id': diction['session_id'],
|
||||
'facture_client_rattachement_id': str(single_client),
|
||||
"_id": {'$in': tab_my_inscription_ids_Object},
|
||||
},
|
||||
{'$set': update_data})
|
||||
|
||||
tab_local_invoice_ref_interne.append(str(local_invoice_ref_interne))
|
||||
|
||||
"""
|
||||
07/03/20204 : mettre un statut de facturation sur la session afin de voir
|
||||
tout de suite quel session est entièrement facturée ou partiellement.
|
||||
|
||||
regles :
|
||||
Si toutes les inscription associées à une session sont facturée ==> invoiced_statut de la session = 2
|
||||
Si au moins une inscription associée à une session est facturé ==> invoiced_statut de la session = 1
|
||||
Si non invoiced_statut de la session =0
|
||||
"""
|
||||
nb_inscription_facture = MYSY_GV.dbname['inscription'].count_documents({'partner_owner_recid':my_partner['recid'],
|
||||
'invoiced':'1'})
|
||||
|
||||
nb_inscription_non_facture = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'partner_owner_recid': my_partner['recid'],
|
||||
'invoiced': {'$ne':'1'}})
|
||||
|
||||
nb_inscription_valide = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'partner_owner_recid': my_partner['recid'],
|
||||
'status':'1'})
|
||||
|
||||
invoiced_statut = "0"
|
||||
if( nb_inscription_facture == nb_inscription_valide ):
|
||||
# toutes les inscription valides ont été facturée
|
||||
invoiced_statut = "2"
|
||||
elif ( nb_inscription_facture > 0 ):
|
||||
# Au moins une ligne a été facturée
|
||||
invoiced_statut = "1"
|
||||
|
||||
# Mise à jour du statut de facturation de la session
|
||||
MYSY_GV.dbname['session_formation'].update_one({'partner_owner_recid':my_partner['recid'],
|
||||
'valide':'1',
|
||||
'_id':ObjectId(str(diction['session_id']))
|
||||
},
|
||||
{'$set':{'invoiced_statut':invoiced_statut}})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Creation de l'historique dans les action 'courrier_template_tracking_history'
|
||||
local_qry = {'partner_owner_recid': str(my_partner['recid']), 'session_id': str(diction['session_id']),
|
||||
'invoiced_ref': {'$in': tab_local_invoice_ref_interne}}
|
||||
|
||||
# print(" ### local_qry = ", local_qry)
|
||||
|
||||
for val in MYSY_GV.dbname['inscription'].find({'partner_owner_recid': str(my_partner['recid']),
|
||||
'session_id': str(diction['session_id']),
|
||||
'invoiced_ref': {'$in': tab_local_invoice_ref_interne}}):
|
||||
|
||||
ref_facture = ""
|
||||
if ("invoiced_ref" in val.keys()):
|
||||
ref_facture = val['invoiced_ref']
|
||||
|
||||
local_status, local_retval = module_editique.Editic_Log_History_Action_From_courrier_template_type_document_ref_interne(
|
||||
my_partner, "FACTURATION_SESSION", str(diction['session_id']), 'inscription',
|
||||
str(val['_id']),
|
||||
str(diction['courrier_template_id']),
|
||||
"Facture : " + str(ref_facture)
|
||||
)
|
||||
|
||||
if (local_status is False):
|
||||
mycommon.myprint(" WARNING : Impossible de logguer l'historique l'inscription_id : " + str(val['_id']))
|
||||
|
||||
return_message = " La session a été correctement facturée.\nListe des factures : "
|
||||
for tmp in tab_local_invoice_ref_interne:
|
||||
return_message += "\n - " + str(tmp)
|
||||
|
||||
return True, str(return_message), tab_local_invoice_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 créer et d'envoyer les factures par email ", False
|
||||
|
||||
|
||||
"""
|
||||
Sauvegarde fonction avant modif
|
||||
"""
|
||||
|
||||
|
||||
def Prepare_and_Send_Facture_From_Session_By_Inscription_Id_SAVE_ORIG(tab_files, Folder, diction):
|
||||
try:
|
||||
|
||||
field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'email_test', 'email_production',
|
||||
'tab_inscription_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 liste ")
|
||||
return False, " La valeur '" + val + "' n'est pas presente dans liste", False
|
||||
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_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
|
||||
|
||||
my_inscription_ids = ""
|
||||
tab_my_inscription_ids = []
|
||||
tab_my_inscription_ids_Object = []
|
||||
if ("tab_inscription_ids" in diction.keys()):
|
||||
if diction['tab_inscription_ids']:
|
||||
my_inscription_ids = diction['tab_inscription_ids']
|
||||
|
||||
tab_my_inscription_ids = str(my_inscription_ids).split(",")
|
||||
print(" ### tab_my_inscription_ids = ", tab_my_inscription_ids)
|
||||
for my_inscription_id in tab_my_inscription_ids:
|
||||
|
||||
tmp_count = MYSY_GV.dbname['inscription'].count_documents({'session_id': str(diction['session_id']),
|
||||
'_id': ObjectId(str(my_inscription_id)),
|
||||
'partner_owner_recid': str(
|
||||
my_partner['recid'])})
|
||||
|
||||
if (tmp_count != 1):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " L'indentifiant de l'inscription " + str(
|
||||
my_inscription_id) + " est invalide ")
|
||||
return False, " L'indentifiant de l'inscription " + str(my_inscription_id) + " est invalide "
|
||||
|
||||
tab_my_inscription_ids_Object.append(ObjectId(str(my_inscription_id)))
|
||||
|
||||
# Verifier que la session est valide
|
||||
is_session_valide = MYSY_GV.dbname['session_formation'].count_documents(
|
||||
{'_id': ObjectId(str(diction['session_id'])),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (is_session_valide != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de la session est invalide ")
|
||||
return False, " L'identifiant de la session est invalide ", False
|
||||
|
||||
"""
|
||||
Gestion des inscriptions n'ayant pas de client ID
|
||||
"""
|
||||
liste_inscription_no_client = MYSY_GV.dbname['inscription'].find(
|
||||
{"$or": [{'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
"client_rattachement_id": '',
|
||||
"invoiced": {'$ne': '1'},
|
||||
"_id": {'$in': tab_my_inscription_ids_Object},
|
||||
},
|
||||
{'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
|
@ -8303,7 +9130,6 @@ def Prepare_and_Send_Facture_From_Session_By_Inscription_Id(tab_files, Folder, d
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
# CONTROLE : Verification des data client (si tous les clients 'particuliers' sont ok
|
||||
for local_inscription_no_client in liste_inscription_no_client:
|
||||
print(" ### List des inscrit n'ayant pas de 'client_id': ", local_inscription_no_client)
|
||||
|
@ -8466,7 +9292,8 @@ def Prepare_and_Send_Facture_From_Session_By_Inscription_Id(tab_files, Folder, d
|
|||
my_partner['recid']),
|
||||
"client_rattachement_id": {'$ne': ''},
|
||||
"invoiced": {'$ne': '1'},
|
||||
"_id": {'$in': tab_my_inscription_ids_Object},
|
||||
"_id": {
|
||||
'$in': tab_my_inscription_ids_Object},
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -8564,41 +9391,38 @@ def Prepare_and_Send_Facture_From_Session_By_Inscription_Id(tab_files, Folder, d
|
|||
"""
|
||||
07/03/20204 : mettre un statut de facturation sur la session afin de voir
|
||||
tout de suite quel session est entièrement facturée ou partiellement.
|
||||
|
||||
|
||||
regles :
|
||||
Si toutes les inscription associées à une session sont facturée ==> invoiced_statut de la session = 2
|
||||
Si au moins une inscription associée à une session est facturé ==> invoiced_statut de la session = 1
|
||||
Si non invoiced_statut de la session =0
|
||||
"""
|
||||
nb_inscription_facture = MYSY_GV.dbname['inscription'].count_documents({'partner_owner_recid':my_partner['recid'],
|
||||
'invoiced':'1'})
|
||||
nb_inscription_facture = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'partner_owner_recid': my_partner['recid'],
|
||||
'invoiced': '1'})
|
||||
|
||||
nb_inscription_non_facture = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'partner_owner_recid': my_partner['recid'],
|
||||
'invoiced': {'$ne':'1'}})
|
||||
'invoiced': {'$ne': '1'}})
|
||||
|
||||
nb_inscription_valide = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'partner_owner_recid': my_partner['recid'],
|
||||
'status':'1'})
|
||||
'status': '1'})
|
||||
|
||||
invoiced_statut = "0"
|
||||
if( nb_inscription_facture == nb_inscription_valide ):
|
||||
if (nb_inscription_facture == nb_inscription_valide):
|
||||
# toutes les inscription valides ont été facturée
|
||||
invoiced_statut = "2"
|
||||
elif ( nb_inscription_facture > 0 ):
|
||||
elif (nb_inscription_facture > 0):
|
||||
# Au moins une ligne a été facturée
|
||||
invoiced_statut = "1"
|
||||
|
||||
# Mise à jour du statut de facturation de la session
|
||||
MYSY_GV.dbname['session_formation'].update_one({'partner_owner_recid':my_partner['recid'],
|
||||
'valide':'1',
|
||||
'_id':ObjectId(str(diction['session_id']))
|
||||
MYSY_GV.dbname['session_formation'].update_one({'partner_owner_recid': my_partner['recid'],
|
||||
'valide': '1',
|
||||
'_id': ObjectId(str(diction['session_id']))
|
||||
},
|
||||
{'$set':{'invoiced_statut':invoiced_statut}})
|
||||
|
||||
|
||||
|
||||
|
||||
{'$set': {'invoiced_statut': invoiced_statut}})
|
||||
|
||||
# Creation de l'historique dans les action 'courrier_template_tracking_history'
|
||||
local_qry = {'partner_owner_recid': str(my_partner['recid']), 'session_id': str(diction['session_id']),
|
||||
|
@ -8636,7 +9460,6 @@ def Prepare_and_Send_Facture_From_Session_By_Inscription_Id(tab_files, Folder, d
|
|||
return False, " Impossible de créer et d'envoyer les factures par email ", False
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Creation des factures pour un client avec uniquement la liste des inscriptions concernée.
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ def Add_Class_Categorie(diction):
|
|||
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, " IImpossible de créer la catégorie de formation "
|
||||
return False, " Impossible de créer la catégorie de formation "
|
||||
|
||||
|
||||
"""
|
||||
|
|
|
@ -0,0 +1,650 @@
|
|||
"""
|
||||
Ce fichier permet de gerer les notes de apprenants dans le système
|
||||
Principe de base :
|
||||
• On crée les types de d’évaluation. Par exemple : TD, TP, Projet, Projet_UE (le projet à l’intérieur d’une UE), Stage, Contrôle_Continue etc.
|
||||
• Pour chaque UE, créer les évaluations associées. Par exemple certaines UE n’ont pas de TP, donc pas d’évaluation TP,
|
||||
• Pour chaque Evaluation d’une EU, on associe une liste de notes.
|
||||
|
||||
"""
|
||||
import bson
|
||||
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
|
||||
import GlobalVariable as MYSY_GV
|
||||
from math import isnan
|
||||
import GlobalVariable as MYSY_GV
|
||||
import ela_index_bdd_classes as eibdd
|
||||
import email_mgt as email
|
||||
import jinja2
|
||||
from flask import send_file
|
||||
from xhtml2pdf import pisa
|
||||
from email.message import EmailMessage
|
||||
from email.mime.text import MIMEText
|
||||
from email import encoders
|
||||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.base import MIMEBase
|
||||
from email import encoders
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Ajout d'un type d'evaluation
|
||||
"""
|
||||
|
||||
def Add_Evaluation_Type(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'code', 'nom', 'description']
|
||||
|
||||
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', 'code', 'nom', ]
|
||||
|
||||
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, " 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 que ce code n'existe pas déjà
|
||||
is_existe_type_evaluation = MYSY_GV.dbname['type_evaluation'].count_documents({'code':str(diction['code']),
|
||||
'valide':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
|
||||
if( is_existe_type_evaluation > 0 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Un type d'évaluation avec le code '" + str(diction['code']) + "' existe déjà ")
|
||||
return False, " Un type d'évaluation avec le code '" + str(diction['code']) + "' existe déjà "
|
||||
|
||||
|
||||
|
||||
|
||||
new_data = diction
|
||||
del diction['token']
|
||||
|
||||
# Initialisation des champs non envoyés à vide
|
||||
for val in field_list:
|
||||
if val not in diction.keys():
|
||||
new_data[str(val)] = ""
|
||||
|
||||
new_data['valide'] = "1"
|
||||
new_data['locked'] = "0"
|
||||
|
||||
new_data['date_update'] = str(datetime.now())
|
||||
new_data['update_by'] = str(my_partner['_id'])
|
||||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
inserted_id = MYSY_GV.dbname['type_evaluation'].insert_one(new_data).inserted_id
|
||||
if (not inserted_id):
|
||||
mycommon.myprint(
|
||||
" Impossible de créer le type d'évaluation (2) ")
|
||||
return False, " Impossible de créer le type d'évaluation (2) "
|
||||
|
||||
|
||||
return True, " Le type d'évaluation a été correctement ajouté"
|
||||
|
||||
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 créer le type d'évaluation "
|
||||
|
||||
|
||||
"""
|
||||
Mise à jour d'un type d'évaluation
|
||||
"""
|
||||
|
||||
def Update_Evaluation_Type(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', '_id', 'code', 'nom', 'description',]
|
||||
|
||||
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', '_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 liste ")
|
||||
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
|
||||
|
||||
new_data = diction
|
||||
|
||||
# Verifier que le type d'évaluation
|
||||
is_existe_type_evaluation = MYSY_GV.dbname['type_evaluation'].count_documents(
|
||||
{'_id': ObjectId(str(diction['_id'])),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (is_existe_type_evaluation < 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'identifiant du type d'évaluation est invalide ")
|
||||
return False, " L'identifiant du type d'évaluation est invalide "
|
||||
|
||||
|
||||
|
||||
local_id = str(diction['_id'])
|
||||
|
||||
del diction['token']
|
||||
del diction['_id']
|
||||
|
||||
|
||||
new_data['date_update'] = str(datetime.now())
|
||||
new_data['update_by'] = str(my_partner['_id'])
|
||||
|
||||
data_cle = {}
|
||||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||||
data_cle['_id'] = ObjectId(local_id)
|
||||
data_cle['valide'] = "1"
|
||||
data_cle['locked'] = "0"
|
||||
|
||||
result = MYSY_GV.dbname['type_evaluation'].find_one_and_update(
|
||||
data_cle,
|
||||
{"$set": new_data},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if ("_id" not in result.keys()):
|
||||
mycommon.myprint(
|
||||
" Impossible de mettre à jour le type d'évaluation (2) ")
|
||||
return False, " Impossible de mettre à jour le type d'évaluation (2) "
|
||||
|
||||
return True, " Le type d'évaluation a été correctement mis à jour"
|
||||
|
||||
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 mettre à jour le type d'évaluation "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Suppression d'un type d'évaluation
|
||||
regles :
|
||||
|
||||
"""
|
||||
|
||||
def Delete_Type_Evaluation(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', '_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', '_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 liste ")
|
||||
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 que la codition de paiement existe
|
||||
is_existe_type_eval = MYSY_GV.dbname['type_evaluation'].count_documents(
|
||||
{'_id': ObjectId(str(diction['_id'])),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (is_existe_type_eval < 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'identifiant du type d'évaluation n'est pas valide ")
|
||||
return False, " L'identifiant du type d'évaluation n'est pas valide "
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
delete = MYSY_GV.dbname['type_evaluation'].delete_one({'_id': ObjectId(str(diction['_id'])),
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
}, )
|
||||
|
||||
|
||||
|
||||
return True, " Le type d'évaluation a été correctement supprimé"
|
||||
|
||||
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 supprimer type d'évaluation "
|
||||
|
||||
|
||||
"""
|
||||
Recuperer la liste des type d'evaluation d'un partenaire
|
||||
"""
|
||||
def Get_List_Type_Evaluation(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', ]
|
||||
|
||||
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'existe pas")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
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, " 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
|
||||
|
||||
"""
|
||||
Clés de mise à jour
|
||||
"""
|
||||
data_cle = {}
|
||||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||||
data_cle['valide'] = "1"
|
||||
data_cle['locked'] = "0"
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
for retval in MYSY_GV.dbname['type_evaluation'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
||||
user = retval
|
||||
user['id'] = str(val_tmp)
|
||||
val_tmp = val_tmp + 1
|
||||
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer la liste des type d'évaluation "
|
||||
|
||||
|
||||
"""
|
||||
Recuperer les données d'un type d'évaluation donné
|
||||
"""
|
||||
def Get_Given_Type_Evaluation(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', '_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'existe pas")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', '_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 liste ")
|
||||
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
|
||||
|
||||
"""
|
||||
Clés de mise à jour
|
||||
"""
|
||||
data_cle = {}
|
||||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||||
data_cle['valide'] = "1"
|
||||
data_cle['locked'] = "0"
|
||||
data_cle['_id'] = ObjectId(str(diction['_id']))
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
for retval in MYSY_GV.dbname['type_evaluation'].find(data_cle):
|
||||
user = retval
|
||||
user['id'] = str(val_tmp)
|
||||
val_tmp = val_tmp + 1
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer le types d'évaluation "
|
||||
|
||||
|
||||
"""
|
||||
Ajout ou mettre à jour une evaluation à une l'UE d'une formation.
|
||||
les champs :
|
||||
- class_id,
|
||||
- class_ue_id,
|
||||
- type_evaluation_id,
|
||||
- max_note
|
||||
"""
|
||||
|
||||
def Add_Class_UE_Evaluation(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'class_id', 'class_ue_id', 'type_evaluation_id', 'max_note',
|
||||
]
|
||||
|
||||
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', 'class_id', 'class_ue_id', 'type_evaluation_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 liste ")
|
||||
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 que class_ue_id est valide
|
||||
"""
|
||||
is_ue_id_existe_class = MYSY_GV.dbname['myclass'].count_documents({ '_id':ObjectId(str(diction['class_id'])),
|
||||
'list_unite_enseignement._id': str(diction['class_ue_id']),
|
||||
'partner_owner_recid':my_partner['recid'],
|
||||
'valide':'1',
|
||||
'locked':'0'})
|
||||
|
||||
if (is_ue_id_existe_class != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'unité d'enseignement n'existe pas dans la formation ")
|
||||
return False, " L'unité d'enseignement n'existe pas dans la formation "
|
||||
|
||||
|
||||
"""
|
||||
Verifier que le type d'évaluation existe
|
||||
"""
|
||||
is_type_eval_existe = MYSY_GV.dbname['type_evaluation'].count_documents({'_id':ObjectId(str(diction['type_evaluation_id'])),
|
||||
'partner_owner_recid':my_partner['recid'],
|
||||
'valide': '1',
|
||||
'locked': '0'
|
||||
})
|
||||
|
||||
if( is_type_eval_existe != 1 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'identifiant du type de formation est invalide ")
|
||||
return False, " L'identifiant du type de formation est invalide "
|
||||
|
||||
new_data = diction
|
||||
del diction['token']
|
||||
|
||||
# Initialisation des champs non envoyés à vide
|
||||
for val in field_list:
|
||||
if val not in diction.keys():
|
||||
new_data[str(val)] = ""
|
||||
|
||||
new_data['valide'] = "1"
|
||||
new_data['locked'] = "0"
|
||||
|
||||
new_data['date_update'] = str(datetime.now())
|
||||
new_data['update_by'] = str(my_partner['_id'])
|
||||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
inserted_id = MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].insert_one(new_data).inserted_id
|
||||
if (not inserted_id):
|
||||
mycommon.myprint(
|
||||
" Impossible de créer l'évaluation pour l'UE (2) ")
|
||||
return False, " Impossible de créer l'évaluation pour l'UE (2) "
|
||||
|
||||
|
||||
return True, " L'évaluation a été correctement ajoutée"
|
||||
|
||||
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 créer l'évaluation pour l'UE "
|
||||
|
||||
|
||||
def Update_Class_UE_Evaluation(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'max_note', 'class_ue_evaluation_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', 'class_ue_evaluation_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 liste ")
|
||||
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 que class_ue_id est valide
|
||||
"""
|
||||
is_ue_id_existe_class = MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].count_documents({ '_id':ObjectId(str(diction['class_ue_evaluation_id'])),
|
||||
'partner_owner_recid':my_partner['recid'],
|
||||
'valide': '1',
|
||||
'locked': '0'
|
||||
})
|
||||
|
||||
if (is_ue_id_existe_class != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'identifiant de l'évaluation est invalide ")
|
||||
return False, " L'identifiant de l'évaluation est invalide "
|
||||
|
||||
|
||||
|
||||
new_data = diction
|
||||
del diction['token']
|
||||
del diction['class_ue_evaluation_id']
|
||||
|
||||
# Initialisation des champs non envoyés à vide
|
||||
for val in field_list:
|
||||
if val not in diction.keys():
|
||||
new_data[str(val)] = ""
|
||||
|
||||
new_data['valide'] = "1"
|
||||
new_data['locked'] = "0"
|
||||
|
||||
new_data['date_update'] = str(datetime.now())
|
||||
new_data['update_by'] = str(my_partner['_id'])
|
||||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
result = MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].find_one_and_update(
|
||||
{'_id': ObjectId(str(diction['class_ue_evaluation_id'])),
|
||||
'partner_owner_recid': my_partner['recid'],
|
||||
'valide': '1',
|
||||
'locked': '0'
|
||||
},
|
||||
{"$set": new_data},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if ("_id" not in result.keys()):
|
||||
mycommon.myprint(
|
||||
" Impossible de mettre à jour l'évaluation (2) ")
|
||||
return False, " Impossible de mettre à jour l'évaluation (2) "
|
||||
|
||||
|
||||
|
||||
return True, " L'évaluation a été correctement mise à jour"
|
||||
|
||||
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 mettre à jour l'évaluation "
|
||||
|
|
@ -1674,7 +1674,7 @@ def GerneratePDF_Partner_Invoice(diction):
|
|||
|
||||
contenu_doc_Template = jinja2.Template(str(partner_document_INVOICE_data['contenu_doc']))
|
||||
|
||||
#print(" #### Order_header_data = ", Order_header_data)
|
||||
print(" #### partner_document_INVOICE_data = ", str(partner_document_INVOICE_data['contenu_doc']))
|
||||
#sourceHtml = contenu_doc_Template.render(params=Order_header_data)
|
||||
|
||||
#print(" ### Order_header_data = ", Order_header_data)
|
||||
|
@ -1751,9 +1751,16 @@ def GerneratePDF_Partner_Invoice(diction):
|
|||
|
||||
"""
|
||||
|
||||
print("company_data = ", company_data)
|
||||
sourceHtml = contenu_doc_Template.render(params=Order_header_data, param_order_lines=Order_header_lines_data, company_data=company_data)
|
||||
"""
|
||||
print("Order_header_data = ", Order_header_data)
|
||||
print("Order_header_lines_data = ", Order_header_lines_data)
|
||||
print("company_data['params'] = ", company_data['params'])
|
||||
"""
|
||||
|
||||
#sourceHtml = contenu_doc_Template.render(params=Order_header_data, param_order_lines=Order_header_lines_data, company_data=company_data)
|
||||
|
||||
sourceHtml = contenu_doc_Template.render(params_order_header=Order_header_data, params_order_lines=Order_header_lines_data,
|
||||
params=company_data['params'])
|
||||
|
||||
orig_file_name = "Partner_Invoice_"+str(Order_header_data['invoice_header_ref_interne'])+".pdf"
|
||||
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) +"/"+ str(orig_file_name)
|
||||
|
@ -2023,7 +2030,6 @@ def Send_Partner_Invoice_By_Email(diction):
|
|||
contenu_doc_Template = jinja2.Template(str(partner_document_INVOICE_data['contenu_doc']))
|
||||
|
||||
# Recuperation des données du partenaire associé à l'utilisateur connecté
|
||||
|
||||
local_status, local_retval = mycommon.Get_Connected_User_Partner_Data_From_RecID(my_partner['recid'])
|
||||
if (local_status is False):
|
||||
return local_status, local_retval
|
||||
|
@ -2031,6 +2037,7 @@ def Send_Partner_Invoice_By_Email(diction):
|
|||
|
||||
local_company_data = local_retval
|
||||
|
||||
"""
|
||||
# Recuperation des données de la société
|
||||
company_data = {}
|
||||
|
||||
|
@ -2065,19 +2072,52 @@ def Send_Partner_Invoice_By_Email(diction):
|
|||
company_data.update(new_field_logo)
|
||||
company_data.update(new_field_cachet)
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
Recuperation du dictionnaire des info
|
||||
"""
|
||||
tab_client = []
|
||||
tab_client.append(ObjectId(str(Order_header_client_data['_id'])))
|
||||
|
||||
new_diction = {}
|
||||
new_diction['token'] = diction['token']
|
||||
new_diction['list_stagiaire_id'] = []
|
||||
new_diction['list_session_id'] = []
|
||||
new_diction['list_class_id'] = []
|
||||
new_diction['list_client_id'] = tab_client
|
||||
new_diction['list_apprenant_id'] = []
|
||||
|
||||
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
||||
|
||||
if (local_status is False):
|
||||
return local_status, local_retval
|
||||
|
||||
convention_dictionnary_data = local_retval
|
||||
company_data = {
|
||||
"params": convention_dictionnary_data,
|
||||
}
|
||||
|
||||
|
||||
|
||||
contenu_doc_Template_subject = jinja2.Template(str(partner_document_INVOICE_data['sujet']))
|
||||
|
||||
#print(" #### Order_header_data = ", Order_header_data)
|
||||
sourceHtml = contenu_doc_Template.render(params=Order_header_data, param_order_lines=Order_header_lines_data, company_data=company_data)
|
||||
sujetHtml = contenu_doc_Template_subject.render(params=Order_header_data)
|
||||
#sourceHtml = contenu_doc_Template.render(params=Order_header_data, param_order_lines=Order_header_lines_data, company_data=company_data)
|
||||
|
||||
contenu_doc_Template = jinja2.Template(str(partner_document_INVOICE_data['contenu_doc']))
|
||||
contenuHtml = contenu_doc_Template.render(params_order_header=Order_header_data,
|
||||
params_order_lines=Order_header_lines_data,
|
||||
params=company_data['params'])
|
||||
|
||||
contenu_doc_Template_subject = jinja2.Template(str(partner_document_INVOICE_data['sujet']))
|
||||
sujetHtml = contenu_doc_Template_subject.render(params_order_header=Order_header_data)
|
||||
|
||||
#print(" #### sourceHtml = ", sourceHtml)
|
||||
|
||||
|
||||
print("debut envoi mail de test ")
|
||||
msg = EmailMessage()
|
||||
msg.set_content(sourceHtml, subtype='html')
|
||||
msg.set_content(contenuHtml, subtype='html')
|
||||
|
||||
|
||||
"""
|
||||
|
@ -2310,28 +2350,32 @@ def Compute_Invoice_Order_Data(diction):
|
|||
local_retval['order_line_montant_reduction'])
|
||||
ligne_montant_reduction = mycommon.tryFloat(local_retval['order_line_montant_reduction'])
|
||||
|
||||
"""
|
||||
print(" #### invoice_line_montant_reduction = ",
|
||||
str(mycommon.tryFloat(local_retval['order_line_montant_reduction'])))
|
||||
"""
|
||||
|
||||
if ("order_line_tax_amount" in local_retval.keys()):
|
||||
line_sum_invoice_line_tax_amount = line_sum_invoice_line_tax_amount + mycommon.tryFloat(
|
||||
local_retval['order_line_tax_amount'])
|
||||
print(" #### invoice_line_tax_amount = ", str(mycommon.tryFloat(local_retval['order_line_tax_amount'])))
|
||||
#print(" #### invoice_line_tax_amount = ", str(mycommon.tryFloat(local_retval['order_line_tax_amount'])))
|
||||
|
||||
if ("order_line_montant_hors_taxes" in local_retval.keys()):
|
||||
line_sum_invoice_line_montant_hors_taxes_before_reduction = line_sum_invoice_line_montant_hors_taxes_before_reduction + mycommon.tryFloat(
|
||||
local_retval['order_line_montant_hors_taxes'])
|
||||
|
||||
"""
|
||||
print(" #### invoice_line_montant_hors_taxes = ",
|
||||
str(mycommon.tryFloat(local_retval['order_line_montant_hors_taxes'])))
|
||||
"""
|
||||
|
||||
invoice_line_montant_hors_taxes_APRES_REDUCTION = mycommon.tryFloat(
|
||||
local_retval['order_line_montant_hors_taxes']) - ligne_montant_reduction
|
||||
print(" #### invoice_line_montant_hors_taxes_APRES_REDUCTION = ", str(invoice_line_montant_hors_taxes_APRES_REDUCTION))
|
||||
#print(" #### invoice_line_montant_hors_taxes_APRES_REDUCTION = ", str(invoice_line_montant_hors_taxes_APRES_REDUCTION))
|
||||
|
||||
if ("order_line_montant_toutes_taxes" in local_retval.keys()):
|
||||
line_sum_invoice_line_montant_toutes_taxes = line_sum_invoice_line_montant_toutes_taxes + mycommon.tryFloat(local_retval['order_line_montant_toutes_taxes'])
|
||||
print(" #### invoice_line_montant_toutes_taxes = ", str(mycommon.tryFloat(local_retval['order_line_montant_toutes_taxes'])))
|
||||
#print(" #### invoice_line_montant_toutes_taxes = ", str(mycommon.tryFloat(local_retval['order_line_montant_toutes_taxes'])))
|
||||
|
||||
print(" ----------- FIN DES LIGNES ")
|
||||
|
||||
|
@ -2378,6 +2422,8 @@ def Compute_Invoice_Order_Data(diction):
|
|||
"""
|
||||
|
||||
elif (str(header_reduction_type) == "percent"):
|
||||
|
||||
"""
|
||||
print(" GRRRR line_sum_order_line_montant_hors_taxes_after_reduction = ",
|
||||
line_sum_invoice_line_montant_hors_taxes_after_reduction)
|
||||
print(" GRRRR mycommon.tryFloat(header_reduction_type_value)/100 = ",
|
||||
|
@ -2387,15 +2433,17 @@ def Compute_Invoice_Order_Data(diction):
|
|||
(line_sum_invoice_line_montant_hors_taxes_after_reduction - (
|
||||
line_sum_invoice_line_montant_hors_taxes_after_reduction * mycommon.tryFloat(
|
||||
header_reduction_type_value) / 100)))
|
||||
|
||||
"""
|
||||
header_reduction_type_value_total_amount = line_sum_invoice_line_montant_hors_taxes_after_reduction * mycommon.tryFloat(
|
||||
header_reduction_type_value) / 100
|
||||
global_order_amount_ht_after_header_reduction = line_sum_invoice_line_montant_hors_taxes_after_reduction - ((
|
||||
line_sum_invoice_line_montant_hors_taxes_after_reduction * mycommon.tryFloat(
|
||||
header_reduction_type_value) / 100))
|
||||
|
||||
"""
|
||||
print(" GRRRR global_order_amount_ht_after_header_reduction = ",
|
||||
global_order_amount_ht_after_header_reduction)
|
||||
|
||||
"""
|
||||
else:
|
||||
header_reduction_type_value_total_amount = 0
|
||||
global_order_amount_ht_before_header_reduction = line_sum_invoice_line_montant_hors_taxes_after_reduction
|
||||
|
|
Loading…
Reference in New Issue