01/10/2023 - 17h
parent
b1489d0f4c
commit
1ed2cf1f99
|
@ -1,13 +1,14 @@
|
|||
<?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="30/09/2023 - 14h">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="30/09/2023 - 19h">
|
||||
<change afterPath="$PROJECT_DIR$/partner_invoice.py" afterDir="false" />
|
||||
<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$/email_inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_inscription_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/email_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/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$/partner_order.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_order.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partners.py" beforeDir="false" afterPath="$PROJECT_DIR$/partners.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/ressources_humaines.py" beforeDir="false" afterPath="$PROJECT_DIR$/ressources_humaines.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -71,20 +72,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00068" summary="14/08/23 - 16h30">
|
||||
<created>1692023863799</created>
|
||||
<option name="number" value="00068" />
|
||||
<option name="presentableId" value="LOCAL-00068" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1692023863799</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00069" summary="15/08/23 -14h">
|
||||
<created>1692102586761</created>
|
||||
<option name="number" value="00069" />
|
||||
<option name="presentableId" value="LOCAL-00069" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1692102586763</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00070" summary="15/08/23 - 20h">
|
||||
<created>1692122709241</created>
|
||||
<option name="number" value="00070" />
|
||||
|
@ -414,7 +401,21 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1696076203877</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="117" />
|
||||
<task id="LOCAL-00117" summary="30/09/2023 - 18h">
|
||||
<created>1696091230108</created>
|
||||
<option name="number" value="00117" />
|
||||
<option name="presentableId" value="LOCAL-00117" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1696091230108</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00118" summary="30/09/2023 - 19h">
|
||||
<created>1696093021639</created>
|
||||
<option name="number" value="00118" />
|
||||
<option name="presentableId" value="LOCAL-00118" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1696093021639</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="119" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -429,8 +430,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="30/08/23 - 17h" />
|
||||
<MESSAGE value="30/08/23 - 22h" />
|
||||
<MESSAGE value="01/09/23 - 19h" />
|
||||
<MESSAGE value="04/09/23 - 20h" />
|
||||
<MESSAGE value="05/09/23 - 14h30" />
|
||||
|
@ -454,6 +453,8 @@
|
|||
<MESSAGE value="26/09/23 - 23h" />
|
||||
<MESSAGE value="28/09/23 - 23h" />
|
||||
<MESSAGE value="30/09/2023 - 14h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="30/09/2023 - 14h" />
|
||||
<MESSAGE value="30/09/2023 - 18h" />
|
||||
<MESSAGE value="30/09/2023 - 19h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="30/09/2023 - 19h" />
|
||||
</component>
|
||||
</project>
|
2846
Log/log_file.log
2846
Log/log_file.log
File diff suppressed because it is too large
Load Diff
63
class_mgt.py
63
class_mgt.py
|
@ -4001,3 +4001,66 @@ def delete_Class_by_internal_url(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de supprimer la formation "
|
||||
|
||||
"""
|
||||
Cette fonction retourne une formation, prenant en argument le l'internal_url
|
||||
"""
|
||||
def get_Class_From_Internal_Url(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'internal_url']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'internal_url']
|
||||
|
||||
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
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
for retval in MYSY_GV.dbname['myclass'].find({'valide': '1', 'locked': '0', 'internal_url':str(diction['internal_url']),
|
||||
'partner_owner_recid':str(my_partner['recid'])}):
|
||||
user = retval
|
||||
user['id'] = str(val_tmp)
|
||||
val_tmp = val_tmp + 1
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
#print(" RetObject = ", user)
|
||||
|
||||
return True, RetObject
|
||||
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer les données de la formation "
|
||||
|
||||
|
||||
|
|
29
main.py
29
main.py
|
@ -53,6 +53,7 @@ import ressources_materiels as ressources_materiels
|
|||
import partner_order as partner_order
|
||||
import partner_document_mgt as partner_document_mgt
|
||||
import user_access_right as user_access_right
|
||||
import partner_invoice as partner_invoice
|
||||
|
||||
app = Flask(__name__)
|
||||
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
|
||||
|
@ -2158,6 +2159,19 @@ def delete_Class_by_internal_url():
|
|||
return jsonify(status=localStatus, message=message )
|
||||
|
||||
|
||||
"""
|
||||
Cette API retourne une formation, en partant de l'internal url de la formation
|
||||
"""
|
||||
@app.route('/myclass/api/get_Class_From_Internal_Url/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def get_Class_From_Internal_Url():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### get_Class_From_Internal_Url : payload = ",str(payload))
|
||||
localStatus, message= cm.get_Class_From_Internal_Url(payload)
|
||||
return jsonify(status=localStatus, message=message )
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
@ -4769,6 +4783,21 @@ def Is_User_Has_Right_To_Action():
|
|||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API de facturation des commandes d'un partenaire
|
||||
"""
|
||||
|
||||
@app.route('/myclass/api/Invoice_Partner_Order/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Invoice_Partner_Order():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Invoice_Partner_Order payload = ",payload)
|
||||
status, retval, invoice_id = partner_invoice.Invoice_Partner_Order(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
context = SSL.Context(SSL.SSLv23_METHOD)
|
||||
|
|
|
@ -0,0 +1,308 @@
|
|||
"""
|
||||
Ce fichier permet de gerer la facturation des commandes des partenaires vers leur client.
|
||||
|
||||
Il se base sur les commandes faite à l'aide du fichier "partner_order.py"
|
||||
|
||||
"""
|
||||
import bson
|
||||
import pymongo
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
from bson import ObjectId
|
||||
import re
|
||||
from datetime import datetime
|
||||
import prj_common as mycommon
|
||||
import secrets
|
||||
import inspect
|
||||
import sys, os
|
||||
import csv
|
||||
import pandas as pd
|
||||
from pymongo import ReturnDocument
|
||||
import GlobalVariable as MYSY_GV
|
||||
from math import isnan
|
||||
import GlobalVariable as MYSY_GV
|
||||
import ela_index_bdd_classes as eibdd
|
||||
import email_mgt as email
|
||||
import jinja2
|
||||
from flask import send_file
|
||||
from xhtml2pdf import pisa
|
||||
from email.message import EmailMessage
|
||||
from email.mime.text import MIMEText
|
||||
from email import encoders
|
||||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.base import MIMEBase
|
||||
from email import encoders
|
||||
import partner_order as partner_order
|
||||
|
||||
|
||||
def Invoice_Partner_Order(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:
|
||||
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 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
|
||||
|
||||
|
||||
# Verification de la validité de la commande à 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':'commande', 'valide': '1',
|
||||
'locked': '0'})
|
||||
|
||||
if( order_to_invoice_data_count < 0 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - Les references de la commande sont invalides ")
|
||||
return False, " Les references de la commande 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':'commande'})
|
||||
|
||||
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']) != "2" ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - La commande n'est pas au statut 'Traité'. Facturation annulée. ")
|
||||
return False, " La commande n'est pas au statut 'Traité'. 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']) != "commande" or str(order_lines_to_invoice_data['order_line_status']) != "2"
|
||||
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 Quantite "+ 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 Quantite "+ 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_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':'commande'},
|
||||
{'$set':{'order_header_status':'3'}
|
||||
}
|
||||
)
|
||||
|
||||
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': 'commande'},
|
||||
{'$set': {'order_header_status': '2'}}
|
||||
})
|
||||
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'
|
||||
"""
|
||||
/!\ On va recopier les header et line, telqel.
|
||||
On fera les changements plus tard si besoin
|
||||
"""
|
||||
|
||||
|
||||
# Rcuperation 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.
|
||||
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': 'commande'},
|
||||
{'$set': {'order_header_status': '2'}}
|
||||
})
|
||||
|
||||
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())
|
||||
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':'commande'}, {'_id':0, 'order_header_type':0, 'order_header_status':0})
|
||||
|
||||
new_invoice_data_header['invoice_header_ref_interne'] = retval_sequence_invoice['prefixe']+str(current_seq_value)
|
||||
new_invoice_data_header['invoice_header_type'] = "facture"
|
||||
new_invoice_data_header['invoice_date'] = invoice_date_time
|
||||
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': 'commande'},
|
||||
{'$set': {'order_header_status': '2'}}
|
||||
})
|
||||
mycommon.myprint(
|
||||
" Impossible de créer l'entete de la facture ")
|
||||
return False, "Impossible de créer l'entete de la facture ", False
|
||||
|
||||
|
||||
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)
|
||||
|
||||
inserted_line_id = MYSY_GV.dbname['partner_invoice_line'].insert_one(new_invoice_data_line).inserted_id
|
||||
if (not inserted_line_id):
|
||||
|
||||
# Vu quil y a un soucis avec l'une des ligne, 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': 'commande'},
|
||||
{'$set': {'order_header_status': '2'}}
|
||||
})
|
||||
|
||||
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
|
||||
|
||||
|
||||
# 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': 'commande'}
|
||||
|
||||
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': 'commande'},
|
||||
{'$set': {'order_line_status': '3'}}
|
||||
)
|
||||
|
||||
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'])))
|
||||
|
||||
|
||||
|
||||
return True, " La commande 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 la commande ", False
|
||||
|
|
@ -4665,8 +4665,18 @@ def Convert_Quotation_to_Order(diction):
|
|||
print(" ### La nouvelle Entete a été créer le num_order = ", new_created_order['order_header_ref_interne'])
|
||||
|
||||
|
||||
# Traitement des ligne
|
||||
# Traitement des lignes
|
||||
cpt_line = 0
|
||||
qyr_convert = {'order_header_id': str(diction['order_id']),
|
||||
'valide': '1', 'locked': '0',
|
||||
'order_line_type':'devis',
|
||||
'partner_owner_recid': str(
|
||||
my_partner['recid'])}
|
||||
|
||||
|
||||
|
||||
print( " #### qry convert = ", qyr_convert)
|
||||
|
||||
for Quotation_line_data in MYSY_GV.dbname['partner_order_line'].find({'order_header_id': str(diction['order_id']),
|
||||
'valide': '1', 'locked': '0',
|
||||
'order_line_type':'devis',
|
||||
|
|
180
partners.py
180
partners.py
|
@ -216,7 +216,7 @@ def update_partner_main_mail(diction):
|
|||
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||
# field_list.
|
||||
'''
|
||||
field_list = ['token', 'mail', 'new_mail', 'conf_new_mail']
|
||||
field_list = ['token', 'mail', 'new_mail', 'conf_new_mail', 'partner_account_id']
|
||||
incom_keys = diction.keys()
|
||||
|
||||
for val in incom_keys:
|
||||
|
@ -247,6 +247,26 @@ def update_partner_main_mail(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
||||
return False, " Impossible de mettre à jour le partenaire "
|
||||
|
||||
partner_account_id = ""
|
||||
if ("partner_account_id" in diction.keys()):
|
||||
partner_account_id = diction['partner_account_id']
|
||||
|
||||
# Verification de la validité du compte
|
||||
is_count_valide = MYSY_GV.dbname['partnair_account'].count_documents(
|
||||
{'_id': ObjectId(partner_account_id), 'active': '1', 'locked': '0',
|
||||
'recid': partner_recid})
|
||||
if (is_count_valide <= 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " est invalide")
|
||||
return False, " Le compte partner_account_id :" + str(partner_account_id) + " est invalide "
|
||||
|
||||
if (is_count_valide > 1):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " correspond à plusieurs utilisateurs (" + str(is_count_valide) + ")")
|
||||
return False, " Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " correspond à plusieurs utilisateurs "
|
||||
|
||||
|
||||
mymail=""
|
||||
if ("mail" in diction.keys()):
|
||||
if diction['mail']:
|
||||
|
@ -281,8 +301,9 @@ def update_partner_main_mail(diction):
|
|||
coll_name = MYSY_GV.dbname['partnair_account']
|
||||
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'recid': str(partner_recid), 'locked': '0', 'active': '1', 'email':mymail},
|
||||
{'_id':ObjectId(partner_account_id), 'locked': '0', 'active': '1', 'email':mymail},
|
||||
{"$set": mydata},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
|
@ -317,7 +338,7 @@ def update_partner_pwd(diction):
|
|||
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||
# field_list.
|
||||
'''
|
||||
field_list = ['token', 'pwd', 'new_pwd', 'conf_new_pwd']
|
||||
field_list = ['token', 'pwd', 'new_pwd', 'conf_new_pwd', 'partner_account_id',]
|
||||
incom_keys = diction.keys()
|
||||
|
||||
for val in incom_keys:
|
||||
|
@ -348,6 +369,27 @@ def update_partner_pwd(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
||||
return False, " Impossible de mettre à jour le partenaire "
|
||||
|
||||
partner_account_id = ""
|
||||
if ("partner_account_id" in diction.keys()):
|
||||
partner_account_id = diction['partner_account_id']
|
||||
|
||||
# Verification de la validité du compte
|
||||
is_count_valide = MYSY_GV.dbname['partnair_account'].count_documents(
|
||||
{'_id': ObjectId(partner_account_id), 'active': '1', 'locked': '0',
|
||||
'recid': partner_recid})
|
||||
if (is_count_valide <= 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " est invalide")
|
||||
return False, " Le compte partner_account_id :" + str(partner_account_id) + " est invalide "
|
||||
|
||||
if (is_count_valide > 1):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " correspond à plusieurs utilisateurs (" + str(is_count_valide) + ")")
|
||||
return False, " Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " correspond à plusieurs utilisateurs "
|
||||
|
||||
|
||||
|
||||
mypwd=""
|
||||
if ("pwd" in diction.keys()):
|
||||
if diction['pwd']:
|
||||
|
@ -384,7 +426,7 @@ def update_partner_pwd(diction):
|
|||
coll_name = MYSY_GV.dbname['partnair_account']
|
||||
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'recid': str(partner_recid), 'locked': '0', 'active': '1', 'pwd':mypwd},
|
||||
{'_id':ObjectId(partner_account_id), 'locked': '0', 'active': '1', 'pwd':mypwd},
|
||||
{"$set": mydata},
|
||||
upsert= False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
|
@ -450,7 +492,7 @@ def update_partner_insert_key(diction):
|
|||
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||
# field_list.
|
||||
'''
|
||||
field_list = ['token', 'current_insert_key', 'new_insert_key', 'conf_insert_key']
|
||||
field_list = ['token', 'current_insert_key', 'new_insert_key', 'conf_insert_key', 'partner_account_id']
|
||||
incom_keys = diction.keys()
|
||||
|
||||
for val in incom_keys:
|
||||
|
@ -481,6 +523,29 @@ def update_partner_insert_key(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
||||
return False, " Impossible de mettre à jour la clé d'insertion "
|
||||
|
||||
partner_account_id = ""
|
||||
if ("partner_account_id" in diction.keys()):
|
||||
partner_account_id = diction['partner_account_id']
|
||||
|
||||
# Verification de la validité du compte
|
||||
is_count_valide = MYSY_GV.dbname['partnair_account'].count_documents(
|
||||
{'_id': ObjectId(partner_account_id), 'active': '1', 'locked': '0',
|
||||
'recid': partner_recid})
|
||||
if (is_count_valide <= 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " est invalide")
|
||||
return False, " Le compte partner_account_id :" + str(partner_account_id) + " est invalide "
|
||||
|
||||
if (is_count_valide > 1):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " correspond à plusieurs utilisateurs (" + str(is_count_valide) + ")")
|
||||
return False, " Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " correspond à plusieurs utilisateurs "
|
||||
|
||||
is_partner_admin_account = "0"
|
||||
if ("is_partner_admin_account" in diction.keys()):
|
||||
partner_account_id = diction['is_partner_admin_account']
|
||||
|
||||
mykey=""
|
||||
if ("current_insert_key" in diction.keys()):
|
||||
if diction['current_insert_key']:
|
||||
|
@ -517,8 +582,9 @@ def update_partner_insert_key(diction):
|
|||
coll_name = MYSY_GV.dbname['partnair_account']
|
||||
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'recid': str(partner_recid), 'locked': '0', 'active': '1', 'insert_key':mykey},
|
||||
{'_id':ObjectId(partner_account_id), 'locked': '0', 'active': '1', 'insert_key':mykey},
|
||||
{"$set": mydata},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
|
@ -558,7 +624,8 @@ def update_partner_account(file_logo=None, file_cachet=None, Folder=None, dictio
|
|||
'invoice_nom', 'invoice_adr_street', 'invoice_adr_city', 'invoice_adr_zip',
|
||||
'invoice_adr_country', 'invoice_email', 'invoice_telephone', 'invoice_vat_num',
|
||||
'siret', 'num_nda', 'iscertitrace', 'isdatadock', 'isqualiopi', 'website',
|
||||
'isbureaucertitrace', 'iscertifvoltaire', 'file_logo_recid', 'file_cachet_recid']
|
||||
'isbureaucertitrace', 'iscertifvoltaire', 'file_logo_recid', 'file_cachet_recid',
|
||||
'partner_account_id', ]
|
||||
|
||||
|
||||
incom_keys = diction.keys()
|
||||
|
@ -601,6 +668,31 @@ def update_partner_account(file_logo=None, file_cachet=None, Folder=None, dictio
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
||||
return False, " Impossible de mettre à jour le partenaire "
|
||||
|
||||
partner_account_id = ""
|
||||
if ("partner_account_id" in diction.keys()):
|
||||
partner_account_id = diction['partner_account_id']
|
||||
|
||||
|
||||
# Verification de la validité du compte
|
||||
is_count_valide = MYSY_GV.dbname['partnair_account'].count_documents({'_id':ObjectId(partner_account_id), 'active':'1', 'locked':'0',
|
||||
'recid':partner_recid})
|
||||
if( is_count_valide <= 0 ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :"+str(partner_account_id)+" est invalide")
|
||||
return False, " Le compte partner_account_id :"+str(partner_account_id)+" est invalide "
|
||||
|
||||
if( is_count_valide > 1 ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le compte partner_account_id :" + str(
|
||||
partner_account_id) + " correspond à plusieurs utilisateurs ("+str(is_count_valide)+")")
|
||||
return False, " Le compte partner_account_id :" + str(partner_account_id) + " correspond à plusieurs utilisateurs "
|
||||
|
||||
|
||||
is_partner_admin_account = "0"
|
||||
if ("is_partner_admin_account" in diction.keys()):
|
||||
partner_account_id = diction['is_partner_admin_account']
|
||||
|
||||
|
||||
print(" #### partner_account_id = ", partner_account_id)
|
||||
|
||||
mydata = {}
|
||||
if ("nom" in diction.keys()):
|
||||
mydata['nom'] = diction['nom']
|
||||
|
@ -704,48 +796,54 @@ def update_partner_account(file_logo=None, file_cachet=None, Folder=None, dictio
|
|||
"""
|
||||
Si le compte partenaire n'as pas de compte de payement stripe, alors on profite de cette mise à jour pour le faire
|
||||
"""
|
||||
tmp = coll_name.find({'recid':str(partner_recid)})
|
||||
print('### tmp = '+str(tmp[0]))
|
||||
tmp = coll_name.find({'_id':ObjectId(partner_account_id), 'active':'1', 'locked':'0',
|
||||
'recid':partner_recid})
|
||||
|
||||
partnair_stripe_id = ""
|
||||
if ("stripe_account_id" in tmp[0].keys()):
|
||||
if tmp[0]['stripe_account_id']:
|
||||
partnair_stripe_id = tmp[0]['stripe_account_id']
|
||||
is_admin_account = "0"
|
||||
if( "is_partner_admin_account" in tmp[0].keys()):
|
||||
is_admin_account = tmp[0]['is_partner_admin_account']
|
||||
|
||||
if ( partnair_stripe_id is None or len(partnair_stripe_id) < 5):
|
||||
print('### le partenaire = ' + str(tmp[0]['nom']) + " n'as pas de compte Stripe. on va le créer")
|
||||
"""
|
||||
Creation du compte de payement Stripe
|
||||
"""
|
||||
if( is_admin_account == "1"):
|
||||
partnair_stripe_id = ""
|
||||
if ("stripe_account_id" in tmp[0].keys()):
|
||||
if tmp[0]['stripe_account_id']:
|
||||
partnair_stripe_id = tmp[0]['stripe_account_id']
|
||||
|
||||
my_stripe_data = {}
|
||||
my_stripe_data['email'] = str(tmp[0]['email'])
|
||||
my_stripe_data['name'] = str(tmp[0]['nom'])
|
||||
if ( partnair_stripe_id is None or len(partnair_stripe_id) < 5):
|
||||
print('### le partenaire = ' + str(tmp[0]['nom']) + " n'as pas de compte Stripe. on va le créer")
|
||||
"""
|
||||
Creation du compte de payement Stripe
|
||||
"""
|
||||
|
||||
my_stripe_data['city'] = ""
|
||||
if ("adr_city" in tmp[0].keys()):
|
||||
if tmp[0]['adr_city']:
|
||||
my_stripe_data['city'] = str(tmp[0]['adr_city'])
|
||||
my_stripe_data = {}
|
||||
my_stripe_data['email'] = str(tmp[0]['email'])
|
||||
my_stripe_data['name'] = str(tmp[0]['nom'])
|
||||
|
||||
my_stripe_data['country'] = ""
|
||||
if ("adr_country" in tmp[0].keys()):
|
||||
if tmp[0]['adr_country']:
|
||||
my_stripe_data['country'] = str(tmp[0]['adr_country'])
|
||||
my_stripe_data['city'] = ""
|
||||
if ("adr_city" in tmp[0].keys()):
|
||||
if tmp[0]['adr_city']:
|
||||
my_stripe_data['city'] = str(tmp[0]['adr_city'])
|
||||
|
||||
local_status, part_stripe_account_id = Stripe.create_customer(my_stripe_data)
|
||||
mydata['stripe_account_id'] = part_stripe_account_id
|
||||
mydata['stripe_paymentmethod_id'] = ""
|
||||
my_stripe_data['country'] = ""
|
||||
if ("adr_country" in tmp[0].keys()):
|
||||
if tmp[0]['adr_country']:
|
||||
my_stripe_data['country'] = str(tmp[0]['adr_country'])
|
||||
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - WARNING : Impossible de créer le compte STRIPE du Client " + str(
|
||||
tmp[0]['nom']))
|
||||
local_status, part_stripe_account_id = Stripe.create_customer(my_stripe_data)
|
||||
mydata['stripe_account_id'] = part_stripe_account_id
|
||||
mydata['stripe_paymentmethod_id'] = ""
|
||||
|
||||
if (local_status is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - WARNING : Impossible de créer le compte STRIPE du Client " + str(
|
||||
tmp[0]['nom']))
|
||||
|
||||
|
||||
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'recid': str(partner_recid), 'locked': '0', 'active': '1'},
|
||||
{'_id':ObjectId(partner_account_id), 'locked': '0', 'active': '1'},
|
||||
{"$set": mydata},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
|
@ -757,9 +855,11 @@ def update_partner_account(file_logo=None, file_cachet=None, Folder=None, dictio
|
|||
|
||||
|
||||
"""
|
||||
A present que le partenaire est mis à jour / créé, on va mettre à jour les image logo et image cachet s'il y en a
|
||||
A present que le partenaire est mis à jour / créé, on va mettre à jour les image logo et image cachet s'il y en a.
|
||||
Mais seulement pour les comptes admin
|
||||
"""
|
||||
if( file_logo ):
|
||||
|
||||
if( is_admin_account == "1" and file_logo ):
|
||||
recordimage_diction = {}
|
||||
recordimage_diction['token'] = diction['token']
|
||||
recordimage_diction['related_collection'] = "partnair_account"
|
||||
|
@ -771,7 +871,7 @@ def update_partner_account(file_logo=None, file_cachet=None, Folder=None, dictio
|
|||
if( local_status is False):
|
||||
return local_status, local_message
|
||||
|
||||
if( file_cachet ):
|
||||
if( is_admin_account == "1" and file_cachet ):
|
||||
recordimage_diction = {}
|
||||
recordimage_diction['token'] = diction['token']
|
||||
recordimage_diction['related_collection'] = "partnair_account"
|
||||
|
|
Loading…
Reference in New Issue