07/09/2023 - 14h

master
cherif 2023-09-07 14:00:58 +02:00
parent 97ee715a9a
commit 3bb668f8d6
5 changed files with 1894 additions and 21 deletions

View File

@ -1,8 +1,9 @@
<?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/09/2023 - 11h">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="06/09/2023 - 13h">
<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$/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" />
@ -69,13 +70,6 @@
<option name="presentableId" value="Default" />
<updated>1680804787304</updated>
</task>
<task id="LOCAL-00049" summary="23/07/2023 - 21h">
<created>1690141881201</created>
<option name="number" value="00049" />
<option name="presentableId" value="LOCAL-00049" />
<option name="project" value="LOCAL" />
<updated>1690141881201</updated>
</task>
<task id="LOCAL-00050" summary="24/07/23 - 17h">
<created>1690214062664</created>
<option name="number" value="00050" />
@ -412,7 +406,14 @@
<option name="project" value="LOCAL" />
<updated>1693991026077</updated>
</task>
<option name="localTasksCounter" value="98" />
<task id="LOCAL-00098" summary="06/09/2023 - 13h">
<created>1693999843882</created>
<option name="number" value="00098" />
<option name="presentableId" value="LOCAL-00098" />
<option name="project" value="LOCAL" />
<updated>1693999843882</updated>
</task>
<option name="localTasksCounter" value="99" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -427,7 +428,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="18/08/23 - 17h30" />
<MESSAGE value="19/08/23 - 15h30" />
<MESSAGE value="19/08/23 - 20h30" />
<MESSAGE value="20/08/23 - 23h30" />
@ -452,6 +452,7 @@
<MESSAGE value="05/09/23 - 14h30" />
<MESSAGE value="05/09/23 - 20h30" />
<MESSAGE value="06/09/2023 - 11h" />
<option name="LAST_COMMIT_MESSAGE" value="06/09/2023 - 11h" />
<MESSAGE value="06/09/2023 - 13h" />
<option name="LAST_COMMIT_MESSAGE" value="06/09/2023 - 13h" />
</component>
</project>

View File

@ -485,5 +485,24 @@ MODELE_DOCUMENT_TYPE = ['sms', 'email', 'pdf']
Gestion des commandes et devis des partenaires
"""
PARTNER_ORDER_TYPE = ['devis', 'commande']
PARTNER_ORDER_TYPE = ['devis', 'commande']
"""
En termes de process, un document de type commande peut avoir le statut de :
-1 => Annulé
0 => Brouillon
1 => En cours
2 => Traité (prêt à être facturée)
3 => Facturé (la facture est traitée dans un autre document).
"""
PARTNER_ORDER_STATUS = ['-1', '0', '1', '2', '3']
"""
Les devis :
En termes de process, un document de type devis peut avoir le un des statuts ci-dessous :
Brouillon => valeur 0
En cours => valeur 1
Fermé => valeur 2
Annulé => valeur -1
"""
PARTNER_QUOTATION_STATUS = ['-1', '0', '1', '2']

File diff suppressed because it is too large Load Diff

12
main.py
View File

@ -4276,6 +4276,18 @@ def Update_Partner_Order_Header():
status, retval = partner_order.Update_Partner_Order_Header(payload)
return jsonify(status=status, message=retval)
"""
API de mise à jour d'une entete d'un devis client d'un partenaire
"""
@app.route('/myclass/api/Update_Partner_Quotation_Header/', methods=['POST','GET'])
@crossdomain(origin='*')
def Update_Partner_Quotation_Header():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Update_Partner_Quotation_Header payload = ",payload)
status, retval = partner_order.Update_Partner_Quotation_Header(payload)
return jsonify(status=status, message=retval)
"""

View File

@ -159,6 +159,21 @@ def Add_Partner_Order(diction):
return False, " - Le champ 'ref_interne' fait plus de 255 caractères "
data['order_header_ref_interne'] = diction['order_header_ref_interne']
order_header_status = ""
if ("order_header_status" in diction.keys()):
order_header_status = diction['order_header_status']
if (order_header_status not in MYSY_GV.PARTNER_ORDER_STATUS):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'Statut' est invalide. Les valeurs acceptées " + str(
MYSY_GV.PARTNER_ORDER_STATUS))
return False, " - Le champ 'Statut' est invalide. Les valeurs acceptées " + str(
MYSY_GV.PARTNER_ORDER_STATUS)
data['order_header_status'] = diction['order_header_status']
else:
data['order_header_status'] = "0"
order_header_ref_externe = ""
if ("order_header_ref_externe" in diction.keys()):
@ -551,6 +566,21 @@ def Add_Partner_Quotation(diction):
return False, " - Le champ 'Description' fait plus de 500 caractères "
data['order_header_description'] = diction['order_header_description']
order_header_status = ""
if ("order_header_status" in diction.keys()):
order_header_status = diction['order_header_status']
if (order_header_status not in MYSY_GV.PARTNER_QUOTATION_STATUS):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'Statut' est invalide. Les valeurs acceptées " + str(
MYSY_GV.PARTNER_QUOTATION_STATUS))
return False, " - Le champ 'Statut' est invalide. Les valeurs acceptées " + str(
MYSY_GV.PARTNER_QUOTATION_STATUS)
data['order_header_status'] = diction['order_header_status']
else:
data['order_header_status'] = "0"
order_header_comment = ""
if ("order_header_comment" in diction.keys()):
if diction['order_header_comment']:
@ -904,7 +934,7 @@ def Update_Partner_Order_Header(diction):
'order_header_ref_interne', 'order_header_total_ht', 'order_header_total_tax',
'order_header_total_ttc', 'order_header_status', 'order_header_type_reduction',
'order_header_type_reduction_valeur', 'order_header_montant_reduction',
'order_header_id']
'order_header_id', 'order_header_type']
@ -919,7 +949,7 @@ def Update_Partner_Order_Header(diction):
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', "order_header_client_id", "order_header_date_cmd",
'order_header_id', 'order_header_ref_interne']
'order_header_id', 'order_header_ref_interne', 'order_header_type']
for val in field_list_obligatoire:
if val not in diction:
@ -954,7 +984,7 @@ def Update_Partner_Order_Header(diction):
Pour un debut pas de facturation partielle. c'est tout ou rien.
"""
my_order_data_count = MYSY_GV.dbname['partner_order_header'].count_documents({'partner_owner_recid':str(my_partner['recid']),
'valide':'1', 'locked':'0',
'valide':'1', 'locked':'0', 'order_header_type':'commande',
'_id':ObjectId(str(order_header_id))})
if( my_order_data_count != 1 ):
@ -962,6 +992,13 @@ def Update_Partner_Order_Header(diction):
str(inspect.stack()[0][3]) + " - L'identifiant de la commande est invalide ")
return False, " L'identifiant de la commande est invalide",
"""
Recuperation et stockage des données de l'entete avant mise à jour
"""
my_order_data_previous_information = MYSY_GV.dbname['partner_order_header'].find_one(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0', 'order_header_type': 'commande',
'_id': ObjectId(str(order_header_id))})
# Recuperation des champs
data = {}
@ -992,6 +1029,18 @@ def Update_Partner_Order_Header(diction):
return False, " - Le champ 'Description' fait plus de 500 caractères "
data['order_header_description'] = diction['order_header_description']
order_header_status = ""
if ("order_header_status" in diction.keys()):
order_header_status = diction['order_header_status']
if (order_header_status not in MYSY_GV.PARTNER_ORDER_STATUS):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'Statut' est invalide. Les valeurs acceptées "+str(MYSY_GV.PARTNER_ORDER_STATUS))
return False, " - Le champ 'Statut' est invalide. Les valeurs acceptées "+str(MYSY_GV.PARTNER_ORDER_STATUS)
data['order_header_status'] = diction['order_header_status']
order_header_comment = ""
if ("order_header_comment" in diction.keys()):
order_header_comment = diction['order_header_comment']
@ -1047,6 +1096,9 @@ def Update_Partner_Order_Header(diction):
if ("order_header_vendeur_id" in diction.keys()):
order_header_vendeur_id = diction['order_header_vendeur_id']
#local_qry = {'_id': ObjectId(str(order_header_vendeur_id)), 'valide': '1', 'locked': '0', 'partner_recid': str(my_partner['recid'])}
#print(" #### local_qry = ", local_qry)
# Verifier que l'employé vendeur existe bien pour ce partner
is_employee_exist_count = MYSY_GV.dbname['ressource_humaine'].count_documents(
{'_id': ObjectId(str(order_header_vendeur_id)), 'valide': '1',
@ -1205,7 +1257,7 @@ def Update_Partner_Order_Header(diction):
inserted_data = MYSY_GV.dbname['partner_order_header'].find_one_and_update(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0',
'valide': '1', 'locked': '0','order_header_type':'commande',
'_id': ObjectId(str(order_header_id))},
{"$set": data},
return_document=ReturnDocument.AFTER,
@ -1217,6 +1269,43 @@ def Update_Partner_Order_Header(diction):
" Impossible de mettre à jour l'entete de commande ")
return False, "Impossible de mettre à jour l'entete de commande "
"""
Si le statut de l'entete de commande a bougé, alors on met à le statut de toutes les ligne
Verification my_order_data_previous_information['order_header_status'] != order_header_status
"""
local_qry = {'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0',
'order_header_id': str(order_header_id)
}
#print(" #### COMMANDE local_qry = ", local_qry)
if( "order_header_status" in my_order_data_previous_information.keys()):
if( str(my_order_data_previous_information['order_header_status']) != str(order_header_status)):
# Il y a eu une mise à jour du statut de l'entete, on va donc mettre à jour les statuts des lignes de commande
inserted_data_line = MYSY_GV.dbname['partner_order_line'].update_many(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0',
'order_header_id': str(order_header_id)
},
{
"$set": {"order_line_status": str(order_header_status), 'date_update':str(data['date_update'])}
})
"""print("raw:", inserted_data_line.raw_result)
print("acknowledged:", inserted_data_line.acknowledged)
print("matched_count:", inserted_data_line.matched_count)"""
else:
inserted_data_line = MYSY_GV.dbname['partner_order_line'].update_many(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0',
'order_header_id': str(order_header_id)
},
{
"$set": {"order_line_status": str(order_header_status), 'date_update': str(data['date_update'])}
})
"""print("raw:", inserted_data_line.raw_result)
print("acknowledged:", inserted_data_line.acknowledged)
print("matched_count:", inserted_data_line.matched_count)"""
return True, " La commande a été correctement mise à jour"
except Exception as e:
@ -1225,6 +1314,411 @@ def Update_Partner_Order_Header(diction):
return False, " Impossible de mettre à jour la commande "
"""
Fonction de mise à jour d'un devis
"""
def Update_Partner_Quotation_Header(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'order_header_client_id', 'order_header_description', 'order_header_comment',
'order_header_date_cmd', 'order_header_date_expiration',
'order_header_adr_fact_adresse', 'order_header_adr_fact_code_postal',
'order_header_adr_fact_ville', 'order_header_adr_fact_pays',
'order_header_adr_liv_adresse', 'order_header_adr_liv_code_postal', 'order_header_adr_liv_ville',
'order_header_adr_liv_pays',
'order_header_condition_paiement', 'order_header_ref_client', 'order_header_vendeur_id',
'order_header_ref_interne', 'order_header_total_ht', 'order_header_total_tax',
'order_header_total_ttc', 'order_header_status', 'order_header_type_reduction',
'order_header_type_reduction_valeur', 'order_header_montant_reduction',
'order_header_id', 'order_header_type']
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', "order_header_client_id", "order_header_date_cmd",
'order_header_id', 'order_header_ref_interne', 'order_header_type']
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
order_header_id = ""
if ("order_header_id" in diction.keys()):
if diction['order_header_id']:
order_header_id = diction['order_header_id']
"""
# Verifier que la commande existe et qu'elle est modifiable.
Pour les ligne, on fait pareil, on ne peut modifier que celles qui sont modifiable.
Conditions pour modifier entete :
1 - statut est : devis, cmd, MAIS PAS ANNULE ou FACTURE
Pour un debut pas de facturation partielle. c'est tout ou rien.
"""
my_order_data_count = MYSY_GV.dbname['partner_order_header'].count_documents(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0', 'order_header_type':'devis',
'_id': ObjectId(str(order_header_id))})
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",
"""
Recuperation et stockage des données de l'entete avant mise à jour
"""
my_order_data_previous_information = MYSY_GV.dbname['partner_order_header'].find_one(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0', 'order_header_type': 'devis',
'_id': ObjectId(str(order_header_id))})
# Recuperation des champs
data = {}
data['partner_owner_recid'] = my_partner['recid']
order_header_client_id = ""
if ("order_header_client_id" in diction.keys()):
order_header_client_id = diction['order_header_client_id']
# Verifier que le client existe bien pour ce partner
is_client_exist_count = MYSY_GV.dbname['partner_client'].count_documents(
{'_id': ObjectId(str(order_header_client_id)), 'valide': '1',
'locked': '0', 'partner_recid': str(my_partner['recid'])})
if (is_client_exist_count <= 0):
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le client est invalide ")
return False, " - Le client est invalide "
data['order_header_client_id'] = diction['order_header_client_id']
order_header_description = ""
if ("order_header_description" in diction.keys()):
order_header_description = diction['order_header_description']
if (len(str(order_header_description)) > 500):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_description' fait plus de 500 caractères ")
return False, " - Le champ 'Description' fait plus de 500 caractères "
data['order_header_description'] = diction['order_header_description']
order_header_status = ""
if ("order_header_status" in diction.keys()):
order_header_status = diction['order_header_status']
if (order_header_status not in MYSY_GV.PARTNER_QUOTATION_STATUS):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'Statut' est invalide. Les valeurs acceptées " + str(
MYSY_GV.PARTNER_QUOTATION_STATUS))
return False, " - Le champ 'Statut' est invalide. Les valeurs acceptées " + str(
MYSY_GV.PARTNER_QUOTATION_STATUS)
data['order_header_status'] = diction['order_header_status']
order_header_comment = ""
if ("order_header_comment" in diction.keys()):
order_header_comment = diction['order_header_comment']
if (len(str(order_header_comment)) > 500):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_comment' fait plus de 500 caractères ")
return False, " - Le champ 'Commentaire' fait plus de 500 caractères "
data['order_header_comment'] = diction['order_header_comment']
order_header_condition_paiement = ""
if ("order_header_condition_paiement" in diction.keys()):
order_header_condition_paiement = diction['order_header_condition_paiement']
if (len(str(order_header_condition_paiement)) > 255):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_condition_paiement' fait plus de 255 caractères ")
return False, " - Le champ 'Condition de paiement' fait plus de 255 caractères "
data['order_header_condition_paiement'] = diction['order_header_condition_paiement']
order_header_ref_interne = ""
if ("order_header_ref_interne" in diction.keys()):
if diction['order_header_ref_interne']:
order_header_ref_interne = diction['order_header_ref_interne']
if (len(str(order_header_ref_interne)) > 255):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_ref_interne' fait plus de 255 caractères ")
return False, " - Le champ 'ref_interne' fait plus de 255 caractères "
data['order_header_ref_interne'] = diction['order_header_ref_interne']
else:
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - La reference interne de la commande est vide ")
return False, " - La reference interne de la commande est vide "
order_header_ref_externe = ""
if ("order_header_ref_externe" in diction.keys()):
order_header_ref_externe = diction['order_header_ref_externe']
if (len(str(order_header_ref_externe)) > 255):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_ref_externe' fait plus de 255 caractères ")
return False, " - Le champ 'ref_externe' fait plus de 255 caractères "
data['order_header_ref_externe'] = diction['order_header_ref_externe']
order_header_vendeur_id = ""
if ("order_header_vendeur_id" in diction.keys()):
order_header_vendeur_id = diction['order_header_vendeur_id']
# local_qry = {'_id': ObjectId(str(order_header_vendeur_id)), 'valide': '1', 'locked': '0', 'partner_recid': str(my_partner['recid'])}
# print(" #### local_qry = ", local_qry)
# Verifier que l'employé vendeur existe bien pour ce partner
is_employee_exist_count = MYSY_GV.dbname['ressource_humaine'].count_documents(
{'_id': ObjectId(str(order_header_vendeur_id)), 'valide': '1',
'locked': '0', 'partner_recid': str(my_partner['recid'])})
if (is_employee_exist_count <= 0):
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le vendeur est invalide ")
return False, " - Le vendeur est invalide "
data['order_header_vendeur_id'] = diction['order_header_vendeur_id']
order_header_date_cmd = ""
if ("order_header_date_cmd" in diction.keys()):
if diction['order_header_date_cmd']:
order_header_date_cmd = str(diction['order_header_date_cmd'])[0:10]
local_status = mycommon.CheckisDate(order_header_date_cmd)
if (local_status is False):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " La date order_header_date_cmd n'est pas au format 'jj/mm/aaaa' ")
return False, "La date de la commande n'est pas au format 'jj/mm/aaaa'"
data['order_header_date_cmd'] = str(diction['order_header_date_cmd'])[0:10]
else:
# par defaut la date de la commande est la date du jour
data['order_header_date_cmd'] = datetime.today().strftime("%d/%m/%Y")
order_header_date_expiration = ""
if ("order_header_date_expiration" in diction.keys()):
order_header_date_cmd = str(diction['order_header_date_expiration'])[0:10]
local_status = mycommon.CheckisDate(order_header_date_cmd)
if (local_status is False):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " La date order_header_date_expiration n'est pas au format 'jj/mm/aaaa' ")
return False, "La date d'expiration de la commande n'est pas au format 'jj/mm/aaaa'"
data['order_header_date_expiration'] = str(diction['order_header_date_expiration'])[0:10]
## Verification de la cohérence des dates. order_header_date_cmd doit < order_header_date_expiration
if (datetime.strptime(str(diction['order_header_date_cmd'])[0:10], '%d/%m/%Y') >= datetime.strptime(
str(diction['order_header_date_expiration'])[0:10], '%d/%m/%Y')):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - La date d'expiration " + str(diction['order_header_date_expiration'])[
0:10] + " doit etre postérieure à la date de la commande " + str(
diction['order_header_date_cmd'])[0:10] + " ")
return False, " - La date d'expiration " + str(diction['order_header_date_expiration'])[
0:10] + " doit etre postérieure à la date de la commande " + str(
diction['order_header_date_cmd'])[0:10] + " "
## Recuperation de l'adresse de facturation
order_header_adr_fact_adresse = ""
if ("order_header_adr_fact_adresse" in diction.keys()):
order_header_adr_fact_adresse = diction['order_header_adr_fact_adresse']
if (len(str(order_header_adr_fact_adresse)) > 500):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_adr_fact_adresse' fait plus de 500 caractères ")
return False, " - Le champ 'adresse de facturation' fait plus de 500 caractères "
data['order_header_adr_fact_adresse'] = diction['order_header_adr_fact_adresse']
order_header_adr_fact_code_postal = ""
if ("order_header_adr_fact_code_postal" in diction.keys()):
order_header_adr_fact_code_postal = diction['order_header_adr_fact_code_postal']
if (len(str(order_header_adr_fact_code_postal)) > 255):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_adr_fact_code_postal' fait plus de 255 caractères ")
return False, " - Le champ 'order_header_adr_fact_code_postal' fait plus de 255 caractères "
data['order_header_adr_fact_code_postal'] = diction['order_header_adr_fact_code_postal']
order_header_adr_fact_ville = ""
if ("order_header_adr_fact_ville" in diction.keys()):
order_header_adr_fact_ville = diction['order_header_adr_fact_ville']
if (len(str(order_header_adr_fact_ville)) > 255):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_adr_fact_ville' fait plus de 255 caractères ")
return False, " - Le champ 'order_header_adr_fact_ville' fait plus de 255 caractères "
data['order_header_adr_fact_ville'] = diction['order_header_adr_fact_ville']
order_header_adr_fact_pays = ""
if ("order_header_adr_fact_pays" in diction.keys()):
order_header_adr_fact_pays = diction['order_header_adr_fact_pays']
if (len(str(order_header_adr_fact_pays)) > 255):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_adr_fact_pays' fait plus de 255 caractères ")
return False, " - Le champ 'order_header_adr_fact_pays' fait plus de 255 caractères "
data['order_header_adr_fact_pays'] = diction['order_header_adr_fact_pays']
## Recuperation de l'adresse d'exécution de la formation
order_header_adr_liv_adresse = ""
if ("order_header_adr_liv_adresse" in diction.keys()):
order_header_adr_liv_adresse = diction['order_header_adr_liv_adresse']
if (len(str(order_header_adr_liv_adresse)) > 500):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_adr_liv_adresse' fait plus de 500 caractères ")
return False, " - Le champ 'adresse d'exécution' fait plus de 500 caractères "
data['order_header_adr_liv_adresse'] = diction['order_header_adr_liv_adresse']
order_header_adr_liv_code_postal = ""
if ("order_header_adr_liv_code_postal" in diction.keys()):
order_header_adr_liv_code_postal = diction['order_header_adr_liv_code_postal']
if (len(str(order_header_adr_liv_code_postal)) > 255):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_adr_liv_code_postal' fait plus de 255 caractères ")
return False, " - Le champ 'order_header_adr_liv_code_postal' fait plus de 255 caractères "
data['order_header_adr_liv_code_postal'] = diction['order_header_adr_liv_code_postal']
order_header_adr_liv_ville = ""
if ("order_header_adr_liv_ville" in diction.keys()):
order_header_adr_liv_ville = diction['order_header_adr_liv_ville']
if (len(str(order_header_adr_liv_ville)) > 255):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_adr_liv_ville' fait plus de 255 caractères ")
return False, " - Le champ 'order_header_adr_liv_ville' fait plus de 255 caractères "
data['order_header_adr_liv_ville'] = diction['order_header_adr_liv_ville']
order_header_adr_liv_pays = ""
if ("order_header_adr_liv_pays" in diction.keys()):
order_header_adr_liv_pays = diction['order_header_adr_liv_pays']
if (len(str(order_header_adr_liv_pays)) > 255):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Le champ 'order_header_adr_liv_pays' fait plus de 255 caractères ")
return False, " - Le champ 'order_header_adr_liv_pays' fait plus de 255 caractères "
data['order_header_adr_liv_pays'] = diction['order_header_adr_liv_pays']
"""
/!\ : A present que tous les controles sont ok, on va proceder à la creation dans les table.
"""
### 1 - Mise à jour de l'entete
data['date_update'] = str(datetime.now())
print(" ### Update_partner_order data = ", data)
inserted_data = MYSY_GV.dbname['partner_order_header'].find_one_and_update(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0','order_header_type':'devis',
'_id': ObjectId(str(order_header_id))},
{"$set": data},
return_document=ReturnDocument.AFTER,
upsert=False,
)
if (inserted_data is None):
mycommon.myprint(
" Impossible de mettre à jour l'entete du devis ")
return False, "Impossible de mettre à jour l'entete du devis "
"""
Si le statut de l'entete de commande a bougé, alors on met à le statut de toutes les ligne
Verification my_order_data_previous_information['order_header_status'] != order_header_status
"""
local_qry = {'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0',
'order_header_id': str(order_header_id)
},
#print(" #### DEVIS local_qry = ",local_qry )
if( "order_header_status" in my_order_data_previous_information.keys()):
if (str(my_order_data_previous_information['order_header_status']) != str(order_header_status)):
# Il y a eu une mise à jour du statut de l'entete, on va donc mettre à jour les statuts des lignes de commande
inserted_data_line = MYSY_GV.dbname['partner_order_line'].update_many(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0',
'order_header_id': str(order_header_id)
},
{
"$set": {"order_line_status": str(order_header_status), 'date_update': str(data['date_update'])}
})
"""print("raw:", inserted_data_line.raw_result)
print("acknowledged:", inserted_data_line.acknowledged)
print("matched_count:", inserted_data_line.matched_count)"""
else:
inserted_data_line = MYSY_GV.dbname['partner_order_line'].update_many(
{'partner_owner_recid': str(my_partner['recid']),
'valide': '1', 'locked': '0',
'order_header_id': str(order_header_id)
},
{
"$set": {"order_line_status": str(order_header_status), 'date_update': str(data['date_update'])}
})
"""print("raw:", inserted_data_line.raw_result)
print("acknowledged:", inserted_data_line.acknowledged)
print("matched_count:", inserted_data_line.matched_count)"""
return True, " Le devis a été correctement mis à jour"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de mettre à jour le devis "
"""
Fonction ajoute des lignes à une commande qui existe.
Clé :
@ -1242,7 +1736,7 @@ def Add_Update_Partner_Order_Line(diction):
field_list = ['token', 'order_line_formation', 'order_line_qty', 'order_line_prix_unitaire',
'order_line_tax', 'order_line_type_reduction', 'order_line_type_valeur',
'order_line_montant_reduction', 'order_line_id', 'order_header_ref_interne',
'order_header_id']
'order_header_id', 'order_line_status', 'order_line_type']
incom_keys = diction.keys()
for val in incom_keys:
@ -1255,7 +1749,8 @@ def Add_Update_Partner_Order_Line(diction):
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', 'order_line_formation', "order_line_qty", "order_line_prix_unitaire",
'order_line_id', 'order_header_ref_interne', 'order_header_id']
'order_line_id', 'order_header_ref_interne', 'order_header_id',
'order_line_status', 'order_line_type']
for val in field_list_obligatoire:
if val not in diction:
@ -1285,6 +1780,41 @@ def Add_Update_Partner_Order_Line(diction):
order_line_formation = diction['order_line_formation']
data['order_line_formation'] = order_line_formation
order_line_type = ""
if ("order_line_type" in diction.keys()):
if diction['order_line_type']:
order_line_type = diction['order_line_type']
data['order_line_type'] = order_line_type
if( order_line_type not in MYSY_GV.PARTNER_ORDER_TYPE):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur du champ 'order_line_type' est invalide. Les valeurs acceptées :"+str(MYSY_GV.PARTNER_ORDER_TYPE))
return False, " La valeur du champ 'order_line_type' est invalide. Les valeurs acceptées :"+str(MYSY_GV.PARTNER_ORDER_TYPE)
order_line_status = ""
if ("order_line_status" in diction.keys()):
if diction['order_line_status']:
order_line_status = diction['order_line_status']
data['order_line_status'] = order_line_status
if( order_line_type == "commansde"):
if (order_line_status not in MYSY_GV.PARTNER_ORDER_STATUS):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - La valeur du champ 'order_line_type' est invalide. Les valeurs acceptées :" + str(
MYSY_GV.PARTNER_ORDER_STATUS))
return False, " La valeur du champ 'order_line_type' est invalide. Les valeurs acceptées :" + str(
MYSY_GV.PARTNER_ORDER_STATUS)
if (order_line_type == "devis"):
if (order_line_status not in MYSY_GV.PARTNER_QUOTATION_STATUS):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - La valeur du champ 'order_line_type' est invalide. Les valeurs acceptées :" + str(
MYSY_GV.PARTNER_QUOTATION_STATUS))
return False, " La valeur du champ 'order_line_type' est invalide. Les valeurs acceptées :" + str(
MYSY_GV.PARTNER_QUOTATION_STATUS)
order_line_qty = ""
if ("order_line_qty" in diction.keys()):
if diction['order_line_qty']:
@ -1638,7 +2168,7 @@ def Delete_Partner_Order_Line(diction):
Pour un debut pas de facturation partielle. c'est tout ou rien.
"""
my_order_data_count = MYSY_GV.dbname['partner_order_line'].count_documents(
{'partner_owner_recid': str(my_partner['recid']),
{'partner_owner_recid': str(my_partner['recid']), 'order_header_id':str(diction['order_header_id']),
'valide': '1', 'locked': '0',
'_id': ObjectId(str(order_line_id))})
@ -1649,8 +2179,8 @@ def Delete_Partner_Order_Line(diction):
delete_data = MYSY_GV.dbname['partner_order_header'].delete_one(
{'partner_owner_recid': str(my_partner['recid']),
delete_data = MYSY_GV.dbname['partner_order_line'].delete_one(
{'partner_owner_recid': str(my_partner['recid']), 'order_header_id':str(diction['order_header_id']),
'_id': ObjectId(str(order_line_id))} )
@ -1734,11 +2264,36 @@ def Get_Given_Partner_Order(diction):
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
# Si le champ 'order_header_client_id' alors on va chercher le nom du client
if ('order_header_client_id' in retval.keys()):
Client_data = MYSY_GV.dbname['partner_client'].find_one(
{'_id': ObjectId(str(retval['order_header_client_id'])), 'valide': '1', 'locked': '0',
'partner_recid': str(my_partner['recid'])})
if (Client_data and 'nom' in Client_data.keys()):
user['order_header_client_nom'] = str(Client_data['nom'])
# Si le champ 'order_header_vendeur_id' alors on va chercher le nom et prenom du vendeur (employe)
if ('order_header_vendeur_id' in retval.keys()):
Employee_data = MYSY_GV.dbname['ressource_humaine'].find_one(
{'_id': ObjectId(str(retval['order_header_vendeur_id'])), 'valide': '1', 'locked': '0',
'partner_recid': str(my_partner['recid'])})
order_header_vendeur_nom_prenom = ""
if (Employee_data and 'nom' in Employee_data.keys()):
order_header_vendeur_nom_prenom = str(Employee_data['nom'])
if (Employee_data and 'prenom' in Employee_data.keys()):
order_header_vendeur_nom_prenom = str(order_header_vendeur_nom_prenom) + " " + str(
Employee_data['prenom'])
user['order_header_vendeur_nom_prenom'] = str(order_header_vendeur_nom_prenom)
# Recuperation des ligne associées
retval_line_data = []
for retval_line in MYSY_GV.dbname['partner_order_line'].find({'order_header_id':str(retval['_id']), 'partner_owner_recid':str(my_partner['recid']),
'valide':'1', 'locked':'0'}):
retval_line_data.append(retval_line)