3120 lines
124 KiB
Python
3120 lines
124 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 smtplib
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
|
|
import pymongo
|
|
from pandas.io.formats.style import jinja2
|
|
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
|
|
import Contact as contact
|
|
|
|
"""
|
|
Creation d'un client
|
|
"""
|
|
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", "list_contact",
|
|
'adr_adresse', 'adr_code_postal', 'adr_ville', 'adr_pays',
|
|
'invoice_email', 'invoice_nom', 'invoice_siret',
|
|
'invoice_tva', 'invoice_condition_paiement_id', 'invoice_adresse', 'invoice_ville',
|
|
'invoice_code_postal', 'invoice_pays', "client_type_id",
|
|
'is_fournisseur', 'is_client', 'is_financeur', 'is_company', 'invoice_automatique',
|
|
'type_financeur_id', 'type_pouvoir_public_id'
|
|
]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', "raison_sociale", "nom", "email", "telephone", ]
|
|
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 la liste des arguments ")
|
|
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 récupérer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer 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'])}
|
|
|
|
tmp_count = MYSY_GV.dbname['partner_client'].count_documents(qry)
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Il existe déjà un client qui porte le même nom = "+str(diction['nom']))
|
|
|
|
return False, " - Vous avez 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]) + " - Il existe déjà un client qui porte le même email principal = " +str(diction['email']))
|
|
|
|
return False, " - Vous avez déjà un client qui a 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'] = nom
|
|
|
|
siret = ""
|
|
if ("siret" in diction.keys()):
|
|
if diction['siret']:
|
|
siret = diction['siret']
|
|
data['siret'] = siret
|
|
|
|
client_type_id = ""
|
|
if ("client_type_id" in diction.keys()):
|
|
if diction['client_type_id']:
|
|
client_type_id = diction['client_type_id']
|
|
data['client_type_id'] = client_type_id
|
|
|
|
is_company = "0"
|
|
if ("is_company" in diction.keys()):
|
|
if diction['is_company']:
|
|
is_company = diction['is_company']
|
|
data['is_company'] = is_company
|
|
|
|
invoice_automatique = ""
|
|
if ("invoice_automatique" in diction.keys()):
|
|
if diction['invoice_automatique']:
|
|
invoice_automatique = diction['invoice_automatique']
|
|
data['invoice_automatique'] = invoice_automatique
|
|
|
|
|
|
is_fournisseur = ""
|
|
if ("is_fournisseur" in diction.keys() and diction['is_fournisseur']):
|
|
if (str(diction['is_fournisseur']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Fournisseur : La valeur " + str(
|
|
diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Fournisseur : La valeur " + str(
|
|
diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
is_fournisseur = str(diction['is_fournisseur'])
|
|
data['is_fournisseur'] = is_fournisseur
|
|
|
|
is_client = ""
|
|
if ("is_client" in diction.keys() and diction['is_client']):
|
|
if (str(diction['is_client']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
is_client = str(diction['is_client'])
|
|
data['is_client'] = is_client
|
|
|
|
is_financeur = ""
|
|
if ("is_financeur" in diction.keys() and diction['is_financeur']):
|
|
if (str(diction['is_financeur']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
|
|
is_financeur = str(diction['is_financeur'])
|
|
data['is_financeur'] = is_financeur
|
|
|
|
|
|
adr_adresse = ""
|
|
if ("adr_adresse" in diction.keys()):
|
|
if diction['adr_adresse']:
|
|
adr_adresse = diction['adr_adresse']
|
|
data['adr_adresse'] = adr_adresse
|
|
|
|
adr_code_postal = ""
|
|
if ("adr_code_postal" in diction.keys()):
|
|
if diction['adr_code_postal']:
|
|
adr_code_postal = diction['adr_code_postal']
|
|
data['adr_code_postal'] = adr_code_postal
|
|
|
|
adr_ville = ""
|
|
if ("adr_ville" in diction.keys()):
|
|
if diction['adr_ville']:
|
|
adr_ville = diction['adr_ville']
|
|
data['adr_ville'] = adr_ville
|
|
|
|
adr_pays = ""
|
|
if ("adr_pays" in diction.keys()):
|
|
if diction['adr_pays']:
|
|
adr_pays = diction['siret']
|
|
data['adr_pays'] = adr_pays
|
|
|
|
tva = ""
|
|
if ("tva" in diction.keys()):
|
|
if diction['tva']:
|
|
tva = diction['tva']
|
|
data['tva'] = tva
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
email = diction['email']
|
|
|
|
if( mycommon.isEmailValide(email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - L'adresse email "+str(email)+" n'est pas valide")
|
|
|
|
return False, " - L'adresse email "+str(email)+" n'est pas valide "
|
|
data['email'] = email
|
|
|
|
|
|
telephone = ""
|
|
if ("telephone" in diction.keys()):
|
|
if diction['telephone']:
|
|
telephone = diction['telephone']
|
|
data['telephone'] = telephone
|
|
|
|
|
|
website = ""
|
|
if ("website" in diction.keys()):
|
|
if diction['website']:
|
|
website = diction['website']
|
|
data['website'] = website
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
comment = diction['comment']
|
|
data['comment'] = comment
|
|
|
|
invoice_email = ""
|
|
if ("invoice_email" in diction.keys()):
|
|
if diction['invoice_email']:
|
|
invoice_email = diction['invoice_email']
|
|
|
|
if (mycommon.isEmailValide(invoice_email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - L'adresse email de facturation '" + str(invoice_email) + "' n'est pas valide")
|
|
|
|
return False, " - L'adresse email de facturation '" + str(invoice_email) + "' n'est pas valide "
|
|
data['invoice_email'] = invoice_email
|
|
|
|
type_financeur_id = ""
|
|
if ("type_financeur_id" in diction.keys()):
|
|
if (diction['type_financeur_id']):
|
|
type_financeur_id = diction['type_financeur_id']
|
|
|
|
is_valide_type_financeur_id_count = MYSY_GV.dbname['type_organisme_financement'].count_documents(
|
|
{'_id': ObjectId(str(diction['type_financeur_id'])),
|
|
'vallide': '1', 'locked': '0'})
|
|
|
|
if (is_valide_type_financeur_id_count != 0):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " L'identifiant du type de financeur est invalide ")
|
|
return False, " L'identifiant du type de financeur est invalide "
|
|
|
|
data['type_financeur_id'] = type_financeur_id
|
|
|
|
type_pouvoir_public_id = ""
|
|
if ("type_pouvoir_public_id" in diction.keys()):
|
|
if (diction['type_pouvoir_public_id']):
|
|
type_pouvoir_public_id = diction['type_pouvoir_public_id']
|
|
|
|
is_valide_type_pouvoir_public_id_count = MYSY_GV.dbname['type_pouvoir_public'].count_documents(
|
|
{'_id': ObjectId(str(diction['type_pouvoir_public_id'])),
|
|
'vallide': '1', 'locked': '0'})
|
|
|
|
if (is_valide_type_pouvoir_public_id_count != 0):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " L'identifiant du type de pouvoir public est invalide ")
|
|
return False, " L'identifiant du type de pouvoir public est invalide "
|
|
|
|
data['type_pouvoir_public_id'] = type_pouvoir_public_id
|
|
|
|
|
|
|
|
invoice_nom = ""
|
|
if ("invoice_nom" in diction.keys()):
|
|
if diction['invoice_nom']:
|
|
invoice_nom = diction['invoice_nom']
|
|
data['invoice_nom'] = invoice_nom
|
|
|
|
invoice_siret = ""
|
|
if ("invoice_siret" in diction.keys()):
|
|
if diction['invoice_siret']:
|
|
invoice_siret = diction['invoice_siret']
|
|
data['invoice_siret'] = invoice_siret
|
|
|
|
invoice_tva = ""
|
|
if ("invoice_tva" in diction.keys()):
|
|
if diction['invoice_tva']:
|
|
invoice_tva = diction['invoice_tva']
|
|
data['invoice_tva'] = invoice_tva
|
|
|
|
invoice_condition_paiement_id = ""
|
|
if ("invoice_condition_paiement_id" in diction.keys()):
|
|
if diction['invoice_condition_paiement_id']:
|
|
invoice_condition_paiement_id = diction['invoice_condition_paiement_id']
|
|
data['invoice_condition_paiement_id'] = invoice_condition_paiement_id
|
|
|
|
invoice_adresse = ""
|
|
if ("invoice_adresse" in diction.keys()):
|
|
if diction['invoice_adresse']:
|
|
invoice_adresse = diction['invoice_adresse']
|
|
data['invoice_adresse'] = invoice_adresse
|
|
|
|
invoice_ville = ""
|
|
if ("invoice_ville" in diction.keys()):
|
|
if diction['invoice_ville']:
|
|
invoice_ville = diction['invoice_ville']
|
|
data['invoice_ville'] =invoice_ville
|
|
|
|
invoice_code_postal = ""
|
|
if ("invoice_code_postal" in diction.keys()):
|
|
if diction['invoice_code_postal']:
|
|
invoice_code_postal = diction['invoice_code_postal']
|
|
data['invoice_code_postal'] = invoice_code_postal
|
|
|
|
invoice_pays = ""
|
|
if ("invoice_pays" in diction.keys()):
|
|
if diction['invoice_pays']:
|
|
invoice_pays = diction['invoice_pays']
|
|
data['invoice_pays'] = invoice_pays
|
|
|
|
list_adress = []
|
|
line = 0
|
|
if ("address" in diction.keys()):
|
|
if diction['address']:
|
|
list_adress = ast.literal_eval(diction['address'])
|
|
data['address'] = list_adress
|
|
for adress_val in list_adress :
|
|
#print(" ### adress_val = ", adress_val)
|
|
address = adress_val
|
|
data['address'][line]['recid'] = mycommon.create_user_recid()
|
|
line = line + 1
|
|
|
|
"""
|
|
/!\ : 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",
|
|
|
|
|
|
|
|
|
|
list_contact = ""
|
|
if ("list_contact" in diction.keys()):
|
|
if diction['list_contact']:
|
|
list_contact = diction['list_contact']
|
|
data['list_contact'] = list_contact
|
|
|
|
data['valide'] = '1'
|
|
data['locked'] = '0'
|
|
data['date_update'] = str(datetime.now())
|
|
data['update_by'] = str(my_partner['_id'])
|
|
|
|
# Creation du RecId
|
|
data['recid'] = mycommon.create_user_recid()
|
|
|
|
|
|
inserted_id = ""
|
|
inserted_id = MYSY_GV.dbname['partner_client'].insert_one(data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le client du partner ")
|
|
return False, " Impossible de créer le client "
|
|
|
|
|
|
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 "
|
|
|
|
|
|
|
|
"""
|
|
Creation d'un prospect
|
|
"""
|
|
def Add_Partner_Prospect(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", "list_contact",
|
|
'adr_adresse', 'adr_code_postal', 'adr_ville', 'adr_pays',
|
|
'invoice_email', 'invoice_nom', 'invoice_siret',
|
|
'invoice_tva', 'invoice_condition_paiement_id', 'invoice_adresse', 'invoice_ville',
|
|
'invoice_code_postal', 'invoice_pays', "client_type_id",
|
|
'is_fournisseur', 'is_client', 'is_financeur', 'is_company', 'invoice_automatique',
|
|
]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', "raison_sociale", "nom", "email", "telephone", ]
|
|
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 la liste des arguments ")
|
|
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 récupérer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer 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'])}
|
|
|
|
tmp_count = MYSY_GV.dbname['partner_client'].count_documents(qry)
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Il existe déjà un client qui porte le même nom = "+str(diction['nom']))
|
|
|
|
return False, " Vous avez 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]) + " - Il existe déjà un client qui porte le même email principal = " +str(diction['email']))
|
|
|
|
return False, " - Vous avez déjà un client qui a le même email principal "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
data = {}
|
|
data['partner_recid'] = my_partner['recid']
|
|
data['partner_owner_recid'] = my_partner['recid']
|
|
data['is_prospect'] = "1"
|
|
|
|
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'] = nom
|
|
|
|
siret = ""
|
|
if ("siret" in diction.keys()):
|
|
if diction['siret']:
|
|
siret = diction['siret']
|
|
data['siret'] = siret
|
|
|
|
client_type_id = ""
|
|
if ("client_type_id" in diction.keys()):
|
|
if diction['client_type_id']:
|
|
client_type_id = diction['client_type_id']
|
|
data['client_type_id'] = client_type_id
|
|
|
|
is_company = "0"
|
|
if ("is_company" in diction.keys()):
|
|
if diction['is_company']:
|
|
is_company = diction['is_company']
|
|
data['is_company'] = is_company
|
|
|
|
invoice_automatique = ""
|
|
if ("invoice_automatique" in diction.keys()):
|
|
if diction['invoice_automatique']:
|
|
invoice_automatique = diction['invoice_automatique']
|
|
data['invoice_automatique'] = invoice_automatique
|
|
|
|
|
|
is_fournisseur = ""
|
|
if ("is_fournisseur" in diction.keys() and diction['is_fournisseur']):
|
|
if (str(diction['is_fournisseur']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Fournisseur : La valeur " + str(
|
|
diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Fournisseur : La valeur " + str(
|
|
diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
is_fournisseur = str(diction['is_fournisseur'])
|
|
data['is_fournisseur'] = is_fournisseur
|
|
|
|
is_client = ""
|
|
if ("is_client" in diction.keys() and diction['is_client']):
|
|
if (str(diction['is_client']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
is_client = str(diction['is_client'])
|
|
data['is_client'] = is_client
|
|
|
|
is_financeur = ""
|
|
if ("is_financeur" in diction.keys() and diction['is_financeur']):
|
|
if (str(diction['is_financeur']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
|
|
is_financeur = str(diction['is_financeur'])
|
|
data['is_financeur'] = is_financeur
|
|
|
|
|
|
adr_adresse = ""
|
|
if ("adr_adresse" in diction.keys()):
|
|
if diction['adr_adresse']:
|
|
adr_adresse = diction['adr_adresse']
|
|
data['adr_adresse'] = adr_adresse
|
|
|
|
adr_code_postal = ""
|
|
if ("adr_code_postal" in diction.keys()):
|
|
if diction['adr_code_postal']:
|
|
adr_code_postal = diction['adr_code_postal']
|
|
data['adr_code_postal'] = adr_code_postal
|
|
|
|
adr_ville = ""
|
|
if ("adr_ville" in diction.keys()):
|
|
if diction['adr_ville']:
|
|
adr_ville = diction['adr_ville']
|
|
data['adr_ville'] = adr_ville
|
|
|
|
adr_pays = ""
|
|
if ("adr_pays" in diction.keys()):
|
|
if diction['adr_pays']:
|
|
adr_pays = diction['siret']
|
|
data['adr_pays'] = adr_pays
|
|
|
|
tva = ""
|
|
if ("tva" in diction.keys()):
|
|
if diction['tva']:
|
|
tva = diction['tva']
|
|
data['tva'] = tva
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
email = diction['email']
|
|
|
|
if( mycommon.isEmailValide(email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - L'adresse email "+str(email)+" n'est pas valide")
|
|
|
|
return False, " - L'adresse email "+str(email)+" n'est pas valide "
|
|
data['email'] = email
|
|
|
|
|
|
telephone = ""
|
|
if ("telephone" in diction.keys()):
|
|
if diction['telephone']:
|
|
telephone = diction['telephone']
|
|
data['telephone'] = telephone
|
|
|
|
|
|
website = ""
|
|
if ("website" in diction.keys()):
|
|
if diction['website']:
|
|
website = diction['website']
|
|
data['website'] = website
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
comment = diction['comment']
|
|
data['comment'] = comment
|
|
|
|
invoice_email = ""
|
|
if ("invoice_email" in diction.keys()):
|
|
if diction['invoice_email']:
|
|
invoice_email = diction['invoice_email']
|
|
|
|
if (mycommon.isEmailValide(invoice_email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - L'adresse email de facturation '" + str(invoice_email) + "' n'est pas valide")
|
|
|
|
return False, " - L'adresse email de facturation '" + str(invoice_email) + "' n'est pas valide "
|
|
data['invoice_email'] = invoice_email
|
|
|
|
invoice_nom = ""
|
|
if ("invoice_nom" in diction.keys()):
|
|
if diction['invoice_nom']:
|
|
invoice_nom = diction['invoice_nom']
|
|
data['invoice_nom'] = invoice_nom
|
|
|
|
invoice_siret = ""
|
|
if ("invoice_siret" in diction.keys()):
|
|
if diction['invoice_siret']:
|
|
invoice_siret = diction['invoice_siret']
|
|
data['invoice_siret'] = invoice_siret
|
|
|
|
invoice_tva = ""
|
|
if ("invoice_tva" in diction.keys()):
|
|
if diction['invoice_tva']:
|
|
invoice_tva = diction['invoice_tva']
|
|
data['invoice_tva'] = invoice_tva
|
|
|
|
invoice_condition_paiement_id = ""
|
|
if ("invoice_condition_paiement_id" in diction.keys()):
|
|
if diction['invoice_condition_paiement_id']:
|
|
invoice_condition_paiement_id = diction['invoice_condition_paiement_id']
|
|
data['invoice_condition_paiement_id'] = invoice_condition_paiement_id
|
|
|
|
invoice_adresse = ""
|
|
if ("invoice_adresse" in diction.keys()):
|
|
if diction['invoice_adresse']:
|
|
invoice_adresse = diction['invoice_adresse']
|
|
data['invoice_adresse'] = invoice_adresse
|
|
|
|
invoice_ville = ""
|
|
if ("invoice_ville" in diction.keys()):
|
|
if diction['invoice_ville']:
|
|
invoice_ville = diction['invoice_ville']
|
|
data['invoice_ville'] =invoice_ville
|
|
|
|
invoice_code_postal = ""
|
|
if ("invoice_code_postal" in diction.keys()):
|
|
if diction['invoice_code_postal']:
|
|
invoice_code_postal = diction['invoice_code_postal']
|
|
data['invoice_code_postal'] = invoice_code_postal
|
|
|
|
invoice_pays = ""
|
|
if ("invoice_pays" in diction.keys()):
|
|
if diction['invoice_pays']:
|
|
invoice_pays = diction['invoice_pays']
|
|
data['invoice_pays'] = invoice_pays
|
|
|
|
list_adress = []
|
|
line = 0
|
|
if ("address" in diction.keys()):
|
|
if diction['address']:
|
|
list_adress = ast.literal_eval(diction['address'])
|
|
data['address'] = list_adress
|
|
for adress_val in list_adress :
|
|
print(" ### adress_val = ", adress_val)
|
|
address = adress_val
|
|
data['address'][line]['recid'] = mycommon.create_user_recid()
|
|
line = line + 1
|
|
|
|
"""
|
|
/!\ : 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",
|
|
|
|
|
|
|
|
|
|
list_contact = ""
|
|
if ("list_contact" in diction.keys()):
|
|
if diction['list_contact']:
|
|
list_contact = diction['list_contact']
|
|
data['list_contact'] = list_contact
|
|
|
|
data['valide'] = '1'
|
|
data['locked'] = '0'
|
|
data['date_update'] = str(datetime.now())
|
|
data['update_by'] = str(my_partner['_id'])
|
|
|
|
# Creation du RecId
|
|
data['recid'] = mycommon.create_user_recid()
|
|
|
|
|
|
inserted_id = ""
|
|
inserted_id = MYSY_GV.dbname['partner_client'].insert_one(data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le client du partner ")
|
|
return False, " Impossible de créer le client "
|
|
|
|
|
|
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 contact d'un client de partner -- oselette.
|
|
les contacts sont gérés dans la collection "contact"
|
|
"""
|
|
def Update_Partner_Client_Contact(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "partner_client_contact_recid", "adresse", "ville", "code_postal", "pays", "email", "telephone",
|
|
"client_type_id"]
|
|
|
|
"""
|
|
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 récupérer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire. "
|
|
|
|
data_update = {}
|
|
|
|
partner_client_contact_recid = ""
|
|
if ("partner_client_contact_recid" in diction.keys()):
|
|
partner_client_contact_recid = diction['partner_client_contact_recid']
|
|
|
|
adresse = ""
|
|
if ("adresse" in diction.keys()):
|
|
adresse = diction['adresse']
|
|
data_update['partner_recid'] = my_partner['recid']
|
|
data_update["address.$[elem].adresse"] = adresse
|
|
|
|
ville = ""
|
|
if ("ville" in diction.keys()):
|
|
ville = diction['ville']
|
|
data_update["address.$[elem].ville"] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in diction.keys()):
|
|
code_postal = diction['code_postal']
|
|
data_update["address.$[elem].code_postal"] = code_postal
|
|
|
|
pays = ""
|
|
if ("pays" in diction.keys()):
|
|
pays = diction['pays']
|
|
data_update["address.$[elem].pays"] = pays
|
|
|
|
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
email = diction['email']
|
|
data_update["address.$[elem].email"] = email
|
|
if (mycommon.isEmailValide(email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - L'adresse email " + str(email) + " n'est pas valide")
|
|
|
|
return False, " -L'adresse email " + str(email) + " n'est pas valide "
|
|
|
|
telephone = ""
|
|
if ("telephone" in diction.keys()):
|
|
telephone = diction['telephone']
|
|
data_update["address.$[elem].telephone"] = telephone
|
|
|
|
|
|
"""print(" #### data_update = ", data_update)
|
|
print(" #### partner_recid = ", str(partner_recid))
|
|
print(" #### elem.recid = ", str(partner_client_contact_recid))
|
|
"""
|
|
|
|
result = MYSY_GV.dbname['partner_client'].update_one(
|
|
{'partner_recid':str(partner_recid)},
|
|
{ "$set": data_update},
|
|
upsert=True,
|
|
array_filters=[{"elem.recid": str(partner_client_contact_recid) }],
|
|
)
|
|
|
|
|
|
"""
|
|
print("raw:", result.raw_result)
|
|
print("acknowledged:", result.acknowledged)
|
|
print("matched_count:", result.matched_count)
|
|
"""
|
|
|
|
|
|
return True, " Le contact du client 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 d'ajouter le client "
|
|
|
|
"""
|
|
Mise à jour d'un client.
|
|
La clé de mise à jour est : l'email et ou le nom
|
|
|
|
Donc pas de modification possible du mail et du nom
|
|
"""
|
|
def Update_Partner_Client(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "_id", "raison_sociale", "nom", "siret", "tva", "email",
|
|
"telephone", "website", "comment", "address", "list_contact",
|
|
'adr_adresse', 'adr_code_postal', 'adr_ville', 'adr_pays',
|
|
'invoice_email', 'invoice_nom', 'invoice_siret',
|
|
'invoice_tva','invoice_condition_paiement_id', 'invoice_adresse', 'invoice_ville',
|
|
'invoice_code_postal', 'invoice_pays', 'client_type_id',
|
|
'is_fournisseur', 'is_client', 'is_financeur', 'is_company', 'invoice_automatique',
|
|
'type_financeur_id', 'type_pouvoir_public_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
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 la liste des arguments ")
|
|
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({'token':str(token)})
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
"""
|
|
Verification s'il n'existe pas un cient du partenaire qui perte le meme
|
|
nom, ou la meme adresse email
|
|
"""
|
|
|
|
qry_update = {"_id":ObjectId(str(diction['_id'])), 'valide':'1', 'locked':'0',
|
|
'partner_recid':str(my_partner['recid'])}
|
|
|
|
|
|
|
|
#print(" ### qry_update = ", qry_update)
|
|
tmp_count = MYSY_GV.dbname['partner_client'].count_documents(qry_update)
|
|
if (tmp_count <= 0):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " L'identifiant du client est invalide ")
|
|
return False, " L'identifiant du client est invalide "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
|
|
data_update = {}
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
|
|
raison_sociale = ""
|
|
if ("raison_sociale" in diction.keys()):
|
|
raison_sociale = diction['raison_sociale']
|
|
data_update['raison_sociale'] = diction['raison_sociale']
|
|
|
|
is_company = "0"
|
|
if ("is_company" in diction.keys()):
|
|
is_company = diction['is_company']
|
|
if( is_company in ['0', '1', '2']):
|
|
data_update['is_company'] = is_company
|
|
else:
|
|
data_update['is_company'] = "0"
|
|
|
|
|
|
nom = ""
|
|
if ("nom" in diction.keys()):
|
|
nom = diction['nom']
|
|
data_update['nom'] = diction['nom']
|
|
|
|
|
|
if ("invoice_automatique" in diction.keys()):
|
|
data_update['invoice_automatique'] = diction['invoice_automatique']
|
|
|
|
|
|
# Le nom est un champ obligatoire
|
|
if( str(nom).strip() == ""):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " Le nom du client est vide ")
|
|
return False, " Le nom du client est vide "
|
|
|
|
|
|
siret = ""
|
|
if ("siret" in diction.keys()):
|
|
siret = diction['siret']
|
|
data_update['siret'] = diction['siret']
|
|
|
|
client_type_id = ""
|
|
if ("client_type_id" in diction.keys()):
|
|
client_type_id = diction['client_type_id']
|
|
data_update['client_type_id'] = diction['client_type_id']
|
|
|
|
is_fournisseur = ""
|
|
if ("is_fournisseur" in diction.keys() and diction['is_fournisseur']):
|
|
if (str(diction['is_fournisseur']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Fournisseur : La valeur " + str(
|
|
diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Fournisseur : La valeur " + str(
|
|
diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
is_fournisseur = str(diction['is_fournisseur'])
|
|
data_update['is_fournisseur'] = is_fournisseur
|
|
|
|
is_client = ""
|
|
if ("is_client" in diction.keys() and diction['is_client']):
|
|
if (str(diction['is_client']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
is_client = str(diction['is_client'])
|
|
data_update['is_client'] = is_client
|
|
|
|
is_financeur = ""
|
|
if ("is_financeur" in diction.keys() and diction['is_financeur']):
|
|
if (str(diction['is_financeur']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
|
|
is_financeur = str(diction['is_financeur'])
|
|
data_update['is_financeur'] = is_financeur
|
|
|
|
type_financeur_id = ""
|
|
if ("type_financeur_id" in diction.keys()):
|
|
if( diction['type_financeur_id'] ):
|
|
is_valide_type_financeur_id_count = MYSY_GV.dbname['type_organisme_financement'].count_documents({'_id':ObjectId(str(diction['type_financeur_id'])),
|
|
'vallide':'1', 'locked':'0'})
|
|
|
|
if( is_valide_type_financeur_id_count != 0 ):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " L'identifiant du type de financeur est invalide ")
|
|
return False, " L'identifiant du type de financeur est invalide "
|
|
|
|
|
|
data_update['type_financeur_id'] = diction['type_financeur_id']
|
|
|
|
|
|
type_pouvoir_public_id = ""
|
|
if ("type_pouvoir_public_id" in diction.keys()):
|
|
if (diction['type_pouvoir_public_id']):
|
|
type_pouvoir_public_id = diction['type_pouvoir_public_id']
|
|
|
|
is_valide_type_pouvoir_public_id_count = MYSY_GV.dbname['type_pouvoir_public'].count_documents(
|
|
{'_id': ObjectId(str(diction['type_pouvoir_public_id'])),
|
|
'vallide': '1', 'locked': '0'})
|
|
|
|
if (is_valide_type_pouvoir_public_id_count != 0):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " L'identifiant du type de pouvoir public est invalide ")
|
|
return False, " L'identifiant du type de pouvoir public est invalide "
|
|
|
|
data_update['type_pouvoir_public_id'] = type_pouvoir_public_id
|
|
|
|
|
|
|
|
adr_adresse = ""
|
|
if ("adr_adresse" in diction.keys()):
|
|
adr_adresse = diction['adr_adresse']
|
|
data_update['adr_adresse'] = diction['adr_adresse']
|
|
|
|
adr_code_postal = ""
|
|
if ("adr_code_postal" in diction.keys()):
|
|
adr_code_postal = diction['adr_code_postal']
|
|
data_update['adr_code_postal'] = diction['adr_code_postal']
|
|
|
|
adr_ville = ""
|
|
if ("adr_ville" in diction.keys()):
|
|
adr_ville = diction['adr_ville']
|
|
data_update['adr_ville'] = diction['adr_ville']
|
|
|
|
adr_pays = ""
|
|
if ("adr_pays" in diction.keys()):
|
|
adr_pays = diction['adr_pays']
|
|
data_update['adr_pays'] = diction['adr_pays']
|
|
|
|
|
|
|
|
tva = ""
|
|
if ("tva" in diction.keys()):
|
|
tva = diction['tva']
|
|
data_update['tva'] = diction['tva']
|
|
|
|
telephone = ""
|
|
if ("telephone" in diction.keys()):
|
|
telephone = diction['telephone']
|
|
data_update['telephone'] = diction['telephone']
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
email = diction['email']
|
|
data_update['email'] = diction['email']
|
|
# L'adresse email est obligatoire
|
|
if (str(email).strip() == ""):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " L'adresse email du client est vide ")
|
|
return False, " L'adresse email du client est vide "
|
|
|
|
if (mycommon.isEmailValide(email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - L'adresse email " + str(email) + " n'est pas valide")
|
|
|
|
return False, " - L'adresse email " + str(email) + " n'est pas valide "
|
|
|
|
|
|
invoice_email = ""
|
|
if ("invoice_email" in diction.keys()):
|
|
invoice_email = diction['invoice_email']
|
|
data_update['invoice_email'] = diction['invoice_email']
|
|
if (mycommon.isEmailValide(invoice_email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - L'adresse email de facturation " + str(invoice_email) + " n'est pas valide")
|
|
|
|
return False, " - L'adresse email de facturation " + str(invoice_email) + " n'est pas valide "
|
|
|
|
invoice_nom = ""
|
|
if ("invoice_nom" in diction.keys()):
|
|
invoice_nom = diction['invoice_nom']
|
|
data_update['invoice_nom'] = diction['invoice_nom']
|
|
|
|
invoice_siret = ""
|
|
if ("invoice_siret" in diction.keys()):
|
|
invoice_siret = diction['invoice_siret']
|
|
data_update['invoice_siret'] = diction['invoice_siret']
|
|
|
|
invoice_tva = ""
|
|
if ("invoice_tva" in diction.keys()):
|
|
invoice_tva = diction['invoice_tva']
|
|
data_update['invoice_tva'] = diction['invoice_tva']
|
|
|
|
invoice_condition_paiement_id = ""
|
|
if ("invoice_condition_paiement_id" in diction.keys()):
|
|
invoice_condition_paiement_id = diction['invoice_condition_paiement_id']
|
|
data_update['invoice_condition_paiement_id'] = invoice_condition_paiement_id
|
|
|
|
invoice_adresse = ""
|
|
if ("invoice_adresse" in diction.keys()):
|
|
invoice_adresse = diction['invoice_adresse']
|
|
data_update['invoice_adresse'] = diction['invoice_adresse']
|
|
|
|
invoice_ville = ""
|
|
if ("invoice_ville" in diction.keys()):
|
|
invoice_ville = diction['invoice_ville']
|
|
data_update['invoice_ville'] = diction['invoice_ville']
|
|
|
|
invoice_code_postal = ""
|
|
if ("invoice_code_postal" in diction.keys()):
|
|
invoice_code_postal = diction['invoice_code_postal']
|
|
data_update['invoice_code_postal'] = diction['invoice_code_postal']
|
|
|
|
invoice_pays = ""
|
|
if ("invoice_pays" in diction.keys()):
|
|
invoice_pays = diction['invoice_pays']
|
|
data_update['invoice_pays'] = diction['invoice_pays']
|
|
|
|
|
|
website = ""
|
|
if ("website" in diction.keys()):
|
|
website = diction['website']
|
|
data_update['website'] = diction['website']
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
comment = diction['comment']
|
|
data_update['comment'] = diction['comment']
|
|
|
|
address = {}
|
|
if ("address" in diction.keys()):
|
|
address = ast.literal_eval(diction['address'])
|
|
data_update['address'] = ast.literal_eval(diction['address'])
|
|
""""
|
|
/!\ : 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",
|
|
|
|
list_contact = ""
|
|
if ("list_contact" in diction.keys()):
|
|
list_contact = diction['list_contact']
|
|
data_update['list_contact'] = diction['list_contact']
|
|
|
|
data_update['valide'] = '1'
|
|
data_update['locked'] = '0'
|
|
data_update['date_update'] = str(datetime.now())
|
|
data_update['update_by'] = str(my_partner['_id'])
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(str(diction['_id']))
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
inserted_id = ""
|
|
result = MYSY_GV.dbname['partner_client'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": data_update},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
#print(" ###result = ", result)
|
|
if (result is None):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le client : email = " + str(diction['email']))
|
|
return False, " Impossible de mettre à jour le client "
|
|
|
|
return True, " Le client 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 client "
|
|
|
|
|
|
"""
|
|
Recuperation d'une liste de client d'un partenaire
|
|
"""
|
|
|
|
def Get_Partner_List_Partner_Client(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 and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token',]
|
|
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 la liste des arguments ")
|
|
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"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
#print(" ### Get_Partner_List_Partner_Client data_cle = ", data_cle)
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['partner_client'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
|
|
if( "invoice_condition_paiement_id" not in retval.keys() ):
|
|
user['invoice_condition_paiement_id'] = ""
|
|
|
|
if ("is_prospect" not in retval.keys()):
|
|
user['is_prospect'] = ""
|
|
|
|
if ("intranet_account_id" not in retval.keys()):
|
|
user['intranet_account_id'] = ""
|
|
|
|
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 récupérer la liste des clients "
|
|
|
|
|
|
"""
|
|
Recuperation de la liste des clients d'un partner avec des filtre
|
|
- is_fournisseur,
|
|
- is_financeur,
|
|
- nom
|
|
- email
|
|
- etc
|
|
"""
|
|
"""
|
|
Recuperation d'une liste de client d'un partenaire
|
|
|
|
|
|
"""
|
|
|
|
def Get_Partner_List_Partner_Client_with_filter_Like(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'raison_sociale', 'nom', 'email',
|
|
'is_client', 'is_financeur', 'is_fournisseur']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token',]
|
|
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 la liste des arguments ")
|
|
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_raison_sociale = {}
|
|
if ("raison_sociale" in diction.keys()):
|
|
filt_raison_sociale = {'raison_sociale': {'$regex': str(diction['raison_sociale']), "$options": "i"}}
|
|
|
|
filt_nom = {}
|
|
if ("nom" in diction.keys()):
|
|
filt_nom = {'nom': {'$regex': str(diction['nom']), "$options": "i"}}
|
|
|
|
filt_email = {}
|
|
if ("email" in diction.keys()):
|
|
filt_email = {'email': {'$regex': str(diction['email']), "$options": "i"}}
|
|
|
|
filt_client_is_client = {}
|
|
if ("is_client" in diction.keys()):
|
|
filt_client_is_client = {'is_client': str(diction['is_client'])}
|
|
|
|
filt_client_is_financeur = {}
|
|
if ("is_financeur" in diction.keys()):
|
|
filt_client_is_financeur = {'is_financeur': str(diction['is_financeur'])}
|
|
|
|
filt_client_is_fournisseur = {}
|
|
if ("is_fournisseur" in diction.keys()):
|
|
filt_client_is_fournisseur = {'is_fournisseur': str(diction['is_fournisseur'])}
|
|
|
|
|
|
filt_class_partner_recid = {'partner_owner_recid': str(my_partner['recid'])}
|
|
|
|
qry = {'$and': [filt_raison_sociale, filt_email, filt_nom, filt_client_is_client,
|
|
filt_client_is_financeur,filt_client_is_fournisseur, {'partner_recid': str(my_partner['recid'])}
|
|
]
|
|
}
|
|
|
|
|
|
#print("#### Get_Partner_List_Partner_Client_with_filter_Like laa 01 : query = ", qry)
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for New_retVal in MYSY_GV.dbname['partner_client'].find(qry):
|
|
#print(" ### New_retVal = ", New_retVal)
|
|
|
|
user = New_retVal
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
if ("is_financeur" not in New_retVal.keys()):
|
|
user['is_financeur'] = 0
|
|
|
|
if ("is_client" not in New_retVal.keys()):
|
|
user['is_client'] = 0
|
|
|
|
if ("is_fournisseur" not in New_retVal.keys()):
|
|
user['is_fournisseur'] = 0
|
|
|
|
if( "is_prospect" not in New_retVal.keys() ):
|
|
user['is_prospect'] = ""
|
|
|
|
if ("intranet_account_id" not in New_retVal.keys()):
|
|
user['intranet_account_id'] = ""
|
|
|
|
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 récupérer la liste des clients "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Recuperation d'un client donnée a partir de l'adresse email
|
|
"""
|
|
def Get_Given_Partner_Client(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'email']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token','email' ]
|
|
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 la liste des arguments ")
|
|
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"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
data_cle['email'] = str(diction['email'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
print(" ### data_cle 1 = ", data_cle)
|
|
for retval in MYSY_GV.dbname['partner_client'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
# Si le champ 'invoice_condition_paiement_id' alors on va chercher le code de la condition de paiement
|
|
paiement_ction_code = ""
|
|
if ('invoice_condition_paiement_id' in retval.keys() and retval['invoice_condition_paiement_id']):
|
|
paiement_ction_data = MYSY_GV.dbname['base_partner_paiement_condition'].find_one(
|
|
{'_id': ObjectId(str(retval['invoice_condition_paiement_id'])), 'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (paiement_ction_data and 'code' in paiement_ction_data.keys()):
|
|
paiement_ction_code = str(paiement_ction_data['code'])
|
|
user['invoice_condition_paiement_code'] = paiement_ction_code
|
|
|
|
# Si le client a un 'client_type_id', aller le chercher le code
|
|
if ("client_type_id" in retval.keys() and retval['retval']):
|
|
client_type_data = MYSY_GV.dbname['partner_client_type'].find_one(
|
|
{'_id': ObjectId(str(retval['retval'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (client_type_data and "code" in client_type_data.keys()):
|
|
user['client_type_code'] = client_type_data['code']
|
|
|
|
if ("invoice_automatique" not in retval.keys()):
|
|
user['invoice_automatique'] = ""
|
|
|
|
if ("type_financeur_id" not in retval.keys()):
|
|
user['type_financeur_id'] = ""
|
|
|
|
if ("type_pouvoir_public_id" not in retval.keys()):
|
|
user['type_pouvoir_public_id'] = ""
|
|
|
|
if ("is_prospect" not in retval.keys()):
|
|
user['is_prospect'] = ""
|
|
|
|
if ("intranet_account_id" not in retval.keys()):
|
|
user['intranet_account_id'] = ""
|
|
|
|
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 récupérer le client "
|
|
|
|
"""
|
|
Recuperation d'un client donnée a partir de l'_id
|
|
"""
|
|
def Get_Given_Partner_Client_From_Id(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
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 la liste des arguments ")
|
|
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"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(str(diction['_id']))
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['partner_client'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
# Si le champ 'invoice_condition_paiement_id' alors on va chercher le code de la condition de paiement
|
|
paiement_ction_code = ""
|
|
if ('invoice_condition_paiement_id' in retval.keys() and retval['invoice_condition_paiement_id']):
|
|
paiement_ction_data = MYSY_GV.dbname['base_partner_paiement_condition'].find_one(
|
|
{'_id': ObjectId(str(retval['invoice_condition_paiement_id'])), 'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (paiement_ction_data and 'code' in paiement_ction_data.keys()):
|
|
paiement_ction_code = str(paiement_ction_data['code'])
|
|
user['invoice_condition_paiement_code'] = paiement_ction_code
|
|
|
|
# Si le client a un 'client_type_id', aller le chercher le code
|
|
if( "client_type_id" in retval.keys() and retval['client_type_id']):
|
|
client_type_data = MYSY_GV.dbname['partner_client_type'].find_one({'_id':ObjectId(str(retval['client_type_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( client_type_data and "code" in client_type_data.keys() ):
|
|
user['client_type_code'] = client_type_data['code']
|
|
|
|
|
|
if( "invoice_automatique" not in retval.keys() ):
|
|
user['invoice_automatique'] = ""
|
|
|
|
if ("type_financeur_id" not in retval.keys()):
|
|
user['type_financeur_id'] = ""
|
|
|
|
if ("type_pouvoir_public_id" not in retval.keys()):
|
|
user['type_pouvoir_public_id'] = ""
|
|
|
|
if ("is_prospect" not in retval.keys()):
|
|
user['is_prospect'] = ""
|
|
|
|
if ("intranet_account_id" not in retval.keys()):
|
|
user['intranet_account_id'] = ""
|
|
|
|
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 récupérer le client "
|
|
|
|
|
|
""""
|
|
Cette fonction permet d'importer des clients de partner en masse avec un fichier excel
|
|
"""
|
|
def Add_Partner_Client_mass(file=None, Folder=None, diction=None):
|
|
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 and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, Creation participants annulée")
|
|
return False, " Verifier votre API"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
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 la liste des arguments ")
|
|
return False, " Verifier votre API, Toutes les informations techniques ne sont pas fournies"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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
|
|
|
|
status, saved_file = mycommon.Upload_Save_CSV_File(file, Folder)
|
|
if (status is False):
|
|
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
|
return False, "Impossible de récupérer correctement le fichier à importer"
|
|
|
|
|
|
df = pd.read_csv(saved_file, encoding='utf8', on_bad_lines='skip', sep=';', encoding_errors='ignore')
|
|
df = df.fillna('')
|
|
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les noms des colonne sont bien corrects"
|
|
'''
|
|
field_list = ['nom', 'raison_sociale', 'email', 'adresse', 'code_postal', 'ville', 'pays', 'siret', 'telephone', 'tva', 'website', 'invoice_adresse',
|
|
'invoice_code_postal', 'invoice_email', 'invoice_nom', 'invoice_siret', 'invoice_tva', 'invoice_ville', 'invoice_pays']
|
|
|
|
# Controle du nombre de lignes dans le fichier.
|
|
total_rows = len(df)
|
|
if (total_rows > MYSY_GV.MAX_PARTNER_CLIENT_BY_CSV):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le fichier comporte plus de " + str(
|
|
MYSY_GV.MAX_PARTNER_CLIENT_BY_CSV) + " lignes.")
|
|
return False, " Le fichier comporte plus de " + str(MYSY_GV.MAX_PARTNER_CLIENT_BY_CSV) + " lignes."
|
|
|
|
for val in df.columns:
|
|
if str(val).lower() not in field_list:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " : entete du fichier csv. '" + val + "' n'est pas acceptée")
|
|
return False, " Entete du fichier csv. '" + val + "' n'est pas acceptée"
|
|
|
|
# Verification des champs obligatoires dans le fichier
|
|
field_list_obligatoire_file = ['nom', 'email', 'adresse', 'code_postal', 'ville', 'pays', 'telephone', ]
|
|
|
|
for val in field_list_obligatoire_file:
|
|
if val not in df.columns:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " : Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire")
|
|
return False, " Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire "
|
|
|
|
# Traitement des données du fichier
|
|
|
|
warning_msg = ""
|
|
nb_warning_msg = 0
|
|
x = range(0, total_rows)
|
|
for n in x:
|
|
mydata = {}
|
|
mydata['nom'] = str(df['nom'].values[n])
|
|
mydata['email'] = str(df['email'].values[n])
|
|
mydata['adr_adresse'] = str(df['adresse'].values[n])
|
|
mydata['adr_code_postal'] = str(df['code_postal'].values[n])
|
|
mydata['adr_ville'] = str(df['ville'].values[n])
|
|
mydata['adr_pays'] = str(df['pays'].values[n])
|
|
mydata['telephone'] = str(df['telephone'].values[n])
|
|
mydata['token'] = str(my_token)
|
|
|
|
raison_sociale = ""
|
|
if ("raison_sociale" in df.keys()):
|
|
if (str(df['raison_sociale'].values[n])):
|
|
raison_sociale = str(df['raison_sociale'].values[n])
|
|
mydata['raison_sociale'] = raison_sociale
|
|
|
|
siret = ""
|
|
if ("siret" in df.keys()):
|
|
if (str(df['siret'].values[n])):
|
|
siret = str(df['siret'].values[n])
|
|
mydata['siret'] = siret
|
|
|
|
tva = ""
|
|
if ("tva" in df.keys()):
|
|
if (str(df['tva'].values[n])):
|
|
tva = str(df['tva'].values[n])
|
|
mydata['tva'] = tva
|
|
|
|
website = ""
|
|
if ("website" in df.keys()):
|
|
if (str(df['website'].values[n])):
|
|
website = str(df['website'].values[n])
|
|
mydata['website'] = website
|
|
|
|
invoice_adresse = ""
|
|
if ("invoice_adresse" in df.keys()):
|
|
if (str(df['invoice_adresse'].values[n])):
|
|
invoice_adresse = str(df['invoice_adresse'].values[n])
|
|
mydata['invoice_adresse'] = invoice_adresse
|
|
|
|
invoice_code_postal = ""
|
|
if ("invoice_code_postal" in df.keys()):
|
|
if (str(df['invoice_code_postal'].values[n])):
|
|
invoice_code_postal = str(df['invoice_code_postal'].values[n])
|
|
mydata['invoice_code_postal'] = invoice_code_postal
|
|
|
|
invoice_email = ""
|
|
if ("invoice_email" in df.keys()):
|
|
if (str(df['invoice_email'].values[n])):
|
|
invoice_email = str(df['invoice_email'].values[n])
|
|
mydata['invoice_email'] = invoice_email
|
|
|
|
invoice_nom = ""
|
|
if ("invoice_nom" in df.keys()):
|
|
if (str(df['invoice_nom'].values[n])):
|
|
invoice_nom = str(df['invoice_nom'].values[n])
|
|
mydata['invoice_nom'] = invoice_nom
|
|
|
|
invoice_siret = ""
|
|
if ("invoice_siret" in df.keys()):
|
|
if (str(df['invoice_siret'].values[n])):
|
|
invoice_siret = str(df['invoice_siret'].values[n])
|
|
mydata['invoice_siret'] = invoice_siret
|
|
|
|
invoice_tva = ""
|
|
if ("invoice_tva" in df.keys()):
|
|
if (str(df['invoice_tva'].values[n])):
|
|
invoice_tva = str(df['invoice_tva'].values[n])
|
|
mydata['invoice_tva'] = invoice_tva
|
|
|
|
invoice_ville = ""
|
|
if ("invoice_ville" in df.keys()):
|
|
if (str(df['invoice_ville'].values[n])):
|
|
invoice_ville = str(df['invoice_ville'].values[n])
|
|
mydata['invoice_ville'] = invoice_ville
|
|
|
|
invoice_pays = ""
|
|
if ("invoice_pays" in df.keys()):
|
|
if (str(df['invoice_pays'].values[n])):
|
|
invoice_pays = str(df['invoice_pays'].values[n])
|
|
mydata['invoice_pays'] = invoice_pays
|
|
|
|
clean_dict = {k: mydata[k] for k in mydata if (str(mydata[k]) != "nan")}
|
|
|
|
print("#### clean_dict ", clean_dict)
|
|
status, retval = Add_Partner_Client( clean_dict)
|
|
|
|
if (status is False):
|
|
warning_msg = warning_msg + " Line "+str(n+1)+" : "+str(retval)
|
|
nb_warning_msg = nb_warning_msg + 1
|
|
|
|
|
|
if( nb_warning_msg > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Toutes les lignes ont été correctement traités, sauf : "+str(warning_msg))
|
|
return True, "Toutes les lignes ont été correctement traités, sauf : "+str(warning_msg)
|
|
|
|
|
|
return True, " Toutes les lignes ont été correctement traitées"
|
|
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'importer les client en masse "
|
|
|
|
|
|
"""
|
|
Cette fonction supprime un client.
|
|
Avant il faut verifier :
|
|
1 - pas de stagiaire associé
|
|
2 - Pas de devis associé
|
|
3 - Pas de commande associé
|
|
4 - Pas de contact associé
|
|
"""
|
|
def Delete_Given_Partner_Client(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
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 la liste des arguments ")
|
|
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
|
|
|
|
|
|
|
|
# Verification de la validé du client
|
|
is_existe_client_count = MYSY_GV.dbname['partner_client'].count_documents({'_id':ObjectId(str(diction['_id'])), 'partner_recid':str(my_partner['recid'])})
|
|
if( is_existe_client_count <= 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le client n'est pas valide ")
|
|
return False, " - Le client n'est pas valide ",
|
|
|
|
if (is_existe_client_count > 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Plusieurs clients ont le même identifiant. Suppression annulée")
|
|
return False, " - Plusieurs clients ont le même identifiant. Suppression annulée",
|
|
|
|
|
|
# Verifier qu'il n'y pas de stagiaire associé
|
|
is_Stagiaire_Count = MYSY_GV.dbname['inscription'].count_documents({'client_rattachement_id':str(diction['_id']),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1'})
|
|
if( is_Stagiaire_Count > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le client a "+str(is_Stagiaire_Count)+" stagiaire(s) valide(s). Suppression annulée ")
|
|
return False, " - Le client a "+str(is_Stagiaire_Count)+" stagiaire(s) valide(s). Suppression annulée ",
|
|
|
|
# Verifier qu'il n'y pas de devis ou commande associé
|
|
is_devis_cmd_Count = MYSY_GV.dbname['partner_order_header'].count_documents(
|
|
{'order_header_client_id': str(diction['_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
if (is_devis_cmd_Count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le client a " + str(
|
|
is_devis_cmd_Count) + " commande(s) ou devis valide(s). Suppression annulée ")
|
|
return False, " - Le client a " + str(
|
|
is_devis_cmd_Count) + " commande(s) ou devis valide(s). Suppression annulée"
|
|
|
|
# Supression à contact
|
|
MYSY_GV.dbname['contact'].delete_one(
|
|
{'related_collection':'partner_client',
|
|
'related_collection_recid':str(diction['_id']),
|
|
'partner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
|
|
# Supression à faire
|
|
MYSY_GV.dbname['partner_client'].delete_one({'_id':ObjectId(str(diction['_id'])), 'partner_recid':str(my_partner['recid'])})
|
|
|
|
return True, "La suppression du client a été correctement faite."
|
|
|
|
|
|
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 le client "
|
|
|
|
|
|
"""
|
|
Recuperation de la liste des type de client
|
|
"""
|
|
|
|
def Get_Client_Type_List(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 and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token',]
|
|
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 la liste des arguments ")
|
|
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['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
#print(" ### Get_Partner_List_Partner_Client data_cle = ", data_cle)
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['partner_client_type'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
if( "is_financeur" not in retval.keys() ):
|
|
user['is_financeur'] = 0
|
|
|
|
if ("is_client" not in retval.keys()):
|
|
user['is_client'] = 0
|
|
|
|
if ("is_fournisseur" not in retval.keys()):
|
|
user['is_fournisseur'] = 0
|
|
|
|
if ("is_prospect" not in retval.keys()):
|
|
user['is_prospect'] = ""
|
|
|
|
if ("intranet_account_id" not in retval.keys()):
|
|
user['intranet_account_id'] = ""
|
|
|
|
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 récupérer la liste des types de client "
|
|
|
|
|
|
"""
|
|
Ajout d'un nouveau type de client
|
|
"""
|
|
def Add_Client_Type(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token','code', 'description', 'is_fournisseur', 'is_client', 'is_financeur']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token','code']
|
|
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 la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# Verifier que ce code de type client n'existe pas pour ce partner
|
|
is_code_exist = MYSY_GV.dbname["partner_client_type"].count_documents({'code':str(diction['code']),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_code_exist > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Ce code existe déjà pour un type de client ")
|
|
return False, " Ce code existe déjà pour un type de client",
|
|
|
|
if( "is_fournisseur" in diction.keys() and diction['is_fournisseur']) :
|
|
if ( str(diction['is_fournisseur']) not in ['0', '1'] ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Fournisseur : La valeur " + str(diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Fournisseur : La valeur " + str(diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
|
|
|
|
if ("is_client" in diction.keys() and diction['is_client']):
|
|
if (str(diction['is_client']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
|
|
|
|
if ("is_financeur" in diction.keys() and diction['is_financeur']):
|
|
if (str(diction['is_financeur']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
|
|
|
|
|
|
|
|
new_data = diction
|
|
del new_data['token']
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
inserted_id = MYSY_GV.dbname['partner_client_type'].insert_one(new_data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le type de client (1) ")
|
|
return False, " Impossible de créer le type de client (1) "
|
|
|
|
|
|
return True, " Le type de client a été correctement ajouté "
|
|
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 type de client "
|
|
|
|
|
|
|
|
"""
|
|
Mise à jour d'un type de client
|
|
"""
|
|
def Update_Client_Type(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', 'code', 'description', 'is_fournisseur', 'is_client', 'is_financeur']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token','code', '_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 la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# Verifier que ce code de type client existe pas pour ce partner
|
|
is_code_exist_valide = MYSY_GV.dbname["partner_client_type"].count_documents({'_id':ObjectId(str(diction['_id'])),
|
|
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_code_exist_valide != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant du type de client est invalide ")
|
|
return False, " L'identifiant du type de client est invalide ",
|
|
|
|
if ("is_fournisseur" in diction.keys() and diction['is_fournisseur']):
|
|
if (str(diction['is_fournisseur']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Fournisseur : La valeur " + str(
|
|
diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Fournisseur : La valeur " + str(
|
|
diction['is_fournisseur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
|
|
if ("is_client" in diction.keys() and diction['is_client']):
|
|
if (str(diction['is_client']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Client : La valeur " + str(
|
|
diction['is_client']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
|
|
if ("is_financeur" in diction.keys() and diction['is_financeur']):
|
|
if (str(diction['is_financeur']) not in ['0', '1']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 ")
|
|
return False, " Est Financeur : La valeur " + str(
|
|
diction['is_financeur']) + " n'est pas autorisée. Les valeurs admises sont : 0, 1 "
|
|
|
|
|
|
|
|
local_id = str(diction['_id'])
|
|
new_data = diction
|
|
del new_data['token']
|
|
del new_data['_id']
|
|
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
|
|
update = MYSY_GV.dbname['partner_client_type'].update_one({'_id': ObjectId(str(local_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'},
|
|
{'$set': new_data}
|
|
)
|
|
|
|
|
|
return True, " Le type de client 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 type de client "
|
|
|
|
|
|
"""
|
|
Supprimer un type de client
|
|
"""
|
|
|
|
def Delete_Client_Type(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
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 la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# Verifier que ce code de type client existe pas pour ce partner
|
|
is_code_exist_valide = MYSY_GV.dbname["partner_client_type"].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_code_exist_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant du type de client est invalide ")
|
|
return False, " L'identifiant du type de client est invalide ",
|
|
|
|
|
|
# Verifier que ce type de client n'est utilisé par aucun client
|
|
# Si non on refuse la suppression car cela peut entrainter une incohérence d'info
|
|
type_client_used_count = MYSY_GV.dbname['partner_client'].count_documents({'partner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'client_type_id':str(diction['_id'])})
|
|
|
|
if( type_client_used_count > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le type de client est utilisé par "+str(type_client_used_count)+" client(s) ")
|
|
return False, " Le type de client est utilisé par "+str(type_client_used_count)+" client(s) ",
|
|
|
|
|
|
|
|
new_data = diction
|
|
|
|
delete_retval = MYSY_GV.dbname['partner_client_type'].delete_one(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
|
|
return True, " Le type de client a été correctement supprimé "
|
|
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 le type de client "
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction retourne les contact d'un client qui
|
|
doivent etre inlus dans les communication .
|
|
|
|
Avec le fonction contact.Get_List_Entity_Contact(), on recuperer la liste des contacts
|
|
en suite on regarde le quel a la communication incluse
|
|
|
|
"""
|
|
def Get_Partner_Client_Communication_Contact(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token','_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
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 la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
# Verifier la validité du client
|
|
is_client_exist_valide = MYSY_GV.dbname['partner_client'].count_documents({"_id":ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'locked':'0',
|
|
'partner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_client_exist_valide <= 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant du client est invalide ")
|
|
return False, " L'identifiant du client est invalide ",
|
|
|
|
|
|
# field_list = ['token', 'related_collection', 'related_collection_owner_id']
|
|
new_diction = {}
|
|
new_diction['related_collection'] = "partner_client"
|
|
new_diction['related_collection_recid'] = diction['_id']
|
|
new_diction['partner_recid'] = my_partner['recid']
|
|
new_diction['valide'] = "1"
|
|
new_diction['locked'] = "0"
|
|
new_diction['include_com'] = "1"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['contact'].find(new_diction):
|
|
user = retval
|
|
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 récupérer la liste des contacts du client inclus dans la communication "
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction retourne les contact d'un client qui
|
|
doivent etre inlus dans les communication, ceci en mode non connecté.
|
|
|
|
donc avec en input le partner_owner_recid et non le token
|
|
|
|
"""
|
|
def Get_Partner_Client_Communication_Contact_NO_TOKEN(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['partner_owner_recid','_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['partner_owner_recid','_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 la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
|
|
|
|
# Verifier la validité du client
|
|
is_client_exist_valide = MYSY_GV.dbname['partner_client'].count_documents({"_id":ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'locked':'0',
|
|
'partner_recid':str(diction['partner_owner_recid'])})
|
|
|
|
if( is_client_exist_valide <= 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant du client est invalide ")
|
|
return False, " L'identifiant du client est invalide ",
|
|
|
|
|
|
# field_list = ['token', 'related_collection', 'related_collection_owner_id']
|
|
new_diction = {}
|
|
new_diction['related_collection'] = "partner_client"
|
|
new_diction['related_collection_recid'] = diction['_id']
|
|
new_diction['partner_recid'] = str(diction['partner_owner_recid'])
|
|
new_diction['valide'] = "1"
|
|
new_diction['locked'] = "0"
|
|
new_diction['include_com'] = "1"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['contact'].find(new_diction):
|
|
user = retval
|
|
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 récupérer la liste des contacts du client inclus dans la communication "
|
|
|
|
|
|
"""
|
|
Intranet client :
|
|
Cette fonction permet de créer le compte intranet d'un client
|
|
regles :
|
|
- le login est forcement l'email princiape du client.
|
|
|
|
"""
|
|
|
|
def Create_Partner_Client_Intranet_Account(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés. les filtres accepté sont :
|
|
- ref_interne,
|
|
"""
|
|
field_list = ['token', 'partner_client_id', 'default_pwd']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'partner_client_id', 'default_pwd']
|
|
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 la liste des arguments ")
|
|
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']
|
|
|
|
client_pwd = str(diction['default_pwd']).strip()
|
|
|
|
if( len(str(client_pwd)) <= 5):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le mot de passe doit faire plus 5 caractère ")
|
|
return False, " Le mot de passe doit faire plus 5 caractère "
|
|
|
|
if( " " in str(client_pwd) ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Les espaces ne sont pas autorisés dans le mot de passe ")
|
|
return False, " Les espaces ne sont pas autorisés dans le mot de passe "
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Verifier la validité du client
|
|
"""
|
|
is_valide_client_partner = MYSY_GV.dbname['partner_client'].count_documents({'_id':ObjectId(str(diction['partner_client_id'])),
|
|
'valide':'1', 'locked':'0',
|
|
'partner_recid':my_partner['recid']})
|
|
|
|
if( is_valide_client_partner != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du client est invalide ")
|
|
return False, " L'identifiant du client est invalide "
|
|
|
|
is_valide_client_partner_data = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(str(diction['partner_client_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_recid': my_partner['recid']})
|
|
|
|
client_email = is_valide_client_partner_data['email']
|
|
client_id = str(is_valide_client_partner_data['_id'])
|
|
|
|
client_nom = ""
|
|
if( "nom" in is_valide_client_partner_data.keys() ):
|
|
client_nom = is_valide_client_partner_data['nom']
|
|
|
|
client_telephone = ""
|
|
if ("telephone" in is_valide_client_partner_data.keys()):
|
|
client_telephone = is_valide_client_partner_data['telephone']
|
|
|
|
client_adr_adresse = ""
|
|
if ("adr_adresse" in is_valide_client_partner_data.keys()):
|
|
client_adr_adresse = is_valide_client_partner_data['adr_adresse']
|
|
|
|
client_adr_code_postal = ""
|
|
if ("adr_code_postal" in is_valide_client_partner_data.keys()):
|
|
client_adr_code_postal = is_valide_client_partner_data['adr_code_postal']
|
|
|
|
client_adr_ville = ""
|
|
if ("adr_ville" in is_valide_client_partner_data.keys()):
|
|
client_adr_ville = is_valide_client_partner_data['adr_ville']
|
|
|
|
client_adr_pays = ""
|
|
if ("adr_pays" in is_valide_client_partner_data.keys()):
|
|
client_adr_pays = is_valide_client_partner_data['adr_pays']
|
|
|
|
now = str(datetime.now())
|
|
|
|
new_data = {}
|
|
new_data['nom'] = client_nom
|
|
new_data['adr_street'] = client_adr_adresse
|
|
new_data['adr_city'] = client_adr_ville
|
|
new_data['adr_zip'] = client_adr_code_postal
|
|
new_data['adr_country'] = client_adr_pays
|
|
new_data['mob_phone'] = client_telephone
|
|
|
|
new_data['email'] = client_email
|
|
new_data['pwd'] = str(client_pwd)
|
|
new_data['recid'] = str(my_partner['recid'])
|
|
new_data['partner_client_id'] = str(is_valide_client_partner_data['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['locked'] = "0"
|
|
new_data['active'] = "1"
|
|
new_data['date_creation'] = now
|
|
new_data['created_by'] = str(my_partner['_id'])
|
|
new_data['type'] = "user"
|
|
new_data['lastconnexion'] = ""
|
|
new_data['firstconnexion'] = "1"
|
|
|
|
inserted_id = MYSY_GV.dbname['user_account'].insert_one(new_data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le compte intranet du client (1) ")
|
|
return False, " Impossible de créer le compte intranet du client (1) "
|
|
|
|
"""
|
|
Mettre à jour le compte les données client (collection : partner_client )
|
|
avec l'_id du compte
|
|
"""
|
|
|
|
new_client_data = {}
|
|
new_client_data['intranet_account_id'] = str(inserted_id)
|
|
new_client_data['date_update'] = str(now)
|
|
new_client_data['update_by'] = str(my_partner['_id'])
|
|
|
|
ret_val = MYSY_GV.dbname['partner_client'].find_one_and_update(
|
|
{'_id': ObjectId(str(client_id)), },
|
|
{"$set": new_client_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
"""
|
|
A présent que le compte est créé on va envoyer email de notification au client
|
|
avec l'url, le login et pwd
|
|
"""
|
|
local_diction = {}
|
|
local_diction['ref_interne'] = "INTRANET_CLIENT_LOGIN_NOTIF"
|
|
local_diction['type_doc'] = "email"
|
|
local_diction['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
courrier_data_status, courrier_data_retval = mycommon.Get_Courrier_Template_Include_Default_Data(local_diction)
|
|
if (courrier_data_status is False):
|
|
return True, " WARNING : Le compte intranet du client a été mais impossible d'envoyer l'email de notification au client"
|
|
|
|
if ("contenu_doc" not in courrier_data_retval.keys() or str(courrier_data_retval['contenu_doc']) == ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le modèle de courrier 'INTRANET_CLIENT_LOGIN_NOTIF' n'est pas correctement configuré ")
|
|
return False, " Le modèle de courrier 'INTRANET_CLIENT_LOGIN_NOTIF' n'est pas correctement configuré "
|
|
|
|
convention_dictionnary_data = {}
|
|
new_diction = {}
|
|
new_diction['token'] = str(token)
|
|
new_diction['list_stagiaire_id'] = []
|
|
new_diction['list_session_id'] = []
|
|
new_diction['list_class_id'] = []
|
|
new_diction['list_client_id'] = []
|
|
|
|
new_diction['list_client_id'].append(ObjectId(str(diction['partner_client_id'])))
|
|
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
|
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
"""
|
|
Recuperation du partnair_account.subdomaine_catalog_pub
|
|
"""
|
|
subdomaine_catalog_pub = ""
|
|
admin_partnair = MYSY_GV.dbname['partnair_account'].find_one({'recid':str(my_partner['recid']), 'is_partner_admin_account':'1'}, {'subdomaine_catalog_pub':1})
|
|
|
|
if( admin_partnair and 'subdomaine_catalog_pub' in admin_partnair.keys() ):
|
|
subdomaine_catalog_pub = admin_partnair['subdomaine_catalog_pub']
|
|
else:
|
|
return True, " WARNING : Le compte intranet du client a été mais impossible d'envoyer l'email de notification au client "
|
|
|
|
|
|
dictionnary_data = local_retval
|
|
dictionnary_data['intranet_mysyurl'] = subdomaine_catalog_pub+"."+MYSY_GV.MYSY_PUBLIC_CATALOG_DOMAIN+"/intranet"
|
|
dictionnary_data['intranet_login'] = client_email
|
|
dictionnary_data['intranet_pwd'] = str(client_pwd)
|
|
|
|
# Recuperation des donnes smtp
|
|
local_stpm_status, partner_SMTP_COUNT_smtpsrv, partner_own_smtp_value, partner_SMTP_COUNT_password, partner_SMTP_COUNT_user, partner_SMTP_COUNT_From_User, partner_SMTP_COUNT_port = mycommon.Get_Partner_SMTP_Param(
|
|
my_partner['recid'])
|
|
|
|
if (local_stpm_status is False):
|
|
return True, " WARNING : Le compte intranet du client a été mais impossible d'envoyer l'email de notification au client (2) "
|
|
|
|
|
|
body = {
|
|
"params": dictionnary_data,
|
|
}
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
|
else:
|
|
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
|
|
|
smtpserver.ehlo()
|
|
smtpserver.starttls()
|
|
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
|
|
|
# Traitement du sujet du mail
|
|
sujet_mail_Template = jinja2.Template(str(courrier_data_retval['sujet']))
|
|
sujetHtml = sujet_mail_Template.render(params=body["params"])
|
|
|
|
# Traitement du corps du mail
|
|
contenu_doc_Template = jinja2.Template(str(courrier_data_retval['contenu_doc']))
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Creation de l'email à envoyer
|
|
msg = MIMEMultipart("alternative")
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
msg.attach(html_mime)
|
|
msg['From'] = partner_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = sujetHtml
|
|
|
|
#toaddrs = ",".join(client_email)
|
|
msg['to'] = str(client_email)
|
|
|
|
val = smtpserver.send_message(msg)
|
|
print(" Email de notification envoyé " + str(val))
|
|
|
|
else:
|
|
msg.attach(html_mime)
|
|
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = sujetHtml
|
|
|
|
# toaddrs = ",".join(client_email)
|
|
msg['to'] = str(client_email)
|
|
val = smtpserver.send_message(msg)
|
|
print(" Email de notification envoyé " + str(val))
|
|
|
|
smtpserver.close()
|
|
|
|
|
|
return True, " Le compte intranet du client 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 le compte intranet du client "
|
|
|
|
|
|
"""
|
|
Intranet Client :
|
|
Mettre à jour le mot de passe d'un compte client
|
|
"""
|
|
def Update_Pwd_Partner_Client_Intranet_Account(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés. les filtres accepté sont :
|
|
- ref_interne,
|
|
"""
|
|
field_list = ['token', 'partner_client_id', 'default_pwd']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'partner_client_id', 'default_pwd']
|
|
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 la liste des arguments ")
|
|
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']
|
|
|
|
client_pwd = str(diction['default_pwd']).strip()
|
|
|
|
if( len(str(client_pwd)) <= 5):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le mot de passe doit faire plus 5 caractère ")
|
|
return False, " Le mot de passe doit faire plus 5 caractère "
|
|
|
|
if( " " in str(client_pwd) ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Les espaces ne sont pas autorisés dans le mot de passe ")
|
|
return False, " Les espaces ne sont pas autorisés dans le mot de passe "
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
"""
|
|
Verifier la validité du client
|
|
"""
|
|
is_valide_client_partner = MYSY_GV.dbname['partner_client'].count_documents({'_id':ObjectId(str(diction['partner_client_id'])),
|
|
'valide':'1', 'locked':'0',
|
|
'partner_recid':my_partner['recid']})
|
|
|
|
if( is_valide_client_partner != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du client est invalide ")
|
|
return False, " L'identifiant du client est invalide "
|
|
|
|
is_valide_client_partner_data = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(str(diction['partner_client_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_recid': my_partner['recid']})
|
|
|
|
|
|
"""
|
|
Verifier que le compte sur l'intranet existe et est valide
|
|
"""
|
|
|
|
|
|
|
|
is_valide_client_intranet_account = MYSY_GV.dbname['user_account'].count_documents(
|
|
{'_id': ObjectId(str(is_valide_client_partner_data['intranet_account_id'])),
|
|
'active': '1', 'locked': '0',
|
|
'recid': my_partner['recid']})
|
|
|
|
if (is_valide_client_intranet_account != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du compte intranet du client est invalide ")
|
|
return False, " L'identifiant du compte intranet du client est invalide "
|
|
|
|
|
|
client_email = is_valide_client_partner_data['email']
|
|
|
|
now = str(datetime.now())
|
|
|
|
new_data = {}
|
|
new_data['date_update'] = now
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['pwd'] = str(client_pwd)
|
|
|
|
ret_val = MYSY_GV.dbname['user_account'].find_one_and_update(
|
|
{'_id': ObjectId(str(is_valide_client_partner_data['intranet_account_id'])),
|
|
'active': '1', 'locked': '0',
|
|
'recid': my_partner['recid']},
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
return True, " Le compte intranet du client 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 créer le compte intranet du client "
|
|
|
|
|
|
"""
|
|
Intranet client :
|
|
Desactiver un compte
|
|
(mettre active = 0 )
|
|
"""
|
|
def Disable_Partner_Client_Intranet_Account(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés. les filtres accepté sont :
|
|
- ref_interne,
|
|
"""
|
|
field_list = ['token', 'partner_client_id', ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'partner_client_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 la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Verifier la validité du client
|
|
"""
|
|
is_valide_client_partner = MYSY_GV.dbname['partner_client'].count_documents({'_id':ObjectId(str(diction['partner_client_id'])),
|
|
'valide':'1', 'locked':'0',
|
|
'partner_recid':my_partner['recid']})
|
|
|
|
if( is_valide_client_partner != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du client est invalide ")
|
|
return False, " L'identifiant du client est invalide "
|
|
|
|
is_valide_client_partner_data = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(str(diction['partner_client_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_recid': my_partner['recid']})
|
|
|
|
|
|
"""
|
|
Verifier que le compte sur l'intranet existe et est valide
|
|
"""
|
|
is_valide_client_intranet_account = MYSY_GV.dbname['user_account'].count_documents(
|
|
{'_id': ObjectId(str(is_valide_client_partner_data['intranet_account_id'])),
|
|
'active': '1', 'locked': '0',
|
|
'recid': my_partner['recid']})
|
|
|
|
if (is_valide_client_intranet_account != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du compte intranet du client est invalide ")
|
|
return False, " L'identifiant du compte intranet du client est invalide "
|
|
|
|
|
|
client_email = is_valide_client_partner_data['email']
|
|
|
|
now = str(datetime.now())
|
|
|
|
new_data = {}
|
|
new_data['date_update'] = now
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['active'] = "0"
|
|
|
|
ret_val = MYSY_GV.dbname['user_account'].find_one_and_update(
|
|
{'_id': ObjectId(str(is_valide_client_partner_data['intranet_account_id'])),
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
return True, " Le compte intranet du client a été correctement désactivé "
|
|
|
|
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 le compte intranet du client "
|
|
|
|
|
|
|
|
"""
|
|
Intranet Client
|
|
Reactivier un compte intranet client
|
|
"""
|
|
def Enable_Partner_Client_Intranet_Account(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés. les filtres accepté sont :
|
|
- ref_interne,
|
|
"""
|
|
field_list = ['token', 'partner_client_id', ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'partner_client_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 la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Verifier la validité du client
|
|
"""
|
|
is_valide_client_partner = MYSY_GV.dbname['partner_client'].count_documents({'_id':ObjectId(str(diction['partner_client_id'])),
|
|
'valide':'1', 'locked':'0',
|
|
'partner_recid':my_partner['recid']})
|
|
|
|
if( is_valide_client_partner != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du client est invalide ")
|
|
return False, " L'identifiant du client est invalide "
|
|
|
|
is_valide_client_partner_data = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(str(diction['partner_client_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_recid': my_partner['recid']})
|
|
|
|
|
|
"""
|
|
Verifier que le compte sur l'intranet existe et est valide
|
|
"""
|
|
is_valide_client_intranet_account = MYSY_GV.dbname['user_account'].count_documents(
|
|
{'_id': ObjectId(str(is_valide_client_partner_data['intranet_account_id'])),
|
|
'active': '1', 'locked': '0',
|
|
'recid': my_partner['recid']})
|
|
|
|
if (is_valide_client_intranet_account != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du compte intranet du client est invalide ")
|
|
return False, " L'identifiant du compte intranet du client est invalide "
|
|
|
|
|
|
client_email = is_valide_client_partner_data['email']
|
|
|
|
now = str(datetime.now())
|
|
|
|
new_data = {}
|
|
new_data['date_update'] = now
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['active'] = "1"
|
|
|
|
ret_val = MYSY_GV.dbname['user_account'].find_one_and_update(
|
|
{'_id': ObjectId(str(is_valide_client_partner_data['intranet_account_id'])),
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
return True, " Le compte intranet du client a été correctement activé "
|
|
|
|
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 le compte intranet du client "
|
|
|
|
|