ssdqs
parent
9048dc6d15
commit
6f767f06cf
|
@ -1,10 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="04/03/2024 - 22h15">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="06/03/2024 - 22h15">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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$/crm_opportunite.py" beforeDir="false" afterPath="$PROJECT_DIR$/crm_opportunite.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Session_Formation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -74,13 +75,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00187" summary="04/01/2024 - 22h30">
|
||||
<created>1704403529234</created>
|
||||
<option name="number" value="00187" />
|
||||
<option name="presentableId" value="LOCAL-00187" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1704403529234</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00188" summary="5555">
|
||||
<created>1704469014108</created>
|
||||
<option name="number" value="00188" />
|
||||
|
@ -417,7 +411,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1709587020474</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="236" />
|
||||
<task id="LOCAL-00236" summary="06/03/2024 - 22h15">
|
||||
<created>1709759516683</created>
|
||||
<option name="number" value="00236" />
|
||||
<option name="presentableId" value="LOCAL-00236" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1709759516692</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="237" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -432,7 +433,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="04/02/2024 - 21h" />
|
||||
<MESSAGE value="04/02/2024 - 23h" />
|
||||
<MESSAGE value="05/02/2024 -23h" />
|
||||
<MESSAGE value="06/02/2024 -20h" />
|
||||
|
@ -457,6 +457,7 @@
|
|||
<MESSAGE value="02/03/2024 - 23h20" />
|
||||
<MESSAGE value="sss" />
|
||||
<MESSAGE value="04/03/2024 - 22h15" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="04/03/2024 - 22h15" />
|
||||
<MESSAGE value="06/03/2024 - 22h15" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="06/03/2024 - 22h15" />
|
||||
</component>
|
||||
</project>
|
2446
Log/log_file.log
2446
Log/log_file.log
File diff suppressed because it is too large
Load Diff
|
@ -8069,3 +8069,726 @@ def Sent_Facture_Stagiaire_By_Email_By_Partner_client(tab_files_name_full_path,
|
|||
return False, " Impossible d'envoyer la convention par email "
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Facturation partielles d'une session.
|
||||
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
|
||||
|
||||
"""
|
||||
def Prepare_and_Send_Facture_From_Session_By_Inscription_Id(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)))
|
||||
|
||||
print(" éééé tab_my_inscription_ids_Object = ", tab_my_inscription_ids_Object)
|
||||
# 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']),
|
||||
'client_rattachement_id': {'$exists': False},
|
||||
"invoiced": {'$ne': '1'},
|
||||
"_id": {'$in': tab_my_inscription_ids_Object},
|
||||
}]
|
||||
}
|
||||
)
|
||||
|
||||
print(" zzzzz ")
|
||||
# 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': {'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': {'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("client_rattachement_id",
|
||||
{'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(
|
||||
my_partner['recid']),
|
||||
"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'],
|
||||
'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))
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Creation des factures pour un client avec uniquement la liste des inscriptions concernée.
|
||||
|
||||
Ex : je veux facturer que 2 des 5 inscrits d'un client donné.
|
||||
"""
|
||||
def Invoice_Partner_From_Session_By_Inscription_Id( diction):
|
||||
try:
|
||||
|
||||
field_list_obligatoire = ['token', 'partner_client_id', 'session_id', '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
|
||||
|
||||
# Verifier que la session est valide
|
||||
is_session_id_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_id_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
|
||||
|
||||
# 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']),
|
||||
'session_id': str(diction['session_id']),
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'status': '1',
|
||||
'_id':{'$in':diction['tab_inscription_ids']}
|
||||
},
|
||||
)
|
||||
|
||||
if (nb_valide_inscription_pr_client <= 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Aucune inscription valide pour ce client pour cette session ")
|
||||
return False, " Aucune inscription valide pour ce client pour cette session ", False
|
||||
|
||||
partner_client_id_data = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'_id': ObjectId(str(diction['partner_client_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(my_partner['recid'])})
|
||||
|
||||
|
||||
qry = {'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'client_rattachement_id':str(diction['partner_client_id']),
|
||||
'_id':{'$in':diction['tab_inscription_ids']}}
|
||||
|
||||
print(" KRY === ", qry)
|
||||
# Recuperation des données du stagiaire
|
||||
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']),
|
||||
'_id':{'$in':diction['tab_inscription_ids']}})
|
||||
tab_apprenant = []
|
||||
tab_participant = []
|
||||
for val in inscription_data:
|
||||
tab_participant.append(val['_id'])
|
||||
|
||||
"""
|
||||
update du 30/01/2024
|
||||
si le participant à un apprenant_id, alors on recupere la valeur de l'apprenant id. On doit travailler sur cette dernier.
|
||||
En general, avant d'envoyer une convocation ou convention, l'inscription est validée et donc le dossier apprenant existe.
|
||||
Du coup si tout se passe bien, dans cette fonction, on travaillera tjrs avec l'apprenant_id
|
||||
"""
|
||||
|
||||
if ("apprenant_id" in val.keys() and val['apprenant_id']):
|
||||
tab_apprenant.append(ObjectId(str(val['apprenant_id'])))
|
||||
|
||||
|
||||
print(" ### tab_participant = ", tab_participant)
|
||||
print(" ### tab_apprenant = ", tab_apprenant)
|
||||
|
||||
# Recuperations des info de la session de formation
|
||||
session_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(diction['session_id']))})
|
||||
|
||||
tab_session = []
|
||||
tab_session.append(session_data['_id'])
|
||||
|
||||
|
||||
# Recuperation du titre de la formation
|
||||
class_data = MYSY_GV.dbname['myclass'].find({'internal_url': str(session_data['class_internal_url']),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'locked': '0'})
|
||||
|
||||
|
||||
price_by = "perstagiaire"
|
||||
if( "perstagiaire" in session_data.keys() ):
|
||||
price_by = session_data['perstagiaire']
|
||||
if( price_by not in MYSY_GV.TRAINING_PRICE) :
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " Le prix par " + str(price_by) + " n'est valide. Les valeurs autorisées sont " + str(MYSY_GV.TRAINING_PRICE))
|
||||
return False, " Le prix par " + str(price_by) + " n'est valide. Les valeurs autorisées sont " + str(MYSY_GV.TRAINING_PRICE) + " ", False
|
||||
|
||||
partner_invoice_header_data = {}
|
||||
|
||||
list_partner_invoice_header_champ = ['order_header_client_id', 'order_header_ref_interne', 'order_header_email_client', 'order_header_origin', 'order_header_ref_client', 'order_header_vendeur_id',
|
||||
'order_header_date_cmd', 'order_header_date_expiration', 'order_header_adr_fact_adresse', 'order_header_adr_fact_code_postal', 'order_header_adr_fact_ville', 'order_header_adr_fact_pays',
|
||||
'order_header_adr_liv_adresse', 'order_header_adr_liv_code_postal', 'order_header_adr_liv_ville', 'order_header_adr_liv_pays', 'valide', 'locked', 'date_update',
|
||||
'order_header_montant_reduction', 'order_header_tax', 'order_header_tax_amount', 'total_header_hors_taxe_after_header_reduction', 'total_header_hors_taxe_before_header_reduction',
|
||||
'total_header_toutes_taxes', 'total_lines_hors_taxe_after_lines_reduction', 'total_lines_hors_taxe_before_lines_reduction', 'total_lines_montant_reduction', 'invoice_header_ref_interne',
|
||||
'invoice_header_type', 'invoice_date', 'update_by']
|
||||
|
||||
# PreRemplir les champs
|
||||
for val in list_partner_invoice_header_champ:
|
||||
partner_invoice_header_data[str(val)] = ""
|
||||
|
||||
|
||||
partner_invoice_header_data['order_header_client_id'] = str(partner_client_id_data['_id'])
|
||||
|
||||
code_session = ""
|
||||
if( "code_session" in session_data.keys() ):
|
||||
code_session = session_data['code_session']
|
||||
partner_invoice_header_data['order_header_ref_interne'] = "Code_Session_"+str(code_session)
|
||||
|
||||
order_header_email_client = ""
|
||||
if ("email" in partner_client_id_data.keys()):
|
||||
order_header_email_client = partner_client_id_data['email']
|
||||
partner_invoice_header_data['order_header_email_client'] = order_header_email_client
|
||||
|
||||
order_header_origin = "session_id_"+str(session_data['_id'])
|
||||
partner_invoice_header_data['order_header_origin'] = order_header_origin
|
||||
|
||||
order_header_adr_fact_adresse = ""
|
||||
if( "invoice_adresse" in partner_client_id_data.keys() ):
|
||||
order_header_adr_fact_adresse = partner_client_id_data['invoice_adresse']
|
||||
partner_invoice_header_data['order_header_adr_fact_adresse'] = order_header_adr_fact_adresse
|
||||
|
||||
order_header_adr_fact_ville = ""
|
||||
if ("invoice_ville" in partner_client_id_data.keys()):
|
||||
order_header_adr_fact_ville = partner_client_id_data['invoice_adresse']
|
||||
partner_invoice_header_data['order_header_adr_fact_ville'] = order_header_adr_fact_ville
|
||||
|
||||
order_header_adr_fact_code_postal = ""
|
||||
if ("invoice_code_postal" in partner_client_id_data.keys()):
|
||||
order_header_adr_fact_code_postal = partner_client_id_data['invoice_code_postal']
|
||||
partner_invoice_header_data['order_header_adr_fact_code_postal'] = order_header_adr_fact_code_postal
|
||||
|
||||
order_header_adr_fact_pays = ""
|
||||
if ("invoice_pays" in partner_client_id_data.keys()):
|
||||
order_header_adr_fact_pays = partner_client_id_data['invoice_pays']
|
||||
partner_invoice_header_data['order_header_adr_fact_pays'] = order_header_adr_fact_pays
|
||||
|
||||
order_header_montant_reduction = "0"
|
||||
partner_invoice_header_data['order_header_montant_reduction'] = order_header_montant_reduction
|
||||
|
||||
|
||||
# Calcul du Totol HT sans reduction
|
||||
total_ht = 0
|
||||
prix_session = 0
|
||||
session_price = 0
|
||||
if( "prix_session" not in session_data.keys() ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " Facturation : La session n'a pas de prix valide")
|
||||
return False, " Facturation : La session n'a pas de prix valide ", False
|
||||
|
||||
if( str(session_data['prix_session']).strip() == "" ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " Facturation : La session n'a pas de prix valide (2) ")
|
||||
return False, " Facturation : La session n'a pas de prix valide (2) ", False
|
||||
|
||||
prix_session = mycommon.tryFloat(str(session_data['prix_session']))
|
||||
|
||||
|
||||
if( str(price_by).strip() == "persession" ):
|
||||
total_ht = round(prix_session, 2)
|
||||
else:
|
||||
total_ht = round(prix_session * nb_valide_inscription_pr_client, 2)
|
||||
|
||||
partner_invoice_header_data['total_header_hors_taxe_before_header_reduction'] = total_ht
|
||||
|
||||
# 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]) + " Facturation : Impossible de récupérer le taux de TVA ")
|
||||
return False, " Facturation : 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]) + " Facturation : Le taux de TVA est invalide ")
|
||||
return False, " Facturation : Le taux de TVA est invalide ", False
|
||||
|
||||
partner_invoice_header_data['order_header_tax'] = taux_tva_retval
|
||||
partner_invoice_header_data['order_header_tax_amount'] = str(round(tva_value * total_ht/100, 2))
|
||||
partner_invoice_header_data['total_header_toutes_taxes'] = str(round(total_ht + (tva_value * total_ht)/100, 2))
|
||||
partner_invoice_header_data['invoice_header_type'] = "facture"
|
||||
|
||||
# Récuperation de la sequence de l'objet "partner_invoice_header" dans la collection : "mysy_sequence"
|
||||
retval_sequence_invoice = MYSY_GV.dbname['mysy_sequence'].find_one(
|
||||
{'partner_invoice_header': 'partner_order_header',
|
||||
'valide': '1', 'partner_owner_recid': str(
|
||||
my_partner['recid'])})
|
||||
|
||||
if (retval_sequence_invoice is None):
|
||||
# Il n'y pas de sequence pour le partenaire, on va aller chercher la sequence par defaut
|
||||
retval_sequence_invoice = MYSY_GV.dbname['mysy_sequence'].find_one(
|
||||
{'related_mysy_object': 'partner_invoice_header',
|
||||
'valide': '1', 'partner_owner_recid': 'default'})
|
||||
|
||||
if (retval_sequence_invoice is None or "current_val" not in retval_sequence_invoice.keys()):
|
||||
# Il n'y aucune sequence meme par defaut.
|
||||
|
||||
mycommon.myprint(" Facture : Impossible de récupérer la sequence 'retval_sequence_invoice' ")
|
||||
return False, "Facture : Impossible de récupérer la sequence 'retval_sequence_invoice' ", False
|
||||
|
||||
current_seq_value = str(retval_sequence_invoice['current_val'])
|
||||
new_sequence_value = int(mycommon.tryInt(current_seq_value)) + 1
|
||||
new_sequance_data_to_update = {'current_val': new_sequence_value}
|
||||
|
||||
ret_val2 = MYSY_GV.dbname['mysy_sequence'].find_one_and_update(
|
||||
{'_id': ObjectId(str(retval_sequence_invoice['_id'])), 'valide': '1'},
|
||||
{"$set": new_sequance_data_to_update},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=False,
|
||||
)
|
||||
invoice_date_time = str(datetime.now().strftime("%d/%m/%Y"))
|
||||
|
||||
|
||||
"""
|
||||
Verifier qu'il n'y pas une facture du partenaire avec le meme ref interne
|
||||
"""
|
||||
is_already_invoice_ref_exist = MYSY_GV.dbname['partner_invoice_header'].count_documents({'partner_invoice_header':str(my_partner['recid']),
|
||||
'valide':'1',
|
||||
'invoice_header_ref_interne':str(retval_sequence_invoice['prefixe'] + str(current_seq_value))})
|
||||
|
||||
if( is_already_invoice_ref_exist > 0 ):
|
||||
mycommon.myprint(" Facture : Il existe déjà une facture avec la même ref. interne : "+str(retval_sequence_invoice['prefixe'] + str(current_seq_value)))
|
||||
return False, " Facture : Il existe déjà une facture avec la même ref. interne : "+str(retval_sequence_invoice['prefixe'] + str(current_seq_value)), False
|
||||
|
||||
|
||||
partner_invoice_header_data['invoice_header_ref_interne'] = retval_sequence_invoice['prefixe'] + str(current_seq_value)
|
||||
partner_invoice_header_data['invoice_header_type'] = "facture"
|
||||
partner_invoice_header_data['invoice_date'] = invoice_date_time
|
||||
partner_invoice_header_data['update_by'] = str(my_partner['_id'])
|
||||
partner_invoice_header_data['valide'] = "1"
|
||||
partner_invoice_header_data['locked'] = "0"
|
||||
partner_invoice_header_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
partner_invoice_header_data['date_update'] = str(datetime.now())
|
||||
|
||||
|
||||
print(" #### partner_invoice_header_data = ", partner_invoice_header_data)
|
||||
inserted_invoice_id = MYSY_GV.dbname['partner_invoice_header'].insert_one(partner_invoice_header_data).inserted_id
|
||||
if (not inserted_invoice_id):
|
||||
mycommon.myprint(" Facture : Impossible de créer l'entête de la facture ")
|
||||
return False, " Facture : Impossible de créer l'entête de la facture ", False
|
||||
|
||||
|
||||
"""
|
||||
Création des lignes de facture.
|
||||
Pour memo, dans la collection : partner_invoice_line
|
||||
order_line_formation = titre formation
|
||||
order_line_qty = nb participants
|
||||
order_line_comment = la liste des personnes participans
|
||||
"""
|
||||
|
||||
partner_invoice_line_data = {}
|
||||
list_partner_invoice_line_champ = ['order_line_formation', 'order_line_qty', 'order_line_prix_unitaire', 'order_line_tax', 'order_line_tax_amount', 'order_line_montant_toutes_taxes',
|
||||
'order_line_montant_hors_taxes', 'order_line_type_reduction', 'order_line_type_valeur', 'order_line_montant_reduction', 'order_header_ref_interne',
|
||||
'order_line_comment', 'order_header_id', 'valide', 'locked', 'date_update', 'partner_owner_recid', 'invoice_header_ref_interne', 'invoice_line_type',
|
||||
'invoice_date', 'invoice_header_id']
|
||||
|
||||
|
||||
# PreRemplir les champs
|
||||
for val in list_partner_invoice_line_champ:
|
||||
partner_invoice_line_data[str(val)] = ""
|
||||
|
||||
nb_participant_du_client = len(tab_apprenant)
|
||||
|
||||
nom_prenom_email_participant = ""
|
||||
for val in tab_apprenant:
|
||||
local_apprenant = MYSY_GV.dbname['apprenant'].find_one({'_id':ObjectId(val), 'partner_owner_recid':str(my_partner['recid']),
|
||||
'valide':'1', 'locked':'0'})
|
||||
|
||||
local_nom = ""
|
||||
local_prenom = ""
|
||||
local_email = ""
|
||||
if( "nom" in local_apprenant.keys() ):
|
||||
local_nom = local_apprenant['nom']
|
||||
|
||||
if ("prenom" in local_apprenant.keys()):
|
||||
local_prenom = local_apprenant['prenom']
|
||||
|
||||
if ("email" in local_apprenant.keys()):
|
||||
local_email = local_apprenant['email']
|
||||
|
||||
nom_prenom_email_participant += local_nom+" "+local_prenom+" "+local_email+"\n"
|
||||
|
||||
partner_invoice_line_data['order_line_formation'] = class_data[0]['internal_url']
|
||||
partner_invoice_line_data['order_line_qty'] = str(nb_participant_du_client)
|
||||
partner_invoice_line_data['order_line_prix_unitaire'] = str(prix_session)
|
||||
partner_invoice_line_data['order_line_montant_hors_taxes'] = str(total_ht)
|
||||
partner_invoice_line_data['order_line_comment'] = str(nom_prenom_email_participant)
|
||||
partner_invoice_line_data['invoice_header_id'] = str(inserted_invoice_id)
|
||||
partner_invoice_line_data['invoice_line_type'] = "facture"
|
||||
partner_invoice_line_data['invoice_header_ref_interne'] = partner_invoice_header_data['invoice_header_ref_interne']
|
||||
partner_invoice_line_data['update_by'] = str(my_partner['_id'])
|
||||
partner_invoice_line_data['valide'] = "1"
|
||||
partner_invoice_line_data['locked'] = "0"
|
||||
partner_invoice_line_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
print(" #### partner_invoice_line_data = ", partner_invoice_line_data)
|
||||
inserted_invoice_id = MYSY_GV.dbname['partner_invoice_line'].insert_one(
|
||||
partner_invoice_line_data).inserted_id
|
||||
if (not inserted_invoice_id):
|
||||
mycommon.myprint(" Facture : Impossible de créer les lignes de la facture "+str(partner_invoice_header_data['invoice_header_ref_interne']))
|
||||
return False, " Facture : Impossible de créer les lignes de la facture "+str(partner_invoice_header_data['invoice_header_ref_interne']), False
|
||||
|
||||
|
||||
return True, "L'email a été correctement envoyé ", str(partner_invoice_header_data['invoice_header_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 d'envoyer la convention par email ", False
|
||||
|
||||
|
|
27
main.py
27
main.py
|
@ -7830,6 +7830,33 @@ def Prepare_and_Send_Facture_From_Session_By_Email():
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API : pour préparer et envoyer les factures en partant d'une session, pour une liste d'inscrit.
|
||||
(la facturation partielle)
|
||||
"""
|
||||
@app.route('/myclass/api/Prepare_and_Send_Facture_From_Session_By_Inscription_Id/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Prepare_and_Send_Facture_From_Session_By_Inscription_Id():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Prepare_and_Send_Facture_From_Session_By_Inscription_Id : payload = ",str(payload))
|
||||
|
||||
file = []
|
||||
if request.method == 'POST':
|
||||
# Create variable for uploaded file
|
||||
tab_files = []
|
||||
for tmp in request.files.getlist("File"):
|
||||
tab_files.append(tmp)
|
||||
|
||||
status, retval, invoice_ref = SF.Prepare_and_Send_Facture_From_Session_By_Inscription_Id(tab_files, MYSY_GV.TEMPORARY_DIRECTORY_V2, payload)
|
||||
return jsonify(status=status, message=retval, invoice_ref=invoice_ref)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API: Ajout d'une condition de paiement
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue