242 lines
8.5 KiB
Python
242 lines
8.5 KiB
Python
"""
|
|
Ce fichier permet de gerer tout qui est lié aux client d'un partenaire.
|
|
|
|
Cas d'utilisation :
|
|
Un partenaire de mysy, souhaite créer (CRUD) ses clients
|
|
Emettre des devis, bons de commandes, des factures, etc....
|
|
"""
|
|
|
|
import pymongo
|
|
from pymongo import MongoClient
|
|
import json
|
|
from bson import ObjectId
|
|
import re
|
|
from datetime import datetime
|
|
import prj_common as mycommon
|
|
import secrets
|
|
import inspect
|
|
import sys, os
|
|
import csv
|
|
import pandas as pd
|
|
from pymongo import ReturnDocument
|
|
import GlobalVariable as MYSY_GV
|
|
from math import isnan
|
|
import GlobalVariable as MYSY_GV
|
|
import ela_index_bdd_classes as eibdd
|
|
import email_mgt as email
|
|
import ast
|
|
|
|
def Add_Partner_Client(diction):
|
|
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "raison_sociale", "nom", "siret", "tva", "email",
|
|
"telephone", "website", "comment", "address", "invoice_address", "list_contact", ]
|
|
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', "raison_sociale", "nom", "email", "telephone", "address", ]
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
|
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire. "
|
|
|
|
|
|
"""
|
|
Verification s'il n'existe pas un cient du partenaire qui perte le meme
|
|
nom, ou la meme adresse email
|
|
"""
|
|
|
|
qry = {'nom': str(diction['nom']), 'valide': '1', 'partner_recid': str(my_partner['recid'])}
|
|
print(" ### qry = ", qry)
|
|
|
|
tmp_count = MYSY_GV.dbname['partner_client'].count_documents(qry)
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Cet appel d'offre est deja enregistré : nom = ", str(diction['nom']))
|
|
|
|
return False, " - Il existe déjà un client qui porte le même nom "
|
|
|
|
tmp_count = MYSY_GV.dbname['partner_client'].count_documents({'email': str(diction['email']),
|
|
'valide': '1', 'partner_recid': my_partner['recid']})
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Cet appel d'offre est deja enregistré : email = ", str(diction['email']))
|
|
|
|
return False, " - Il existe déjà un client qui porte le même email principal "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
data = {}
|
|
data['partner_recid'] = my_partner['recid']
|
|
|
|
raison_sociale = ""
|
|
if ("raison_sociale" in diction.keys()):
|
|
if diction['raison_sociale']:
|
|
raison_sociale = diction['raison_sociale']
|
|
data['raison_sociale'] = diction['raison_sociale']
|
|
|
|
nom = ""
|
|
if ("nom" in diction.keys()):
|
|
if diction['nom']:
|
|
nom = diction['nom']
|
|
data['nom'] = diction['nom']
|
|
|
|
siret = ""
|
|
if ("siret" in diction.keys()):
|
|
if diction['siret']:
|
|
siret = diction['siret']
|
|
data['siret'] = diction['siret']
|
|
|
|
tva = ""
|
|
if ("tva" in diction.keys()):
|
|
if diction['tva']:
|
|
tva = diction['tva']
|
|
data['tva'] = diction['tva']
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
email = diction['email']
|
|
data['email'] = diction['email']
|
|
|
|
website = ""
|
|
if ("website" in diction.keys()):
|
|
if diction['website']:
|
|
website = diction['website']
|
|
data['website'] = diction['website']
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
comment = diction['comment']
|
|
data['comment'] = diction['comment']
|
|
|
|
address = {}
|
|
if ("address" in diction.keys()):
|
|
if diction['address']:
|
|
address = ast.literal_eval(diction['address'])
|
|
data['address'] = ast.literal_eval(diction['address'])
|
|
|
|
invoice_address = {}
|
|
if ("invoice_address" in diction.keys()):
|
|
if diction['invoice_address']:
|
|
invoice_address = ast.literal_eval(diction['invoice_address'])
|
|
data['invoice_address'] = ast.literal_eval(diction['invoice_address'])
|
|
|
|
list_contact = ""
|
|
if ("list_contact" in diction.keys()):
|
|
if diction['list_contact']:
|
|
list_contact = diction['list_contact']
|
|
data['list_contact'] = diction['list_contact']
|
|
|
|
|
|
""""
|
|
/!\ : l'adresse etant directement enregistrée sur le client, alors verification que le ligne "adresse" contient bien les champs :
|
|
- adresse, code postal, ville, pays
|
|
"""
|
|
|
|
|
|
adresse_field_list_obligatoire = ['adresse', "code_postal", "ville", "pays", ]
|
|
for val in adresse_field_list_obligatoire:
|
|
if val not in address.keys():
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le champ '" + val + "' est obligatoire dans l'adresse")
|
|
return False, " Le champ '" + val + "' est obligatoire dans l'adresse",
|
|
|
|
|
|
print(" les info client à enregistrer : ", str(data))
|
|
|
|
return True, " Le client a été correctement créé"
|
|
|
|
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 d'ajouter le client "
|
|
|
|
"""
|
|
Mise à jour d'un client
|
|
"""
|
|
def Update_Partner_Client(diction):
|
|
try:
|
|
|
|
return True, " Le client 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 le client "
|
|
|
|
|
|
"""
|
|
Recuperation d'une liste de client d'un partenaire
|
|
"""
|
|
|
|
def Get_Partner_List_Partner_Client(diction):
|
|
try:
|
|
|
|
return True, " Le client 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 le client "
|
|
|
|
|
|
"""
|
|
Recuperation d'un client donnée
|
|
"""
|
|
def Get_Given_Partner_List_Client(diction):
|
|
try:
|
|
|
|
return True, " Le client 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 le client "
|