Elyos_FI_Back_Office/partner_order.py

2855 lines
134 KiB
Python

"""
Ce fichier permet de gerer les devis et les commandes d'un partenaires.
Pour précision, une commande a les status suivants :
- devis
- Commande
- Facturé
- Annulé
Une commande est defini par
order_header et order_lines comme suit :
order {order_header_ref:'xxx', order_header_amount:'yyyy', order_line[ {order_line1}, {order_line2}, ....,{}] }
"""
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
"""
Creation d'un commande client d'un partenaire
Order_type = 'commande'
"""
def Add_Partner_Order(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_lines', 'order_header_type']
"""
/!\ A noter que "order_lines" est tableau [] qui peut contenir les keys suivantes : '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'
ainsi, order_lines sera du style order_lines[ {order_line_formation:'xxx', order_line_qty:'2', etc }, {order_line_formation:'yyy', order_line_qty:'7', etc }, ....{}}
"""
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"]
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
# Recuperation des champs
data = {}
data['partner_owner_recid'] = my_partner['recid']
data['order_header_type'] = "commande"
order_header_client_id = ""
if ("order_header_client_id" in diction.keys()):
if diction['order_header_client_id']:
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()):
if diction['order_header_description']:
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_comment = ""
if ("order_header_comment" in diction.keys()):
if diction['order_header_comment']:
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()):
if diction['order_header_condition_paiement']:
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']
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()):
if diction['order_header_ref_externe']:
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()):
if diction['order_header_vendeur_id']:
order_header_vendeur_id = diction['order_header_vendeur_id']
# 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()):
if diction['order_header_date_expiration']:
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()):
if diction['order_header_adr_fact_adresse']:
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()):
if diction['order_header_adr_fact_code_postal']:
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()):
if diction['order_header_adr_fact_ville']:
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()):
if diction['order_header_adr_fact_pays']:
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()):
if diction['order_header_adr_liv_adresse']:
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()):
if diction['order_header_adr_liv_code_postal']:
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()):
if diction['order_header_adr_liv_ville']:
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()):
if diction['order_header_adr_liv_pays']:
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']
"""
Recuperation des lignes de commande
"""
data_order_lines = []
if( "order_lines" in diction.keys()):
# JSON.loads prends les variable entre double quote. on va donc remplacer les eventuels simple quote par des doubles quotes
data_order_lines = json.loads(str(diction['order_lines']).replace("'", '"'))
for order_line in data_order_lines:
# Verifier les champs acceptés et champs obligatoires pour une ligne de commande
"""
Verification des input acceptés
"""
field_list = ['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']
print(" ### order_line = ", order_line)
incom_keys = order_line.keys()
for val in incom_keys:
if val not in field_list:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Line de commande : Le champ '" + val + "' n'est pas autorisé")
return False, " Line de commande : Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['order_line_formation', "order_line_qty", "order_line_prix_unitaire"]
for val in field_list_obligatoire:
if val not in order_line:
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Line de commande : La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Line de commande : Les informations fournies sont incorrectes",
"""
/!\ : A present que tous les controles sont ok, on va proceder à la creation dans les table.
"""
### 1 - Creation de l'entete
# Rcuperation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
retval_sequence_order = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object': 'partner_order_header',
'valide': '1', 'partner_owner_recid':str(my_partner['recid'])})
if (retval_sequence_order is None or "current_val" not in retval_sequence_order.keys()):
mycommon.myprint(" Impossible de recuperer la sequence 'retval_sequence_order' ")
return False, "Impossible de recuperer la sequence 'retval_sequence_order'"
current_seq_value = str(retval_sequence_order['current_val'])
new_sequence_value = int(mycommon.tryInt(current_seq_value)) + 1
# /!\ Affectation de la reference interne de la commande
data['order_header_ref_interne'] = retval_sequence_order['prefixe']+str(current_seq_value)
print(" #### diction['order_header_ref_interne'] = ", str( data['order_header_ref_interne']))
## Verifier qu'il n'y pas une commande avec la meme reference interne
existe_cmd_ref_interne_count = MYSY_GV.dbname['partner_order_header'].count_documents({'order_header_ref_interne':str(data['order_header_ref_interne'])})
if( existe_cmd_ref_interne_count > 0):
mycommon.myprint(
" Il existe déjà une commande avec la même reference interne "+str(data['order_header_ref_interne']))
return False, " Il existe déjà une commande avec la même reference interne "+str(data['order_header_ref_interne'])+" "
data['valide'] = '1'
data['locked'] = '0'
data['date_update'] = str(datetime.now())
print(" ### add_partner_order data = ", data)
inserted_id = ""
inserted_id = MYSY_GV.dbname['partner_order_header'].insert_one(data).inserted_id
if (not inserted_id):
mycommon.myprint(
" Impossible de créer l'entete de la commande ")
return False, "Impossible de créer l'entete de la commande "
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_order['_id'])), 'valide': '1'},
{"$set": new_sequance_data_to_update},
return_document=ReturnDocument.AFTER,
upsert=False,
)
tmp_val = str(inserted_id)
print(" ### inserted_id = ", str(tmp_val))
### 2 - Creation des lignes
data_order_lines = []
if ("order_lines" in diction.keys()):
# JSON.loads prends les variable entre double quote. on va donc remplacer les eventuels simple quote par des doubles quotes
data_order_lines = json.loads(str(diction['order_lines']).replace("'", '"'))
for order_line in data_order_lines:
order_line['order_header_id'] = str(tmp_val)
order_line['order_header_ref_interne'] = str(data['order_header_ref_interne'])
order_line['valide'] = '1'
order_line['locked'] = '0'
order_line['date_update'] = str(datetime.now())
order_line['partner_owner_recid'] = my_partner['recid']
inserted_line_id = ""
inserted_line_id = MYSY_GV.dbname['partner_order_line'].insert_one(order_line).inserted_id
if (not inserted_line_id):
mycommon.myprint(
" Impossible de créer la ligne la commande ")
return False, " Impossible de créer la ligne la commande "
return True, " La commande a été correctement créée"
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 la commande "
"""
Creation d'un devis client d'un partenaire
Order_Type = 'devis'
"""
def Add_Partner_Quotation(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_lines',
'order_header_type']
"""
/!\ A noter que "order_lines" est tableau [] qui peut contenir les keys suivantes : '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'
ainsi, order_lines sera du style order_lines[ {order_line_formation:'xxx', order_line_qty:'2', etc }, {order_line_formation:'yyy', order_line_qty:'7', etc }, ....{}}
"""
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"]
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
# Recuperation des champs
data = {}
data['partner_owner_recid'] = my_partner['recid']
data['order_header_type'] = "devis"
order_header_client_id = ""
if ("order_header_client_id" in diction.keys()):
if diction['order_header_client_id']:
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()):
if diction['order_header_description']:
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']
else:
data['order_header_status'] = "0"
order_header_comment = ""
if ("order_header_comment" in diction.keys()):
if diction['order_header_comment']:
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()):
if diction['order_header_condition_paiement']:
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']
order_header_ref_externe = ""
if ("order_header_ref_externe" in diction.keys()):
if diction['order_header_ref_externe']:
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()):
if diction['order_header_vendeur_id']:
order_header_vendeur_id = diction['order_header_vendeur_id']
# 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()):
if diction['order_header_date_expiration']:
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()):
if diction['order_header_adr_fact_adresse']:
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()):
if diction['order_header_adr_fact_code_postal']:
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()):
if diction['order_header_adr_fact_ville']:
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()):
if diction['order_header_adr_fact_pays']:
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()):
if diction['order_header_adr_liv_adresse']:
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()):
if diction['order_header_adr_liv_code_postal']:
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()):
if diction['order_header_adr_liv_ville']:
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()):
if diction['order_header_adr_liv_pays']:
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']
"""
Recuperation des lignes de commande
"""
data_order_lines = []
if ("order_lines" in diction.keys()):
# JSON.loads prends les variable entre double quote. on va donc remplacer les eventuels simple quote par des doubles quotes
data_order_lines = json.loads(str(diction['order_lines']).replace("'", '"'))
for order_line in data_order_lines:
# Verifier les champs acceptés et champs obligatoires pour une ligne de commande
"""
Verification des input acceptés
"""
field_list = ['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']
print(" ### order_line = ", order_line)
incom_keys = order_line.keys()
for val in incom_keys:
if val not in field_list:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Line de commande : Le champ '" + val + "' n'est pas autorisé")
return False, " Line de commande : Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['order_line_formation', "order_line_qty", "order_line_prix_unitaire"]
for val in field_list_obligatoire:
if val not in order_line:
mycommon.myprint(
str(inspect.stack()[0][
3]) + " - Line de commande : La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Line de commande : Les informations fournies sont incorrectes",
"""
/!\ : A present que tous les controles sont ok, on va proceder à la creation dans les table.
"""
### 1 - Creation de l'entete
# Rcuperation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
retval_sequence_order = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object': 'partner_quotation_header',
'valide': '1', 'partner_owner_recid': str(
my_partner['recid'])})
if (retval_sequence_order is None or "current_val" not in retval_sequence_order.keys()):
mycommon.myprint(" Impossible de recuperer la sequence 'retval_sequence_order' ")
return False, "Impossible de recuperer la sequence 'retval_sequence_order'"
current_seq_value = str(retval_sequence_order['current_val'])
new_sequence_value = int(mycommon.tryInt(current_seq_value)) + 1
# /!\ Affectation de la reference interne de la commande
data['order_header_ref_interne'] = retval_sequence_order['prefixe'] + str(current_seq_value)
print(" #### diction['order_header_ref_interne'] = ", str(data['order_header_ref_interne']))
## Verifier qu'il n'y pas une commande avec la meme reference interne
existe_cmd_ref_interne_count = MYSY_GV.dbname['partner_order_header'].count_documents(
{'order_header_ref_interne': str(data['order_header_ref_interne'])})
if (existe_cmd_ref_interne_count > 0):
mycommon.myprint(
" Il existe déjà une commande avec la même reference interne " + str(data['order_header_ref_interne']))
return False, " Il existe déjà une commande avec la même reference interne " + str(
data['order_header_ref_interne']) + " "
data['valide'] = '1'
data['locked'] = '0'
data['date_update'] = str(datetime.now())
print(" ### add_partner_order data = ", data)
inserted_id = ""
inserted_id = MYSY_GV.dbname['partner_order_header'].insert_one(data).inserted_id
if (not inserted_id):
mycommon.myprint(
" Impossible de créer l'entete de la commande ")
return False, "Impossible de créer l'entete de la commande "
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_order['_id'])), 'valide': '1'},
{"$set": new_sequance_data_to_update},
return_document=ReturnDocument.AFTER,
upsert=False,
)
tmp_val = str(inserted_id)
print(" ### inserted_id = ", str(tmp_val))
### 2 - Creation des lignes
data_order_lines = []
if ("order_lines" in diction.keys()):
# JSON.loads prends les variable entre double quote. on va donc remplacer les eventuels simple quote par des doubles quotes
data_order_lines = json.loads(str(diction['order_lines']).replace("'", '"'))
for order_line in data_order_lines:
order_line['order_header_id'] = str(tmp_val)
order_line['order_header_ref_interne'] = str(data['order_header_ref_interne'])
order_line['valide'] = '1'
order_line['locked'] = '0'
order_line['date_update'] = str(datetime.now())
order_line['partner_owner_recid'] = my_partner['recid']
inserted_line_id = ""
inserted_line_id = MYSY_GV.dbname['partner_order_line'].insert_one(order_line).inserted_id
if (not inserted_line_id):
mycommon.myprint(
" Impossible de créer la ligne la commande ")
return False, " Impossible de créer la ligne la commande "
return True, " La commande a été correctement créée"
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 la commande "
"""
Fonction de mise à jour d'une entete commande client d'un partner.
Les ligne sont mise à jour avec une fonction à part entière
On se base sur l' '_id' du header et le token pour faire la mise à jour
"""
def Update_Partner_Order_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':'commande',
'_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': 'commande',
'_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_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']
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':'commande',
'_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 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:
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 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é :
- order_header_id
- order_header_ref_interne
- partner_owner_recid
"""
def Add_Update_Partner_Order_Line(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
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_line_status', 'order_line_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'existe pas")
return False, " Les informations fournies sont incorrectes",
"""
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_status', 'order_line_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
data = {}
order_line_formation = ""
if ("order_line_formation" in diction.keys()):
if diction['order_line_formation']:
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']:
order_line_qty = diction['order_line_qty']
data['order_line_qty'] = order_line_qty
order_line_prix_unitaire = ""
if ("order_line_prix_unitaire" in diction.keys()):
if diction['order_line_prix_unitaire']:
order_line_prix_unitaire = diction['order_line_prix_unitaire']
data['order_line_prix_unitaire'] = order_line_prix_unitaire
order_line_tax = ""
if ("order_line_tax" in diction.keys()):
if diction['order_line_tax']:
order_line_tax = diction['order_line_tax']
data['order_line_tax'] = order_line_tax
order_line_type_reduction = ""
if ("order_line_type_reduction" in diction.keys()):
if diction['order_line_type_reduction']:
order_line_type_reduction = diction['order_line_type_reduction']
data['order_line_type_reduction'] = order_line_type_reduction
order_line_type_valeur = ""
if ("order_line_type_valeur" in diction.keys()):
if diction['order_line_type_valeur']:
order_line_type_valeur = diction['order_line_type_valeur']
data['order_line_type_valeur'] = order_line_type_valeur
order_line_montant_reduction = ""
if ("order_line_montant_reduction" in diction.keys()):
if diction['order_line_montant_reduction']:
order_line_montant_reduction = diction['order_line_montant_reduction']
data['order_line_montant_reduction'] = order_line_montant_reduction
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']
data['order_header_ref_interne'] = order_header_ref_interne
order_header_id = ""
if ("order_header_id" in diction.keys()):
if diction['order_header_id']:
order_header_id = diction['order_header_id']
data['order_header_id'] = order_header_id
order_line_id = ""
if ("order_line_id" in diction.keys()):
if diction['order_line_id']:
# il s'agit de mettre à jour la ligne. Il faut verifier que la ligne existe et est modifiable
order_line_id = diction['order_line_id']
existe_order_line_count = MYSY_GV.dbname['partner_order_line'].count_documents({'_id':ObjectId(str(order_line_id)), 'valide':'1', 'locked':'0',
'partner_owner_recid':str(my_partner['recid'])})
if( existe_order_line_count != 1 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La ligne à mettre à jour est invalide")
return False, "La ligne à mettre à jour est invalide",
data['date_update'] = str(datetime.now())
inserted_data = MYSY_GV.dbname['ressource_humaine_affectation'].find_one_and_update(
{'_id': ObjectId(str(order_line_id)), 'valide': '1', 'locked': '0',
'partner_owner_recid': str(my_partner['recid'])},
{"$set": data},
return_document=ReturnDocument.AFTER,
upsert=False,
)
if (inserted_data is None):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - Impossible de mettre à jour la ligne (3)")
return False, " Impossible de mettre à jour la ligne (3) "
else:
# Il s'agit d'une creation d'une nouvelle ligne
data['valide'] = '1'
data['locked'] = '0'
data['date_update'] = str(datetime.now())
data['partner_owner_recid'] = my_partner['recid']
inserted_line_id = ""
inserted_line_id = MYSY_GV.dbname['partner_order_line'].insert_one(data).inserted_id
if (not inserted_line_id):
mycommon.myprint(
" Impossible de créer la ligne la commande ")
return False, " Impossible de créer la ligne la commande "
return True, " La ligne de commande a été correctement ajoutée/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 créer / mettre à jour la ligne de commande "
"""
Fonction de suppression d'une commande client (entete et ligne) si son statut le permet en prenant le '_id'
"""
def Delete_Partner_Order_Header_And_Lines(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'order_header_id']
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_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",
"""
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 supprimable.
Pour les ligne, on fait pareil, on ne peut modifier que celles qui sont modifiable.
Conditions pour modifier entete :
1 - statut est : annulé, devis, cmd, MAIS PAS 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',
'_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 des champs
data = {}
data['partner_owner_recid'] = my_partner['recid']
delete_data = MYSY_GV.dbname['partner_order_header'].delete_one(
{'partner_owner_recid': str(my_partner['recid']),
'_id': ObjectId(str(order_header_id))}, )
if( delete_data is None or delete_data.deleted_count < 0 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - Impossible de supprimer la commande (2) ")
return False, " - Impossible de supprimer la commande (2) ",
# A present,suppression des lignes de la commande
delete_data_order_lines = MYSY_GV.dbname['partner_order_line'].delete_many(
{'partner_owner_recid': str(my_partner['recid']),
'order_header_id': str(order_header_id)}, )
return True, " La commande a été correctement supprimée"
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 supprimer la commande "
"""
Fonction de suppression d'une commande client (entete et ligne) si son statut le permet, en prenant le 'order_header_ref_interne'
"""
def Delete_Partner_Order_Header_And_Lines_From_order_reference(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'order_header_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",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', 'order_header_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",
"""
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_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']
"""
# Verifier que la commande existe et qu'elle est supprimable.
Pour les ligne, on fait pareil, on ne peut modifier que celles qui sont modifiable.
Conditions pour modifier entete :
1 - statut est : annulé, devis, cmd, MAIS PAS 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_ref_interne': str(order_header_ref_interne)})
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",
delete_data = MYSY_GV.dbname['partner_order_header'].delete_one(
{'partner_owner_recid': str(my_partner['recid']),
'order_header_ref_interne': str(order_header_ref_interne)}, )
if( delete_data is None or delete_data.deleted_count < 0 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - Impossible de supprimer la commande (2) ")
return False, " - Impossible de supprimer la commande (2) ",
# A present,suppression des lignes de la commande
delete_data_order_lines = MYSY_GV.dbname['partner_order_line'].delete_many(
{'partner_owner_recid': str(my_partner['recid']),
'order_header_ref_interne': str(order_header_ref_interne)}, )
return True, " La commande a été correctement supprimée"
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 supprimer la commande "
"""
Fonction de suppression d'une ligne d'une commande
"""
def Delete_Partner_Order_Line(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'order_header_id', 'order_line_id']
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_id', 'order_line_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",
"""
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_line_id = ""
if ("order_line_id" in diction.keys()):
if diction['order_line_id']:
order_line_id = diction['order_line_id']
"""
# Verifier que la commande existe et qu'elle est supprimable.
Pour les ligne, on fait pareil, on ne peut modifier que celles qui sont modifiable.
Conditions pour modifier entete :
1 - statut est : annulé, devis, cmd, MAIS PAS FACTURE
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']), 'order_header_id':str(diction['order_header_id']),
'valide': '1', 'locked': '0',
'_id': ObjectId(str(order_line_id))})
if (my_order_data_count != 1):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'identifiant de la ligne est invalide ")
return False, " L'identifiant de la ligne est invalide",
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))} )
if( delete_data is None or delete_data.deleted_count < 0 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - Impossible de supprimer la ligne de commande (2) ")
return False, " - Impossible de supprimer la ligne de commande (2) ",
return True, " La ligne de la commande a été correctement supprimée"
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 supprimer la ligne de la commande"
"""
Recuperation d'une commande donnée à partir du '_id'
"""
def Get_Given_Partner_Order(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:
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']
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
"""
Clés de mise à jour
"""
data_cle = {}
data_cle['partner_owner_recid'] = str(my_partner['recid'])
data_cle['_id'] = ObjectId(str(diction['_id']))
data_cle['valide'] = "1"
data_cle['locked'] = "0"
RetObject = []
val_tmp = 1
#print(" ### data_cle = ", data_cle)
for retval in MYSY_GV.dbname['partner_order_header'].find(data_cle):
user = retval
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)
RetObject.append(mycommon.JSONEncoder().encode(user))
#print(" ### RetObject = ", RetObject)
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 recuperer les données de la commande "
"""
Recuperation des lignes d'une commande à partir de l'order_header_id, sans entete
"""
def Get_Given_Partner_Order_Lines(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'order_header_id']
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'existe pas")
return False, " Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', 'order_header_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",
"""
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
"""
Clés de mise à jour
"""
data_cle = {}
data_cle['partner_owner_recid'] = str(my_partner['recid'])
data_cle['order_header_id'] = str(diction['order_header_id'])
data_cle['valide'] = "1"
data_cle['locked'] = "0"
RetObject = []
val_tmp = 1
#print(" ### data_cle = ", data_cle)
for retval in MYSY_GV.dbname['partner_order_line'].find(data_cle):
user = retval
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
#print(" ### RetObject = ", RetObject)
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 recuperer les lignes de commande "
"""
Recuperation des lignes d'une commande à partir de l' order_header_ref_interne, sans entete
"""
def Get_Given_Partner_Order_Lines_From_order_ref_interne(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'order_header_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'existe pas")
return False, " Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', 'order_header_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",
"""
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
"""
Clés de mise à jour
"""
data_cle = {}
data_cle['partner_owner_recid'] = str(my_partner['recid'])
data_cle['order_header_ref_interne'] = str(diction['order_header_ref_interne'])
data_cle['valide'] = "1"
data_cle['locked'] = "0"
RetObject = []
val_tmp = 1
#print(" ### data_cle = ", data_cle)
for retval in MYSY_GV.dbname['partner_order_line'].find(data_cle):
user = retval
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
#print(" ### RetObject = ", RetObject)
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 recuperer les lignes de commande "
"""
Recuperation d'un commande en partant de la reference interne et du token
"""
def Get_Given_Partner_Order_From_Internal_ref(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'internal_ref']
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'existe pas")
return False, " Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', 'internal_ref']
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
"""
Clés de mise à jour
"""
data_cle = {}
data_cle['partner_owner_recid'] = str(my_partner['recid'])
data_cle['order_header_ref_interne'] = str(diction['internal_ref'])
data_cle['valide'] = "1"
data_cle['locked'] = "0"
RetObject = []
val_tmp = 1
# print(" ### data_cle = ", data_cle)
for retval in MYSY_GV.dbname['partner_order_header'].find(data_cle):
user = retval
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)
RetObject.append(mycommon.JSONEncoder().encode(user))
# print(" ### RetObject = ", RetObject)
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 recuperer les données de la commande "
"""
Recuperation de la liste des commandes d'un partner
"""
def Get_List_Partner_Order_no_filter(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', ]
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'existe pas")
return False, " Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', ]
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
find_qry = {'$and': [{'partner_owner_recid': str(my_partner['recid']), 'valide': '1', 'locked': '0'}, {}, ]}
new_myquery_find_order = [{'$match': find_qry},
{"$addFields": {"partner_order_header_Id": {"$toString": "$_id"}}},
{'$lookup':
{
'from': 'partner_order_line',
'localField': "ressource_humaine_Id",
'foreignField': 'order_header_id',
'pipeline': [{'$match': {'$and': [{}, {
'partner_owner_recid': str(my_partner['recid'])}, {'valide': '1'}]}}, ],
'as': 'partner_order_line_collection'
}
}
]
print(" ### orders new_myquery_find_order = ", new_myquery_find_order)
RetObject = []
val_tmp = 1
for New_retVal in MYSY_GV.dbname['partner_order_header'].aggregate(new_myquery_find_order):
user = New_retVal
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 New_retVal.keys()):
Client_data = MYSY_GV.dbname['partner_client'].find_one({'_id':ObjectId(str(New_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 New_retVal.keys()):
Employee_data = MYSY_GV.dbname['ressource_humaine'].find_one(
{'_id': ObjectId(str(New_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)
RetObject.append(mycommon.JSONEncoder().encode(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 recuperer la liste des commandes "
"""
Recuperation de la liste des commandes avec des filtres.
les filtres acceptés sont :
- ref_interne
- ref_externe
- date_cmd entre date_debut et date_fin
- nom_client
"""
def Get_List_Partner_Order_with_filter(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés. les filtres accepté sont :
- ref_interne,
"""
field_list = ['token', 'date_cmd_debut', 'date_cmd_fin', 'client_nom', 'ref_interne', 'ref_externe']
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'existe pas")
return False, " Les informations fournies sont incorrectes",
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', ]
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
filt_client_nom = {}
sub_filt_client_nom = {}
Lists_partner_client_id = []
if ("client_nom" in diction.keys()):
sub_filt_client_nom = {'nom': {'$regex': str(diction['client_nom']), "$options": "i"}, 'partner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'}
# Recuperation des '_id' des clients dont le nom match en regexp
#print(" ### sub_filt_client_nom = ", sub_filt_client_nom)
for List_Client_Data in MYSY_GV.dbname['partner_client'].find(sub_filt_client_nom, {'_id':1}):
Lists_partner_client_id.append(str(List_Client_Data['_id']))
filt_client_nom = {'order_header_client_id': {'$in': Lists_partner_client_id, }}
#print(' ### filt_client_nom = ', filt_client_nom)
filt_ref_interne = {}
if ("ref_interne" in diction.keys()):
filt_ref_interne = {
'order_header_ref_interne': {'$regex': str(diction['ref_interne']), "$options": "i"}}
filt_ref_externe = {}
if ("ref_externe" in diction.keys()):
filt_ref_externe = {
'order_header_ref_client': {'$regex': str(diction['ref_externe']), "$options": "i"}}
find_qry = {'$and': [{'partner_owner_recid': str(my_partner['recid']), 'valide': '1', 'locked': '0'}, filt_client_nom, filt_ref_interne, filt_ref_externe]}
new_myquery_find_order = [{'$match': find_qry},
{"$addFields": {"partner_order_header_Id": {"$toString": "$_id"}}},
{'$lookup':
{
'from': 'partner_order_line',
'localField': "ressource_humaine_Id",
'foreignField': 'order_header_id',
'pipeline': [{'$match': {'$and': [{}, {
'partner_owner_recid': str(my_partner['recid'])}, {'valide': '1'}]}}, ],
'as': 'partner_order_line_collection'
}
}
]
print(" ### Get_List_Partner_Order_with_filter orders new_myquery_find_order = ", new_myquery_find_order)
RetObject = []
val_tmp = 1
filter_date_debut = ""
if ("date_cmd_debut" in diction.keys()):
if diction['date_cmd_debut']:
filter_date_debut = str(diction['date_cmd_debut'])[0:10]
local_status = mycommon.CheckisDate(filter_date_debut)
if (local_status is False):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " La date de debut (filtre) n'est pas au format 'jj/mm/aaaa' ")
return False, " La date de debut (filtre) n'est pas au format 'jj/mm/aaaa'"
filter_date_fin = ""
if ("date_cmd_fin" in diction.keys()):
if diction['date_cmd_fin']:
filter_date_fin = str(diction['date_cmd_fin'])[0:10]
local_status = mycommon.CheckisDate(filter_date_fin)
if (local_status is False):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " La date de fin (filtre) n'est pas au format 'jj/mm/aaaa' ")
return False, " La date de fin (filtre) n'est pas au format 'jj/mm/aaaa'"
for New_retVal in MYSY_GV.dbname['partner_order_header'].aggregate(new_myquery_find_order):
user = New_retVal
# Si le champ 'order_header_client_id' alors on va chercher le nom du client
if ('order_header_client_id' in New_retVal.keys()):
Client_data = MYSY_GV.dbname['partner_client'].find_one(
{'_id': ObjectId(str(New_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 New_retVal.keys()):
Employee_data = MYSY_GV.dbname['ressource_humaine'].find_one(
{'_id': ObjectId(str(New_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)
if( filter_date_debut and filter_date_fin ):
if ( datetime.strptime(str(New_retVal['order_header_date_cmd'])[0:10], '%d/%m/%Y') >= datetime.strptime(str(filter_date_debut)[0:10], '%d/%m/%Y') and
datetime.strptime(str(New_retVal['order_header_date_cmd'])[0:10], '%d/%m/%Y') <= datetime.strptime(str(filter_date_fin)[0:10], '%d/%m/%Y') ):
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
elif ( filter_date_debut ):
if ( datetime.strptime(str(New_retVal['order_header_date_cmd'])[0:10], '%d/%m/%Y') >= datetime.strptime(str(filter_date_debut)[0:10], '%d/%m/%Y') ):
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
elif ( filter_date_fin ):
if ( datetime.strptime(str(New_retVal['order_header_date_cmd'])[0:10], '%d/%m/%Y') <= datetime.strptime(str(filter_date_fin)[0:10], '%d/%m/%Y') ):
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
else:
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(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 recuperer la liste des commandes "