08/05/2024 - 17h30
parent
98dc4e4ddb
commit
5b3892029e
|
@ -1,12 +1,15 @@
|
|||
<?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="06/05/2024 - 22h30">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="07/05/2024 - 17h30">
|
||||
<change afterPath="$PROJECT_DIR$/invoice_paiement_mgt.py" afterDir="false" />
|
||||
<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$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" 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$/class_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/class_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/metier_formation_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/metier_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" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -76,13 +79,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00239" summary="ddd">
|
||||
<created>1710064628260</created>
|
||||
<option name="number" value="00239" />
|
||||
<option name="presentableId" value="LOCAL-00239" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1710064628261</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00240" summary="ddds">
|
||||
<created>1710078593828</created>
|
||||
<option name="number" value="00240" />
|
||||
|
@ -419,7 +415,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1715027674052</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="288" />
|
||||
<task id="LOCAL-00288" summary="07/05/2024 - 17h30">
|
||||
<created>1715096332563</created>
|
||||
<option name="number" value="00288" />
|
||||
<option name="presentableId" value="LOCAL-00288" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1715096332563</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="289" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -461,7 +464,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="07/04/2024 - 19h19" />
|
||||
<MESSAGE value="09/04/2024 - 15h19" />
|
||||
<MESSAGE value="09/04/2024 - 23h50" />
|
||||
<MESSAGE value="10/04/2024 - 11h50" />
|
||||
|
@ -486,6 +488,7 @@
|
|||
<MESSAGE value="05/05/2024 - 13h30" />
|
||||
<MESSAGE value="05/05/2024 - 17h30" />
|
||||
<MESSAGE value="06/05/2024 - 22h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="06/05/2024 - 22h30" />
|
||||
<MESSAGE value="07/05/2024 - 17h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="07/05/2024 - 17h30" />
|
||||
</component>
|
||||
</project>
|
|
@ -705,4 +705,13 @@ Une enquete a les statuts suivants :
|
|||
2 - repondu
|
||||
-1 - annulé
|
||||
"""
|
||||
SURVEY_STATUS = ['-1', '0', '1', '2']
|
||||
SURVEY_STATUS = ['-1', '0', '1', '2']
|
||||
|
||||
|
||||
"""
|
||||
Statut de paiement des factures
|
||||
0 - aucun regelement
|
||||
1 - partiellement payé
|
||||
2 - entièrement payé
|
||||
"""
|
||||
INVOICE_PAIEMENT_STATUS = ['0', '1', '2']
|
2659
Log/log_file.log
2659
Log/log_file.log
File diff suppressed because it is too large
Load Diff
|
@ -116,6 +116,11 @@ def Add_Class_Categorie(diction):
|
|||
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"
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
125
main.py
125
main.py
|
@ -85,6 +85,7 @@ import unite_enseignement_mgt as unite_enseignement_mgt
|
|||
import metier_formation_mgt as metier_formation_mgt
|
||||
import categorie_formation_mgt as categorie_formation_mgt
|
||||
import domaine_formation_mgt as domaine_formation_mgt
|
||||
import invoice_paiement_mgt as invoice_paiement_mgt
|
||||
|
||||
app = Flask(__name__)
|
||||
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
|
||||
|
@ -8628,6 +8629,35 @@ def Compute_Invoice_Order_Data():
|
|||
status, retval = partner_invoice.Compute_Invoice_Order_Data(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API permet d'ajouter une annotation à une facture
|
||||
"""
|
||||
@app.route('/myclass/api/Add_Update_Invoice_Annotation/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Add_Update_Invoice_Annotation():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Add_Update_Invoice_Annotation payload = ",payload)
|
||||
status, retval = partner_invoice.Add_Update_Invoice_Annotation(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API permet de créer un avoir TOTAL sur une facture
|
||||
"""
|
||||
@app.route('/myclass/api/Create_Invoice_Avoir_Total/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Create_Invoice_Avoir_Total():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Create_Invoice_Avoir_Total payload = ",payload)
|
||||
status, retval , list_credit_note = partner_invoice.Create_Invoice_Avoir_Total(payload)
|
||||
return jsonify(status=status, message=retval, list_credit_note = list_credit_note)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API pour ajouter / mettre à jour une unité d'enseignement (UE) à une formation
|
||||
"""
|
||||
|
@ -9004,6 +9034,101 @@ def Get_Given_Class_domaine():
|
|||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour Ajoute un paiement d'une facture
|
||||
"""
|
||||
@app.route('/myclass/api/Add_Invoice_Paiement/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Add_Invoice_Paiement():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Add_Invoice_Paiement payload = ",payload)
|
||||
status, retval = invoice_paiement_mgt.Add_Invoice_Paiement(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour mettre à jour un paiement d'une facture
|
||||
"""
|
||||
@app.route('/myclass/api/Update_Invoice_Paiement/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Update_Invoice_Paiement():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Update_Invoice_Paiement payload = ",payload)
|
||||
status, retval = invoice_paiement_mgt.Update_Invoice_Paiement(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour la liste des paiement d'une facture avec le montant total
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Invoice_Liste_Payement_And_Total_Amount/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Invoice_Liste_Payement_And_Total_Amount():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Invoice_Liste_Payement_And_Total_Amount payload = ",payload)
|
||||
status, retval = invoice_paiement_mgt.Get_Invoice_Liste_Payement_And_Total_Amount(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API pour recuperer le total payé et le total non payé sur une facture
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Invoice_Total_Amount_Payed_And_Remaining_Amount/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Invoice_Total_Amount_Payed_And_Remaining_Amount():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Invoice_Total_Amount_Payed_And_Remaining_Amount payload = ",payload)
|
||||
status, retval = invoice_paiement_mgt.Get_Invoice_Total_Amount_Payed_And_Remaining_Amount(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API pour la liste des paiement d'une facture
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Invoice_Liste_Payement/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Invoice_Liste_Payement():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Invoice_Liste_Payement payload = ",payload)
|
||||
status, retval = invoice_paiement_mgt.Get_Invoice_Liste_Payement(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour recupérer les données d'un paiement donné
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Given_Invoice_Paiement/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Given_Invoice_Paiement():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Given_Invoice_Paiement payload = ",payload)
|
||||
status, retval = invoice_paiement_mgt.Get_Given_Invoice_Paiement(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour supprimer un paiement donné
|
||||
"""
|
||||
@app.route('/myclass/api/Delete_Given_Invoice_Paiement/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Delete_Given_Invoice_Paiement():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Delete_Given_Invoice_Paiement payload = ",payload)
|
||||
status, retval = invoice_paiement_mgt.Delete_Given_Invoice_Paiement(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
|
|
|
@ -116,6 +116,11 @@ def Add_class_metier(diction):
|
|||
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"
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ from bson import ObjectId
|
|||
import re
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import invoice_paiement_mgt
|
||||
import partners
|
||||
import prj_common as mycommon
|
||||
import secrets
|
||||
|
@ -923,7 +924,7 @@ def Get_List_Partner_Invoice_no_filter(diction):
|
|||
]
|
||||
|
||||
|
||||
print(" ### orders new_myquery_find_invoice = ", new_myquery_find_invoice)
|
||||
#print(" ### orders new_myquery_find_invoice = ", new_myquery_find_invoice)
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
||||
|
@ -976,6 +977,23 @@ def Get_List_Partner_Invoice_no_filter(diction):
|
|||
|
||||
user['order_header_vendeur_nom_prenom'] = str(order_header_vendeur_nom_prenom)
|
||||
|
||||
"""
|
||||
Recuperer le solde (montant restant à payer)
|
||||
"""
|
||||
local_diction = {'token':str(diction['token']), 'invoice_id':str(New_retVal['_id'])}
|
||||
|
||||
reste_to_paye = "0"
|
||||
local_solde_status, local_solde_retval = invoice_paiement_mgt.Get_Invoice_Total_Amount_Payed_And_Remaining_Amount(local_diction)
|
||||
if( local_solde_status ):
|
||||
sold_data = ast.literal_eval(local_solde_retval[0])
|
||||
reste_to_paye = sold_data['remaining_amount']
|
||||
|
||||
user['reste_to_paye'] = reste_to_paye
|
||||
|
||||
if( "credit_note_ref" not in New_retVal.keys() ):
|
||||
user['credit_note_ref'] = ""
|
||||
|
||||
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
return True, RetObject
|
||||
|
@ -1173,6 +1191,23 @@ def Get_List_Partner_Invoice_with_filter(diction):
|
|||
|
||||
user['order_header_vendeur_nom_prenom'] = str(order_header_vendeur_nom_prenom)
|
||||
|
||||
"""
|
||||
Recuperer le solde (montant restant à payer)
|
||||
"""
|
||||
local_diction = {'token': str(diction['token']), 'invoice_id': str(New_retVal['_id'])}
|
||||
|
||||
reste_to_paye = "0"
|
||||
local_solde_status, local_solde_retval = invoice_paiement_mgt.Get_Invoice_Total_Amount_Payed_And_Remaining_Amount(
|
||||
local_diction)
|
||||
if (local_solde_status):
|
||||
sold_data = ast.literal_eval(local_solde_retval[0])
|
||||
reste_to_paye = sold_data['remaining_amount']
|
||||
|
||||
user['reste_to_paye'] = reste_to_paye
|
||||
|
||||
if ("credit_note_ref" not in New_retVal.keys()):
|
||||
user['credit_note_ref'] = ""
|
||||
|
||||
|
||||
if( filter_date_debut and filter_date_fin ):
|
||||
if ( datetime.strptime(str(New_retVal['invoice_date'])[0:10], '%d/%m/%Y') >= datetime.strptime(str(filter_date_debut)[0:10], '%d/%m/%Y') and
|
||||
|
@ -2393,3 +2428,302 @@ def Compute_Invoice_Order_Data(diction):
|
|||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de recalculer les totaux de la facture "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permets ajouter / mettre à jour une annotation
|
||||
sur une facture
|
||||
"""
|
||||
def Add_Update_Invoice_Annotation(diction):
|
||||
try:
|
||||
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', '_id', 'annotation']
|
||||
|
||||
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', 'annotation']
|
||||
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 factre est valide
|
||||
"""
|
||||
is_valide_invoice_cout = MYSY_GV.dbname['partner_invoice_header'].count_documents({'_id':ObjectId(str(diction['_id'])),
|
||||
'partner_owner_recid':my_partner['recid'],
|
||||
'valide':'1',
|
||||
'locked':'0'})
|
||||
|
||||
if( is_valide_invoice_cout <= 0 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'identifiant de la facture est invalide ")
|
||||
return False, " L'identifiant de la facture est invalide ",
|
||||
|
||||
update_data = {}
|
||||
update_data['date_update'] = str(datetime.now())
|
||||
update_data['update_by'] = str(my_partner['_id'])
|
||||
update_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
result = MYSY_GV.dbname['partner_invoice_header'].find_one_and_update(
|
||||
{'_id': ObjectId(str(diction['_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])},
|
||||
{"$set": {"annotation":str(diction['annotation'])}},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
return True, 'La note a été 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 la note"
|
||||
|
||||
|
||||
"""
|
||||
Cette fontion permet de créer un avoir sur la facture.
|
||||
On par d'annulation totale, donc pas partiel
|
||||
|
||||
/!\ : On créer une souche spéciale pour les avoirs
|
||||
|
||||
apres la creation de l'avoir, on va ajouter sur la facture
|
||||
la reference de l'avoir associé
|
||||
|
||||
"""
|
||||
def Create_Invoice_Avoir_Total(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", False
|
||||
|
||||
"""
|
||||
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", False
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner, False
|
||||
|
||||
|
||||
"""
|
||||
Verifier que la factre est valide
|
||||
"""
|
||||
is_valide_invoice_cout = MYSY_GV.dbname['partner_invoice_header'].count_documents({'_id':ObjectId(str(diction['_id'])),
|
||||
'partner_owner_recid':my_partner['recid'],
|
||||
'valide':'1',
|
||||
'locked':'0'})
|
||||
|
||||
if( is_valide_invoice_cout <= 0 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'identifiant de la facture est invalide ")
|
||||
return False, " L'identifiant de la facture est invalide ", False
|
||||
|
||||
|
||||
|
||||
# Récuperation de la sequence de l'objet "partner_credit_note" dans la collection : "mysy_sequence"
|
||||
retval_sequence_credit_note = MYSY_GV.dbname['mysy_sequence'].find_one(
|
||||
{'related_mysy_object': 'partner_credit_note',
|
||||
'valide': '1', 'partner_owner_recid': str(
|
||||
my_partner['recid'])})
|
||||
|
||||
if (retval_sequence_credit_note is None):
|
||||
# Il n'y pas de sequence pour le partenaire, on va aller chercher la sequence par defaut
|
||||
retval_sequence_credit_note = MYSY_GV.dbname['mysy_sequence'].find_one(
|
||||
{'related_mysy_object': 'partner_credit_note',
|
||||
'valide': '1', 'partner_owner_recid': 'default'})
|
||||
|
||||
if (retval_sequence_credit_note is None or "current_val" not in retval_sequence_credit_note.keys()):
|
||||
# Il n'y aucune sequence meme par defaut.
|
||||
|
||||
|
||||
mycommon.myprint(" Aucune sequence de type 'partner_credit_note' n'est configurée dans le système ")
|
||||
return False, " Aucune sequence de type 'partner_credit_note' n'est configurée dans le système ", False
|
||||
|
||||
current_seq_value = str(retval_sequence_credit_note['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_credit_note['_id'])), 'valide': '1'},
|
||||
{"$set": new_sequance_data_to_update},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=False,
|
||||
)
|
||||
|
||||
credit_notes_reference = retval_sequence_credit_note['prefixe'] + str(current_seq_value)
|
||||
invoice_date_time = str(datetime.now().strftime("%d/%m/%Y"))
|
||||
|
||||
local_credit_note = None
|
||||
liste_credit_node = []
|
||||
|
||||
for local_invoice in MYSY_GV.dbname['partner_invoice_header'].find({'_id':ObjectId(str(diction['_id'])),
|
||||
'partner_owner_recid':my_partner['recid'],
|
||||
'valide':'1',
|
||||
'locked':'0'}):
|
||||
|
||||
local_credit_note = local_invoice
|
||||
|
||||
list_champs_a_inverser = ['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']
|
||||
|
||||
for tmp in list_champs_a_inverser :
|
||||
if( tmp in local_credit_note.keys() and local_credit_note[tmp] ):
|
||||
inversed_tmp = mycommon.tryFloat(str(local_credit_note[tmp]).strip()) * (-1)
|
||||
local_credit_note[tmp] = inversed_tmp
|
||||
|
||||
local_credit_note['invoice_header_origin'] = local_invoice['invoice_header_ref_interne']
|
||||
local_credit_note['invoice_header_ref_interne'] = credit_notes_reference
|
||||
local_credit_note['invoice_header_type'] = "avoir"
|
||||
local_credit_note['invoice_date'] = invoice_date_time
|
||||
local_credit_note['date_update'] = str(datetime.now())
|
||||
local_credit_note['update_by'] = str(my_partner['_id'])
|
||||
local_credit_note['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
if( "_id" in local_credit_note.keys() ):
|
||||
del local_credit_note['_id']
|
||||
"""
|
||||
Insertion de l'avoir
|
||||
"""
|
||||
#print(" ### creadit note = ", local_credit_note)
|
||||
|
||||
"""
|
||||
Verifier qu'il n'y pas dans la base un document avec le meme refrence
|
||||
pour ce partenaire
|
||||
"""
|
||||
is_document_exist_count = MYSY_GV.dbname['partner_invoice_header'].count_documents({"invoice_header_ref_interne":credit_notes_reference,
|
||||
"partner_owner_recid":my_partner['recid']})
|
||||
if( is_document_exist_count > 0 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Il existe déjà un document avec la même reference : "+str(credit_notes_reference))
|
||||
return False, " Il existe déjà un document avec la même reference : "+str(credit_notes_reference), False
|
||||
|
||||
inserted_id = MYSY_GV.dbname['partner_invoice_header'].insert_one(local_credit_note).inserted_id
|
||||
if (not inserted_id):
|
||||
mycommon.myprint(
|
||||
" Impossible de créer l'avoir (2) ")
|
||||
return False, "Impossible de créer l'avoir (2) "
|
||||
|
||||
liste_credit_node.append(credit_notes_reference)
|
||||
|
||||
|
||||
"""
|
||||
Mettre à jour la facture avec la reference de l'avoir
|
||||
"""
|
||||
result = MYSY_GV.dbname['partner_invoice_header'].find_one_and_update(
|
||||
{'_id': ObjectId(str(diction['_id'])),
|
||||
'partner_owner_recid': my_partner['recid'],
|
||||
'valide': '1',
|
||||
'locked': '0'},
|
||||
{"$set": {"credit_note_ref":credit_notes_reference}},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
On a finit de créer l'entete, on va aller créer les lignes
|
||||
"""
|
||||
for local_invoice_line in MYSY_GV.dbname['partner_invoice_line'].find({'invoice_header_id': str(diction['_id']),
|
||||
'partner_owner_recid': my_partner['recid'],
|
||||
'valide': '1',
|
||||
'locked': '0'}):
|
||||
|
||||
local_credit_note_line = local_invoice_line
|
||||
|
||||
list_champs_a_inverser = ['order_line_qty', 'order_line_tax_amount',
|
||||
'order_line_montant_toutes_taxes',
|
||||
'order_line_montant_hors_taxes',
|
||||
]
|
||||
|
||||
for tmp in list_champs_a_inverser:
|
||||
if (tmp in local_credit_note_line.keys() and local_credit_note_line[tmp]):
|
||||
inversed_tmp = mycommon.tryFloat(str(local_credit_note_line[tmp]).strip()) * (-1)
|
||||
local_credit_note_line[tmp] = inversed_tmp
|
||||
|
||||
local_credit_note_line['invoice_header_ref_interne_origin'] = local_invoice['invoice_header_ref_interne']
|
||||
local_credit_note_line['invoice_header_ref_interne'] = credit_notes_reference
|
||||
|
||||
local_credit_note_line['invoice_header_id'] = str(inserted_id)
|
||||
local_credit_note_line['invoice_line_type'] = "avoir"
|
||||
|
||||
local_credit_note_line['invoice_date'] = invoice_date_time
|
||||
local_credit_note_line['date_update'] = str(datetime.now())
|
||||
local_credit_note_line['update_by'] = str(my_partner['_id'])
|
||||
local_credit_note_line['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
if ("_id" in local_credit_note_line.keys()):
|
||||
del local_credit_note_line['_id']
|
||||
|
||||
inserted_id = MYSY_GV.dbname['partner_invoice_line'].insert_one(local_credit_note_line).inserted_id
|
||||
if (not inserted_id):
|
||||
mycommon.myprint( " WARNING : Impossible d'inserer la ligne d'avoir pour l'avoir "+str(credit_notes_reference))
|
||||
|
||||
|
||||
|
||||
|
||||
return True, "L'avoir a été créé avec la référence "+str(liste_credit_node), liste_credit_node
|
||||
|
||||
|
||||
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'avoir ", False
|
||||
|
|
Loading…
Reference in New Issue