501 lines
18 KiB
Python
501 lines
18 KiB
Python
"""
|
|
Ce fichier permet de gerer les coditions de paiement d'un partenaire vers ses clients
|
|
ex : X jours Date de facture
|
|
|
|
champs :
|
|
code
|
|
description
|
|
nb_jour
|
|
depart (fature / mois)
|
|
|
|
"""
|
|
import bson
|
|
import pymongo
|
|
from pymongo import MongoClient
|
|
import json
|
|
from bson import ObjectId
|
|
import re
|
|
from datetime import datetime
|
|
import prj_common as mycommon
|
|
import secrets
|
|
import inspect
|
|
import sys, os
|
|
import csv
|
|
import pandas as pd
|
|
from pymongo import ReturnDocument
|
|
import GlobalVariable as MYSY_GV
|
|
from math import isnan
|
|
import GlobalVariable as MYSY_GV
|
|
import ela_index_bdd_classes as eibdd
|
|
import email_mgt as email
|
|
import jinja2
|
|
from flask import send_file
|
|
from xhtml2pdf import pisa
|
|
from email.message import EmailMessage
|
|
from email.mime.text import MIMEText
|
|
from email import encoders
|
|
import smtplib
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
from email.mime.base import MIMEBase
|
|
from email import encoders
|
|
|
|
"""
|
|
Ajout d'une condition de paiement
|
|
"""
|
|
|
|
def Add_Paiement_Condition(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'code', 'description', 'nb_jour', 'depart']
|
|
|
|
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'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'code', 'description', 'nb_jour', 'depart']
|
|
|
|
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 n'existe pas déjà
|
|
is_existe_cdtion_paiement = MYSY_GV.dbname['base_partner_paiement_condition'].count_documents({'code':str(diction['code']),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
|
|
if( is_existe_cdtion_paiement > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Une condition de paiement avec le code '" + str(diction['code']) + "' existe déjà ")
|
|
return False, " Une condition de paiement avec le code '" + str(diction['code']) + "' existe déjà "
|
|
|
|
|
|
nb_jour = diction['nb_jour']
|
|
nb_jour_status, nb_jour_retval = mycommon.IsInt(nb_jour)
|
|
if( nb_jour_status is False ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le nombre de jours '" + str(diction['nb_jour']) + "' n'est pas un entier ")
|
|
return False, " Le nombre de jours '" + str(diction['nb_jour']) + "' n'est pas un entier "
|
|
|
|
depart = str(diction['depart']).strip().lower()
|
|
if( depart not in MYSY_GV.PAIEMENT_CONDITION_DEPART):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le depart '" + str(diction['depart']) + "' n'est pas autorisé. Les valeurs acceptées sont : "+str(MYSY_GV.PAIEMENT_CONDITION_DEPART))
|
|
return False, " Le depart '" + str(diction['depart']) + "' n'est pas autorisé. Les valeurs acceptées sont : "+str(MYSY_GV.PAIEMENT_CONDITION_DEPART)
|
|
|
|
|
|
new_data = diction
|
|
del diction['token']
|
|
|
|
new_data['depart'] = depart
|
|
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
inserted_id = MYSY_GV.dbname['base_partner_paiement_condition'].insert_one(new_data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le condition de paiement (2) ")
|
|
return False, " Impossible de créer la condition de paiement (2) "
|
|
|
|
|
|
return True, " La condition de paiement a été correctement ajouté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 d'ajouter la condition de paiement "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Mise à jour d'une condition de paiement
|
|
"""
|
|
|
|
def Update_Paiement_Condition(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'code', 'description', 'nb_jour', 'depart', '_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'est pas autorisé")
|
|
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
|
|
|
|
new_data = diction
|
|
|
|
# Verifier que la codition de paiement existe
|
|
is_existe_cdtion_paiement = MYSY_GV.dbname['base_partner_paiement_condition'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_cdtion_paiement < 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Une condition de paiement n'existe pas ")
|
|
return False, " Une condition de paiement n'existe pas "
|
|
|
|
if( "nb_jour" in diction.keys() ):
|
|
nb_jour = diction['nb_jour']
|
|
nb_jour_status, nb_jour_retval = mycommon.IsInt(nb_jour)
|
|
if (nb_jour_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le nombre de jours '" + str(
|
|
diction['nb_jour']) + "' n'est pas un entier ")
|
|
return False, " Le nombre de jours '" + str(diction['nb_jour']) + "' n'est pas un entier "
|
|
|
|
if( "depart" in diction.keys() ):
|
|
depart = str(diction['depart']).strip().lower()
|
|
if (depart not in MYSY_GV.PAIEMENT_CONDITION_DEPART):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le depart '" + str(
|
|
diction['depart']) + "' n'est pas autorisé. Les valeurs acceptées sont : " + str(
|
|
MYSY_GV.PAIEMENT_CONDITION_DEPART))
|
|
return False, " Le depart '" + str(
|
|
diction['depart']) + "' n'est pas autorisé. Les valeurs acceptées sont : " + str(
|
|
MYSY_GV.PAIEMENT_CONDITION_DEPART)
|
|
|
|
new_data['depart'] = depart
|
|
|
|
local_id = str(diction['_id'])
|
|
|
|
del diction['token']
|
|
del diction['_id']
|
|
|
|
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(local_id)
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
result = MYSY_GV.dbname['base_partner_paiement_condition'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le condition de paiement (2) ")
|
|
return False, " Impossible de mettre à jour la condition de paiement (2) "
|
|
|
|
return True, " La condition de paiement a été correctement mise à jour"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de mettre à jour la condition de paiement "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Suppression d'une condition de paiement
|
|
regles :
|
|
Si la condition (_id) n'est pas utiliser dans les collection
|
|
- partner_invoice_header
|
|
- partner_order_header
|
|
"""
|
|
|
|
def Delete_Paiement_Condition(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'est pas autorisé")
|
|
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 la codition de paiement existe
|
|
is_existe_cdtion_paiement = MYSY_GV.dbname['base_partner_paiement_condition'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_cdtion_paiement < 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Une condition de paiement n'existe pas ")
|
|
return False, " Une condition de paiement n'existe pas "
|
|
|
|
|
|
"""
|
|
Verifier que la condition n'est pas utilisée (collection : partner_order_header, partner_invoice_header
|
|
"""
|
|
is_condition_in_partner_order_header = MYSY_GV.dbname['partner_order_header'].count_documents({'partner_owner_recid':my_partner['recid'],
|
|
'valide':'1',
|
|
'order_header_condition_paiement':str(diction['_id'])})
|
|
|
|
|
|
if( is_condition_in_partner_order_header > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Cette condition est utilisée dans "+str(is_condition_in_partner_order_header)+" commandes ")
|
|
return False, " Cette condition est utilisée dans "+str(is_condition_in_partner_order_header)+" commandes "
|
|
|
|
is_condition_in_partner_invoice_header = MYSY_GV.dbname['partner_invoice_header'].count_documents(
|
|
{'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'order_header_condition_paiement': str(diction['_id'])})
|
|
|
|
if (is_condition_in_partner_invoice_header > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Cette condition est utilisée dans " + str(
|
|
is_condition_in_partner_invoice_header) + " factures ")
|
|
return False, " Cette condition est utilisée dans " + str(
|
|
is_condition_in_partner_invoice_header) + " factures "
|
|
|
|
|
|
delete = MYSY_GV.dbname['base_partner_paiement_condition'].delete_one({'_id': ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
}, )
|
|
|
|
|
|
|
|
return True, " La condition de paiement a été correctement supprimée"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de supprimer la condition de paiement "
|
|
|
|
|
|
|
|
"""
|
|
Recuperer la liste des conditions de paiement d'un partenaire
|
|
"""
|
|
def Get_List_Paiement_Condition(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"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['base_partner_paiement_condition'].find(data_cle):
|
|
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 conditions de paiement "
|
|
|
|
|
|
"""
|
|
Recuperer les données d'une conditions de paiement donnée
|
|
"""
|
|
def Get_Given_Paiement_Condition(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
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
data_cle['_id'] = ObjectId(str(diction['_id']))
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['base_partner_paiement_condition'].find(data_cle):
|
|
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 les données de la condition de paiement "
|
|
|
|
|
|
|