parent
5d61594ba5
commit
bf8537646c
|
|
@ -4,16 +4,12 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="30/01/2026 - 18h">
|
||||
<change afterPath="$PROJECT_DIR$/tools_cherif/check_domain_certif_v2.py" afterDir="false" />
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="02/02/2026 - 18h">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.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$/ela_user_account.py" beforeDir="false" afterPath="$PROJECT_DIR$/ela_user_account.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/email_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_invoice.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_invoice.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_order.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_order.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
@ -456,7 +452,7 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1747251650255</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="526" />
|
||||
<option name="localTasksCounter" value="527" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
|
@ -498,7 +494,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="14/10/2025 - 23h" />
|
||||
<MESSAGE value="19/10/2025 - 14h" />
|
||||
<MESSAGE value="20/10/2025 - 14h" />
|
||||
<MESSAGE value="20/10/2025 - 14hsd" />
|
||||
|
|
@ -523,6 +518,7 @@
|
|||
<MESSAGE value="04/01/26 - 21h30" />
|
||||
<MESSAGE value="09/01/26 - 20h30" />
|
||||
<MESSAGE value="30/01/2026 - 18h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="30/01/2026 - 18h" />
|
||||
<MESSAGE value="02/02/2026 - 18h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="02/02/2026 - 18h" />
|
||||
</component>
|
||||
</project>
|
||||
2801
Log/log_file.log
2801
Log/log_file.log
File diff suppressed because one or more lines are too long
14
main.py
14
main.py
|
|
@ -7306,6 +7306,20 @@ def Invoice_Partner_Order():
|
|||
status, retval, invoice_id = partner_invoice.Invoice_Partner_Order(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API de facturation des DEVIS d'un partenaire
|
||||
"""
|
||||
|
||||
@app.route('/myclass/api/Invoice_Partner_Quotation/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Invoice_Partner_Quotation():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Invoice_Partner_Quotation payload = ",payload)
|
||||
status, retval, invoice_id = partner_invoice.Invoice_Partner_Quotation(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
# --------------
|
||||
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -583,6 +583,564 @@ def Invoice_Partner_Order(diction):
|
|||
return False, " Impossible de facturer la commande ", False
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permet de facturer un devis
|
||||
"""
|
||||
|
||||
|
||||
def Invoice_Partner_Quotation(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'order_id', 'order_ref_interne']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||
return False, " Les informations fournies sont incorrectes", False
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'order_id', 'order_ref_interne']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
||||
return False, " Les informations fournies sont incorrectes", False
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner, False
|
||||
|
||||
# Verification de la validité du devis à facturer
|
||||
order_to_invoice_data_count = MYSY_GV.dbname['partner_order_header'].count_documents(
|
||||
{'_id': ObjectId(str(diction['order_id'])), 'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner['recid'], 'order_header_type': 'devis', 'valide': '1',
|
||||
'locked': '0'})
|
||||
|
||||
if (order_to_invoice_data_count < 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - Les references du devis sont invalides ")
|
||||
return False, " Les references du devis sont invalides", False
|
||||
|
||||
if (order_to_invoice_data_count > 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Les references correspondent à plusieurs commandes. Facturation annulée. ")
|
||||
return False, " Les references correspondent à plusieurs commandes. Facturation annulée.", False
|
||||
|
||||
order_to_invoice_data = MYSY_GV.dbname['partner_order_header'].find_one(
|
||||
{'_id': ObjectId(str(diction['order_id'])), 'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner['recid'], 'valide': '1',
|
||||
'locked': '0', 'order_header_type': 'devis'})
|
||||
|
||||
print(" #### order_to_invoice_data = ", order_to_invoice_data);
|
||||
if (order_to_invoice_data is None or str(order_to_invoice_data['order_header_status']) not in ['1', '3'] ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Le devis n'est pas au statut 'Confirmé' ou 'Gagné'. Facturation annulée. ")
|
||||
return False, " Le devis n'est pas au statut 'Confirmé' ou 'Gagné'. Facturation annulée.", False
|
||||
|
||||
# Verifier que toutes lignes sont au statut 'traité'
|
||||
nb_line_a_facturer = 0
|
||||
for order_lines_to_invoice_data in MYSY_GV.dbname['partner_order_line'].find(
|
||||
{'order_header_id': str(diction['order_id']),
|
||||
'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner['recid']}):
|
||||
nb_line_a_facturer = nb_line_a_facturer + 1
|
||||
if (str(order_lines_to_invoice_data['order_line_type']) != "devis" or str(
|
||||
order_lines_to_invoice_data['order_line_status']) not in ["1", "3"]
|
||||
or str(order_lines_to_invoice_data['valide']) != "1" or str(
|
||||
order_lines_to_invoice_data['locked']) != "0"):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - La ligne de commande " + str(
|
||||
order_lines_to_invoice_data['order_line_formation']) + " avec la Quantité " + str(
|
||||
order_lines_to_invoice_data['order_line_qty']) + " n'est pas cohérente. Facturation annulée. ")
|
||||
return False, " La ligne de commande " + str(
|
||||
order_lines_to_invoice_data['order_line_formation']) + " avec la Quantité " + str(
|
||||
order_lines_to_invoice_data['order_line_qty']) + " n'est pas cohérente. Facturation annulée.", False
|
||||
|
||||
if (nb_line_a_facturer == 0):
|
||||
# Alors il n'y a aucune ligne à facturer
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Il n'y a aucune ligne à facturer. Facturation annulée. ")
|
||||
return False, "Il n'y a aucune ligne à facturer. Facturation annulée.", False
|
||||
|
||||
# Verification de la validité du client
|
||||
is_client_valide = MYSY_GV.dbname['partner_client'].count_documents(
|
||||
{'_id': ObjectId(str(order_to_invoice_data['order_header_client_id'])),
|
||||
'valide': '1', 'locked': '0', 'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (is_client_valide != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Le client à facturer est invalide. Facturation annulée. ")
|
||||
return False, "Le client à facturer est invalide. Facturation annulée.", False
|
||||
|
||||
"""
|
||||
A présent la commande est valide, on va
|
||||
0 - Mettre à jour la commande en mettant le statut "facturé' ==> comme ca on bloque d'evenuelles modification de la commande
|
||||
1 - Relancer un compute de la commande
|
||||
2 - copier les données dans la collection 'facture'
|
||||
3 - on met à jour les lignes de la commande, pr la mettre à facturé
|
||||
"""
|
||||
|
||||
# 0 - Mettre à jour la commande en mettant le statut "facturé' ==> comme ca on bloque d'evenuelles modification de la commande
|
||||
order_updated = MYSY_GV.dbname['partner_order_header'].update_one(
|
||||
{'_id': ObjectId(str(diction['order_id'])), 'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner['recid'], 'valide': '1',
|
||||
'locked': '0', 'order_header_type': 'devis'},
|
||||
{'$set': {'order_header_status': '5'}
|
||||
}
|
||||
)
|
||||
|
||||
if (order_updated.modified_count != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Impossible de verrouiller la commande à facturer. Facturation annulée. ")
|
||||
return False, "Impossible de verrouiller la commande à facturer. Facturation annulée.", False
|
||||
|
||||
# 1 - Relancer un compute de la commande
|
||||
comput_diction = {}
|
||||
comput_diction['token'] = diction['token']
|
||||
comput_diction['_id'] = diction['order_id']
|
||||
|
||||
local_retval, local_message = partner_order.Compute_Order_Header(comput_diction)
|
||||
if (local_retval is False):
|
||||
order_updated = MYSY_GV.dbname['partner_order_header'].update_one({{'_id': ObjectId(
|
||||
str(diction['order_id'])), 'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner[
|
||||
'recid'], 'valide': '1',
|
||||
'locked': '0',
|
||||
'order_header_type': 'devis'},
|
||||
{'$set': {'order_header_status': '1'}}
|
||||
})
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Impossible de mettre à jour les prix de la commande à facturer. Facturation annulée. ")
|
||||
return False, "Impossible de mettre à jour les prix de la commande à facturer. Facturation annulée.", False
|
||||
|
||||
# 2 - copier les données dans la collection 'facture'
|
||||
"""
|
||||
Important : On va recopier les header et line, tel quel.
|
||||
On fera les changements plus tard si besoin
|
||||
"""
|
||||
|
||||
# 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(
|
||||
{'related_mysy_object': 'partner_invoice_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.
|
||||
order_updated = MYSY_GV.dbname['partner_order_header'].update_one({{'_id': ObjectId(
|
||||
str(diction['order_id'])), 'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner[
|
||||
'recid'], 'valide': '1',
|
||||
'locked': '0',
|
||||
'order_header_type': 'devis'},
|
||||
{'$set': {'order_header_status': '1'}}
|
||||
})
|
||||
|
||||
mycommon.myprint(" Impossible de récupérer la sequence 'retval_sequence_invoice' ")
|
||||
return False, "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"))
|
||||
new_invoice_data_header = MYSY_GV.dbname['partner_order_header'].find_one(
|
||||
{'_id': ObjectId(str(diction['order_id'])), 'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner['recid'], 'valide': '1',
|
||||
'locked': '0', 'order_header_type': 'devis'},
|
||||
{'_id': 0, 'order_header_type': 0, 'order_header_status': 0})
|
||||
|
||||
print(" #### A COPIER new_invoice_data_header = ", str(new_invoice_data_header))
|
||||
|
||||
invoice_ref_interne = retval_sequence_invoice['prefixe'] + str(current_seq_value)
|
||||
new_invoice_data_header['invoice_header_ref_interne'] = invoice_ref_interne
|
||||
new_invoice_data_header['invoice_header_type'] = "facture"
|
||||
new_invoice_data_header['invoice_date'] = invoice_date_time
|
||||
new_invoice_data_header['update_by'] = str(my_partner['_id'])
|
||||
|
||||
"""
|
||||
Calcul de la date d'échance de la facture :
|
||||
Si pas de conidtion de paiement, alors la date à la date du jour
|
||||
"""
|
||||
if ("order_header_condition_paiement_id" in new_invoice_data_header.keys() and
|
||||
new_invoice_data_header['order_header_condition_paiement_id']):
|
||||
paiement_condition_data = MYSY_GV.dbname['base_partner_paiement_condition'].find_one(
|
||||
{'partner_owner_recid': str(my_partner['recid']),
|
||||
'_id': ObjectId(str(new_invoice_data_header['order_header_condition_paiement_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0'})
|
||||
|
||||
if (paiement_condition_data is None or 'depart' not in paiement_condition_data.keys() or
|
||||
'nb_jour' not in paiement_condition_data.keys()):
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " WARNING - DATE ECHEANCE : Condition de paiement invalide pour calculer la date d'échéance ")
|
||||
|
||||
if (paiement_condition_data['depart'] not in MYSY_GV.PAIEMENT_CONDITION_DEPART):
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " WARNING - DATE ECHEANCE : Condition de départ n'est pas dans la liste " + str(
|
||||
MYSY_GV.PAIEMENT_CONDITION_DEPART))
|
||||
|
||||
nb_jour_int = mycommon.tryInt(str(paiement_condition_data['nb_jour']))
|
||||
today = datetime.today()
|
||||
date_echance = datetime.today()
|
||||
|
||||
if (str(paiement_condition_data['depart']) == "mois"):
|
||||
days_in_month = lambda dt: monthrange(dt.year, dt.month)[1]
|
||||
first_day_next_month = today.replace(day=1) + timedelta(days_in_month(today))
|
||||
date_echance = first_day_next_month + timedelta(days=nb_jour_int)
|
||||
|
||||
if (str(paiement_condition_data['depart']) == "facture"):
|
||||
date_echance = today + timedelta(days=nb_jour_int)
|
||||
|
||||
date_echance = date_echance.strftime("%d/%m/%Y")
|
||||
new_invoice_data_header['invoice_date_echeance'] = str(date_echance)
|
||||
new_invoice_data_header['order_header_condition_paiement_code'] = str(paiement_condition_data['code'])
|
||||
new_invoice_data_header['order_header_condition_paiement_description'] = str(
|
||||
paiement_condition_data['description'])
|
||||
|
||||
else:
|
||||
today = datetime.today()
|
||||
date_echance = datetime.today().strftime("%d/%m/%Y")
|
||||
new_invoice_data_header['invoice_date_echeance'] = str(date_echance)
|
||||
new_invoice_data_header['order_header_condition_paiement_code'] = ""
|
||||
new_invoice_data_header['order_header_condition_paiement_description'] = ""
|
||||
|
||||
inserted_invoice_id = MYSY_GV.dbname['partner_invoice_header'].insert_one(new_invoice_data_header).inserted_id
|
||||
if (not inserted_invoice_id):
|
||||
order_updated = MYSY_GV.dbname['partner_order_header'].update_one({{'_id': ObjectId(
|
||||
str(diction['order_id'])), 'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner[
|
||||
'recid'], 'valide': '1',
|
||||
'locked': '0',
|
||||
'order_header_type': 'devis'},
|
||||
{'$set': {'order_header_status': '5', 'invoice_header_ref_interne':str(new_invoice_data_header['invoice_header_ref_interne'])}}
|
||||
})
|
||||
mycommon.myprint(
|
||||
" Impossible de créer l'entete de la facture ")
|
||||
return False, "Impossible de créer l'entete de la facture ", False
|
||||
|
||||
tab_session_3001 = []
|
||||
|
||||
for new_invoice_data_line in MYSY_GV.dbname['partner_order_line'].find(
|
||||
{'order_header_id': str(diction['order_id']),
|
||||
'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner['recid']}, {'_id': 0, 'order_line_type': 0, 'order_line_status': 0,
|
||||
}):
|
||||
new_invoice_data_line['invoice_header_ref_interne'] = retval_sequence_invoice['prefixe'] + str(
|
||||
current_seq_value)
|
||||
new_invoice_data_line['invoice_line_type'] = "facture"
|
||||
new_invoice_data_line['invoice_date'] = invoice_date_time
|
||||
new_invoice_data_line['invoice_header_id'] = str(inserted_invoice_id)
|
||||
new_invoice_data_line['update_by'] = str(my_partner['_id'])
|
||||
|
||||
if ("order_line_session_id" in new_invoice_data_line.keys() and new_invoice_data_line[
|
||||
'order_line_session_id']):
|
||||
tab_session_3001.append(str(new_invoice_data_line['order_line_session_id']))
|
||||
|
||||
work_tab = []
|
||||
if ("order_line_tab_inscrit_id" in new_invoice_data_line.keys()):
|
||||
for tmp in new_invoice_data_line['order_line_tab_inscrit_id']:
|
||||
if ("_id" in tmp.keys() and tmp['_id']):
|
||||
work_tab.append(ObjectId(str(tmp['_id'])))
|
||||
|
||||
del new_invoice_data_line['order_line_tab_inscrit_id']
|
||||
|
||||
new_invoice_data_line['tab_inscription_ids'] = work_tab
|
||||
|
||||
# print(" ### on Va inserer la ligne de factue new_invoice_data_line = ", new_invoice_data_line)
|
||||
|
||||
inserted_line = MYSY_GV.dbname['partner_invoice_line'].insert_one(new_invoice_data_line)
|
||||
|
||||
# print(" ### inserted_line de la ligne inserée = ", inserted_line)
|
||||
|
||||
inserted_line_id = inserted_line.inserted_id
|
||||
|
||||
# print(" ### inserted_line_id de la ligne inserée = ", inserted_line_id)
|
||||
|
||||
if (not inserted_line_id):
|
||||
# Vu quil y a un souci avec l'une des lignes, on fait un roll back complet de la facturation
|
||||
order_updated = MYSY_GV.dbname['partner_order_header'].update_one({{'_id': ObjectId(
|
||||
str(diction['order_id'])), 'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner[
|
||||
'recid'], 'valide': '1',
|
||||
'locked': '0',
|
||||
'order_header_type': 'devis'},
|
||||
{'$set': {'order_header_status': '2', 'invoice_header_ref_interne':''}}
|
||||
})
|
||||
|
||||
MYSY_GV.dbname['partner_invoice_header'].delete_one({'_id': ObjectId(str(str(inserted_invoice_id)))})
|
||||
MYSY_GV.dbname['partner_invoice_line'].delete_many(
|
||||
{'invoice_header_id': ObjectId(str(str(inserted_invoice_id)))})
|
||||
|
||||
mycommon.myprint(
|
||||
" Impossible de finaliser la facturation des lignes de la ligne la commande ")
|
||||
return False, " Impossible de finaliser la facturation des lignes de la ligne la commande. ", False
|
||||
|
||||
"""
|
||||
04/10/2024 - update pour faire le BPF
|
||||
|
||||
on va créer une table de detail qui reprend le detail des inscription
|
||||
"""
|
||||
"""
|
||||
09/01/2026 - si on a des inscrits idenifié - new_invoice_data_line['tab_inscription_ids'] = work_tab
|
||||
Alors on va aller recuperer les données de l'inscrits
|
||||
"""
|
||||
if (len(work_tab) > 0):
|
||||
for inscrit in work_tab:
|
||||
inscrit_data = MYSY_GV.dbname['inscription'].find_one(
|
||||
{'_id': ObjectId(str(inscrit)), 'partner_owner_recid': my_partner['recid']})
|
||||
partner_invoice_line_data_detail = {}
|
||||
partner_invoice_line_data_detail['order_line_inscription_id'] = str(inscrit_data['_id'])
|
||||
partner_invoice_line_data_detail['order_line_inscription_type_apprenant'] = str(
|
||||
inscrit_data['type_apprenant'])
|
||||
partner_invoice_line_data_detail['order_line_inscription_modefinancement'] = str(
|
||||
inscrit_data['modefinancement'])
|
||||
partner_invoice_line_data_detail['order_line_formation'] = str(
|
||||
new_invoice_data_line['order_line_formation'])
|
||||
|
||||
"""
|
||||
27/07/25 : aller recuperer le 'class_id'
|
||||
"""
|
||||
local_class_id = ""
|
||||
if ("order_line_formation" in new_invoice_data_line.keys() and new_invoice_data_line[
|
||||
'order_line_formation']):
|
||||
class_data = MYSY_GV.dbname['myclass'].find_one(
|
||||
{'internal_url': str(new_invoice_data_line['order_line_formation']),
|
||||
'partner_owner_recid': str(my_partner['recid'])}, {'_id': 1})
|
||||
|
||||
if (class_data and '_id' in class_data.keys()):
|
||||
local_class_id = str(class_data['_id'])
|
||||
|
||||
partner_invoice_line_data_detail['order_line_class_id'] = local_class_id
|
||||
|
||||
partner_invoice_line_data_detail['order_line_prix_unitaire'] = str(inscrit_data['price'])
|
||||
partner_invoice_line_data_detail['order_line_montant_hors_taxes'] = str(
|
||||
new_invoice_data_line['order_line_montant_hors_taxes'])
|
||||
partner_invoice_line_data_detail['order_line_invoiced_amount'] = str(
|
||||
new_invoice_data_line['order_line_montant_hors_taxes'])
|
||||
partner_invoice_line_data_detail['order_line_qty'] = "1"
|
||||
|
||||
if ("order_line_tab_inscrit_id" in new_invoice_data_line.keys()):
|
||||
del new_invoice_data_line['order_line_tab_inscrit_id']
|
||||
|
||||
partner_invoice_line_data_detail['tab_inscription_ids'] = [ObjectId(str(inscrit_data['_id']))]
|
||||
|
||||
partner_invoice_line_data_detail['order_line_comment'] = ""
|
||||
partner_invoice_line_data_detail['invoice_header_id'] = str(inserted_invoice_id)
|
||||
partner_invoice_line_data_detail['invoice_line_type'] = "facture"
|
||||
partner_invoice_line_data_detail['invoice_header_ref_interne'] = str(invoice_ref_interne)
|
||||
|
||||
order_line_is_include_bpf = ""
|
||||
if ("order_header_inclus_bpf" in order_to_invoice_data.keys()):
|
||||
order_line_is_include_bpf = order_to_invoice_data['order_header_inclus_bpf']
|
||||
partner_invoice_line_data_detail['order_line_is_include_bpf'] = order_line_is_include_bpf
|
||||
|
||||
partner_invoice_line_data_detail['update_by'] = str(my_partner['_id'])
|
||||
partner_invoice_line_data_detail['valide'] = "1"
|
||||
partner_invoice_line_data_detail['locked'] = "0"
|
||||
partner_invoice_line_data_detail['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
print(" #### partner_invoice_line_data = ", partner_invoice_line_data_detail)
|
||||
inserted_detail_invoice_line_id = MYSY_GV.dbname['partner_invoice_line_detail'].insert_one(
|
||||
partner_invoice_line_data_detail).inserted_id
|
||||
|
||||
else:
|
||||
partner_invoice_line_data_detail = {}
|
||||
partner_invoice_line_data_detail['order_line_inscription_id'] = ""
|
||||
partner_invoice_line_data_detail['order_line_inscription_type_apprenant'] = str(
|
||||
new_invoice_data_line['order_line_type_apprenant'])
|
||||
partner_invoice_line_data_detail['order_line_inscription_modefinancement'] = ""
|
||||
partner_invoice_line_data_detail['order_line_formation'] = str(
|
||||
new_invoice_data_line['order_line_formation'])
|
||||
|
||||
"""
|
||||
27/07/25 : aller recuperer le 'class_id'
|
||||
"""
|
||||
local_class_id = ""
|
||||
if ("order_line_formation" in new_invoice_data_line.keys() and new_invoice_data_line[
|
||||
'order_line_formation']):
|
||||
class_data = MYSY_GV.dbname['myclass'].find_one(
|
||||
{'internal_url': str(new_invoice_data_line['order_line_formation']),
|
||||
'partner_owner_recid': str(my_partner['recid'])}, {'_id': 1})
|
||||
|
||||
if (class_data and '_id' in class_data.keys()):
|
||||
local_class_id = str(class_data['_id'])
|
||||
|
||||
partner_invoice_line_data_detail['order_line_class_id'] = local_class_id
|
||||
|
||||
partner_invoice_line_data_detail['order_line_prix_unitaire'] = str(
|
||||
new_invoice_data_line['order_line_prix_unitaire'])
|
||||
partner_invoice_line_data_detail['order_line_montant_hors_taxes'] = str(
|
||||
new_invoice_data_line['order_line_montant_hors_taxes'])
|
||||
partner_invoice_line_data_detail['order_line_invoiced_amount'] = str(
|
||||
new_invoice_data_line['order_line_montant_hors_taxes'])
|
||||
partner_invoice_line_data_detail['order_line_qty'] = str(new_invoice_data_line['order_line_qty'])
|
||||
|
||||
if ("order_line_tab_inscrit_id" in new_invoice_data_line.keys()):
|
||||
del new_invoice_data_line['order_line_tab_inscrit_id']
|
||||
|
||||
partner_invoice_line_data_detail['tab_inscription_ids'] = work_tab
|
||||
|
||||
partner_invoice_line_data_detail['order_line_comment'] = ""
|
||||
partner_invoice_line_data_detail['invoice_header_id'] = str(inserted_invoice_id)
|
||||
partner_invoice_line_data_detail['invoice_line_type'] = "facture"
|
||||
partner_invoice_line_data_detail['invoice_header_ref_interne'] = str(invoice_ref_interne)
|
||||
|
||||
order_line_is_include_bpf = ""
|
||||
if ("order_header_inclus_bpf" in order_to_invoice_data.keys()):
|
||||
order_line_is_include_bpf = order_to_invoice_data['order_header_inclus_bpf']
|
||||
partner_invoice_line_data_detail['order_line_is_include_bpf'] = order_line_is_include_bpf
|
||||
|
||||
partner_invoice_line_data_detail['update_by'] = str(my_partner['_id'])
|
||||
partner_invoice_line_data_detail['valide'] = "1"
|
||||
partner_invoice_line_data_detail['locked'] = "0"
|
||||
partner_invoice_line_data_detail['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
print(" #### partner_invoice_line_data = ", partner_invoice_line_data_detail)
|
||||
inserted_detail_invoice_line_id = MYSY_GV.dbname['partner_invoice_line_detail'].insert_one(
|
||||
partner_invoice_line_data_detail).inserted_id
|
||||
|
||||
# 3 - on met à jour les lignes de la commande, pr la mettre à facturé
|
||||
qry = {'order_header_id': str(diction['order_id']),
|
||||
'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner['recid'], 'valide': '1',
|
||||
'locked': '0', 'order_header_type': 'devis'}
|
||||
|
||||
# print(" #### qry = ", qry)
|
||||
|
||||
order_updated = MYSY_GV.dbname['partner_order_line'].update_many(
|
||||
{'order_header_id': str(diction['order_id']), 'order_header_ref_interne': str(diction['order_ref_interne']),
|
||||
'partner_owner_recid': my_partner['recid'], 'valide': '1',
|
||||
'locked': '0', 'order_line_type': 'devis'},
|
||||
{'$set': {'order_line_status': '5'}}
|
||||
)
|
||||
|
||||
if (order_updated.modified_count <= 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " WARNING - Impossible de mettre les lignes à facturer pour order_header_id = " + str(
|
||||
str(diction['order_id'])))
|
||||
|
||||
"""
|
||||
05/06/2024 Gestion E-Facture
|
||||
Apres la creation de la facture, on va aller créer le document securisé
|
||||
"""
|
||||
e_Invoice_Diction = {}
|
||||
e_Invoice_Diction['token'] = diction['token']
|
||||
e_Invoice_Diction['invoice_id'] = str(inserted_invoice_id)
|
||||
|
||||
local_E_Invoice_status, local_E_Invoice_retval = Session_Formation.Invoice_Create_Secure_E_Document(
|
||||
e_Invoice_Diction)
|
||||
if (local_E_Invoice_status is False):
|
||||
return True, "WARNING : La facture a été créée avec la réf. " + str(new_invoice_data_header[
|
||||
'invoice_header_ref_interne']) + "; mais impossible de créer la e-Facture Sécurisée (1).", str(
|
||||
new_invoice_data_header['invoice_header_ref_interne'])
|
||||
|
||||
"""
|
||||
30/01/2026 -
|
||||
Après avoir créer la facture, on va aller mettre à jour les EVENTUELLE Session concernée avec les clients concernés.
|
||||
C'est a dire, si le client facturé à des apprenants dans la session, je vais aller dire qu'ils sont facturés
|
||||
|
||||
les lignes sont facturés, je vais juste le num de facture comme ca depuis la session, on vera qu'il y a 2 facturer.
|
||||
"""
|
||||
|
||||
if ("order_header_client_id" in new_invoice_data_header.keys() and new_invoice_data_header[
|
||||
'order_header_client_id']
|
||||
and "invoice_header_ref_interne" in new_invoice_data_header.keys() and new_invoice_data_header[
|
||||
'invoice_header_ref_interne']
|
||||
and "invoice_date" in new_invoice_data_header.keys() and new_invoice_data_header['invoice_date']):
|
||||
now = str(datetime.now())
|
||||
update_data = {}
|
||||
update_data['invoiced'] = "1"
|
||||
update_data['invoiced_ref'] = str(new_invoice_data_header['invoice_header_ref_interne'])
|
||||
update_data['invoiced_date'] = new_invoice_data_header['invoice_date']
|
||||
update_data['date_update'] = str(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': {'$in': tab_session_3001},
|
||||
'facture_client_rattachement_id': str(
|
||||
new_invoice_data_header['order_header_client_id']),
|
||||
},
|
||||
{'$set': update_data})
|
||||
|
||||
"""
|
||||
Ajout l'action dans l'historique
|
||||
"""
|
||||
## Add to log history pour la facture
|
||||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||||
history_event_dict = {}
|
||||
history_event_dict['token'] = diction['token']
|
||||
history_event_dict['related_collection'] = "partner_invoice_header"
|
||||
history_event_dict['related_collection_recid'] = str(inserted_invoice_id)
|
||||
history_event_dict['action_date'] = str(now)
|
||||
history_event_dict['action_description'] = "Creation facture"
|
||||
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
||||
|
||||
## Add to log history pour la commande
|
||||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||||
history_event_dict = {}
|
||||
history_event_dict['token'] = diction['token']
|
||||
history_event_dict['related_collection'] = "partner_order_header"
|
||||
history_event_dict['related_collection_recid'] = str(diction['order_id'])
|
||||
history_event_dict['action_date'] = str(now)
|
||||
history_event_dict['action_description'] = "Facturé. Ref. Facture :" + str(
|
||||
new_invoice_data_header['invoice_header_ref_interne'])
|
||||
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
||||
|
||||
return True, " Le devis a été correctement facturée", str(
|
||||
new_invoice_data_header['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 de facturer le devis ", False
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Recuperation d'une facture donnée
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -2859,7 +2859,20 @@ def Confirm_Partner_Order_Header_And_Lines(diction):
|
|||
if (my_order_data_count != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - L'identifiant de la commande est invalide ")
|
||||
return False, " L'identifiant de la commande est invalide",
|
||||
return False, " L'identifiant du devis est invalide",
|
||||
|
||||
"""
|
||||
Verifier qu'il y a des ligne pour cette commande / devis
|
||||
"""
|
||||
my_order_line_data_count = MYSY_GV.dbname['partner_order_line'].count_documents(
|
||||
{'partner_owner_recid': str(my_partner['recid']),
|
||||
'valide': '1', 'locked': '0',
|
||||
'order_header_id': str(order_header_id)})
|
||||
|
||||
if (my_order_line_data_count <= 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - Aucune ligne pour ce devis ")
|
||||
return False, " Aucune ligne pour ce devis",
|
||||
|
||||
"""
|
||||
Recuperation et stockage des données de l'entete avant mise à jour
|
||||
|
|
|
|||
Loading…
Reference in New Issue