""" Ce fichier permet de traiter et generer le BPF SPEC : Source : https://culture-rh.com/bfp-bilan-pedagogique-financier/ """ import ast import dateutil import pymongo import xlsxwriter from flask import send_file from pymongo import MongoClient import json from bson import ObjectId import re from datetime import datetime, timezone, date 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 from datetime import timedelta from datetime import timedelta import Dashbord_queries.formation_tbd_qries as formation_tbd_qries from dateutil.relativedelta import relativedelta def Get_Qery_Generate_BPF_From_partner_invoice_header(diction): try: diction = mycommon.strip_dictionary(diction) """ Verification des input acceptés """ field_list = ['token', 'periode_start_date', 'periode_end_date', 'filter_value', ] 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 liste ") return False, " Les informations fournies sont incorrectes", """ Verification de l'identité et autorisation de l'entité qui appelle cette API """ token = "" if ("token" in diction.keys()): if diction['token']: token = diction['token'] local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction) if (local_status is not True): return local_status, my_partner filt_client_id = {} if ("filter_client_id" in diction.keys() and diction['filter_client_id']): filt_client_id = {'order_header_client_id': str(diction['filter_client_id'])} filt_periode_start_date = "" if ("periode_start_date" in diction.keys() and diction['periode_start_date']): filt_periode_start_date = str(diction['periode_start_date'])[0:10] local_status = mycommon.CheckisDate(filt_periode_start_date) if (local_status is False): mycommon.myprint(str( inspect.stack()[0][3]) + " Le filtre : 'date de debut' n'est pas au format jj/mm/aaaa.") return False, " Le filtre : 'date de debut' n'est pas au format jj/mm/aaaa." filt_periode_end_date = "" if ("periode_end_date" in diction.keys() and diction['periode_end_date']): filt_periode_end_date = str(diction['periode_end_date'])[0:10] local_status = mycommon.CheckisDate(filt_periode_end_date) if (local_status is False): mycommon.myprint(str( inspect.stack()[0][3]) + " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa.") return False, " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa." """ Si la valeur de 'filter_value' est m0 ou m1, on va aller recuperer les date du mois correspondant. On ecrase les valeur de filt_session_start_date et filt_session_end_date """ if ('filter_value' in diction.keys()): # print(" filter_value = ", diction['filter_value']) if (str(diction['filter_value']) == "m0"): # On recupere les date du mois en cours local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date() if (local_status is False): return local_status, start_current_month_date filt_periode_start_date = start_current_month_date filt_periode_end_date = end_current_month_date # print(" ### filt_session_start_date = ", filt_session_start_date, " ### filt_session_end_date = ", filt_session_end_date) elif (str(diction['filter_value']) == "m1"): # On recupere les date du mois en cours local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date() if (local_status is False): return local_status, start_current_month_date filt_periode_start_date = start_current_month_date filt_periode_end_date = end_current_month_date filt_periode_start_date_ISODATE = datetime.strptime(str(filt_periode_start_date), '%d/%m/%Y') filt_periode_end_date_ISODATE = datetime.strptime(str(filt_periode_end_date), '%d/%m/%Y') RetObject = [] val_tmp = 0 """ C1 – Quelles sont vos ressources provenant directement des entreprises pour la formation de leurs salariés ? On recherche le CA venant des client : is_client = 1, is_financeur != 1 """ C1_qery_match = {'$and': [{"partner_owner_recid": str(my_partner['recid'])}, {"valide": '1'}, { 'mysy_invoice_date': {'$gte': filt_periode_start_date_ISODATE, '$lte': filt_periode_end_date_ISODATE}}, ]} C1_pipe_qry = ([ {"$addFields": { "mysy_invoice_date": { '$dateFromString': { 'dateString': '$invoice_date', 'format': "%d/%m/%Y" } } } }, {'$match': C1_qery_match}, {'$lookup': { 'from': 'partner_client', "let": {'order_header_client_id': "$order_header_client_id", 'partner_owner_recid': '$partner_owner_recid'}, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$order_header_client_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_recid", '$$partner_owner_recid']}, {'$eq': ["is_client", "1"]}, {'$ne': ["is_financeur", "1"]}, ] } } }, ], 'as': 'partner_client_collection' } }, {'$group': { "TotalAmount": {"$sum": {'$toDouble': '$total_header_toutes_taxes'}}, "count": {"$sum": 1} } }, ]) print(" ### Get_Qery_Generate_BPF C1_pipe_qry = ", C1_pipe_qry) C2_pipe_qry = ([ {"$addFields": { "mysy_invoice_date": { '$dateFromString': { 'dateString': '$invoice_date', 'format': "%d/%m/%Y" } } } }, {'$match': C1_qery_match}, {'$lookup': { 'from': 'partner_client', "let": {'order_header_client_id': "$order_header_client_id", 'partner_owner_recid': '$partner_owner_recid'}, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$order_header_client_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_recid", '$$partner_owner_recid']} ] } } }, ], 'as': 'partner_client_collection' } }, { '$unwind': '$partner_client_collection' }, {'$lookup': { 'from': 'partner_client_type', "let": {'client_type_id': "$partner_client_collection.client_type_id", 'partner_recid': '$partner_recid' }, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$client_type_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_client_collection.partner_recid", '$$partner_recid']}, ] } } }, ], 'as': 'partner_client_type_collection' } }, {'$group': { '_id': { "Client_type": "$partner_client_type_collection.code", }, "TotalAmount": {"$sum": {'$toDouble': '$total_header_toutes_taxes'}}, "count": {"$sum": 1} } }, ]) print(" ### Get_Qery_Generate_BPF C2_pipe_qry = ", C2_pipe_qry) C2_pipe_qry_invoice_header_partner__invoice_line_detail__partner_type_organisme_financement__type_apprenant = ([ {"$addFields": { "mysy_invoice_date": { '$dateFromString': { 'dateString': '$invoice_date', 'format': "%d/%m/%Y" } } } }, {'$match': {'invoice_header_type':'facture', 'credit_note_ref': {'$exists': False}, 'invoice_header_ref_interne':{'$in':['Invoice_567', 'Invoice_568', 'Invoice_569', 'Invoice_570', 'Invoice_571', 'Invoice_572', 'Invoice_573' ]} } }, {'$lookup': { 'from': 'partner_invoice_line_detail', "let": {"invoice_header_id": {'$toString': "$_id"}, 'partner_invoice_line_partner_owner_recid': '$partner_owner_recid', 'partner_invoice_line_invoice_header_ref_interne': '$invoice_header_ref_interne'}, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$valide", "1"]}, {'$eq': ["$invoice_header_ref_interne",'$$partner_invoice_line_invoice_header_ref_interne']}, {'$eq': ["$partner_owner_recid", '$$partner_invoice_line_partner_owner_recid']}, ] } } }, ], 'as': 'collection_partner_invoice_line' } }, { '$unwind': '$collection_partner_invoice_line' }, {'$lookup': { 'from': 'type_organisme_financement', "let": {'type_financeur_id': "$order_header_type_financeur_id", }, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$type_financeur_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, ] } } }, ], 'as': 'type_organisme_financement_collection' } }, { '$unwind': '$type_organisme_financement_collection' }, {'$lookup': { 'from': 'type_apprenant', "let": {'type_apprenant_code': "$collection_partner_invoice_line.order_line_inscription_type_apprenant", }, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$valide", "1"]}, {'$eq': ["$code",'$$type_apprenant_code']}, ] } } }, ], 'as': 'type_apprenante_collection' } }, { '$unwind': '$type_apprenante_collection' }, {'$group': { '_id': { "Type Apprenant": "$collection_partner_invoice_line.order_line_inscription_type_apprenant", "Type Apprenant Description": "$type_apprenante_collection.description", }, "TotalAmount_HT": { "$sum": {'$toDouble': '$collection_partner_invoice_line.order_line_invoiced_amount'}}, "count": {"$sum": 1} } }, { '$sort': {'count': -1} }, ]) C3_C8_pipe_qry_invoice_header_partner__invoice_line_detail__partner_type_pouvoir_public = ([ {"$addFields": { "mysy_invoice_date": { '$dateFromString': { 'dateString': '$invoice_date', 'format': "%d/%m/%Y" } } } }, {'$match': {'invoice_header_type':'facture', 'credit_note_ref': {'$exists': False}, 'invoice_header_ref_interne':{'$in':['Invoice_588', 'Invoice_589', 'Invoice_590', 'Invoice_591', 'Invoice_592', 'Invoice_593', 'Invoice_594', 'Invoice_595' ]} } }, {'$lookup': { 'from': 'partner_invoice_line_detail', "let": {"invoice_header_id": {'$toString': "$_id"}, 'partner_invoice_line_partner_owner_recid': '$partner_owner_recid', 'partner_invoice_line_invoice_header_ref_interne': '$invoice_header_ref_interne'}, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$valide", "1"]}, {'$eq': ["$invoice_header_ref_interne",'$$partner_invoice_line_invoice_header_ref_interne']}, {'$eq': ["$partner_owner_recid", '$$partner_invoice_line_partner_owner_recid']}, ] } } }, ], 'as': 'collection_partner_invoice_line' } }, { '$unwind': '$collection_partner_invoice_line' }, {'$lookup': { 'from': 'type_pouvoir_public', "let": {'order_header_type_pouvoir_public_id': "$order_header_type_pouvoir_public_id", }, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$order_header_type_pouvoir_public_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, ] } } }, ], 'as': 'type_pouvoir_public_collection' } }, { '$unwind': '$type_pouvoir_public_collection' }, {'$group': { '_id': { "Type pouvoir public": "$type_pouvoir_public_idt", "Type pouvoir public": "$type_pouvoir_public_collection.description", }, "TotalAmount_HT": { "$sum": {'$toDouble': '$collection_partner_invoice_line.order_line_invoiced_amount'}}, "count": {"$sum": 1} } }, { '$sort': {'count': -1} }, ]) C9_pipe_qry_invoice_header_partner__invoice_line_detail__partner_type_pouvoir_public = ([ {"$addFields": { "mysy_invoice_date": { '$dateFromString': { 'dateString': '$invoice_date', 'format': "%d/%m/%Y" } } } }, {'$match': {'invoice_header_type':'facture', 'credit_note_ref': {'$exists': False}, 'order_header_is_company':'0', 'invoice_header_ref_interne':{'$in':['Invoice_588', 'Invoice_589', 'Invoice_590', 'Invoice_591', 'Invoice_592', 'Invoice_593', 'Invoice_594', 'Invoice_595' ]} } }, {'$lookup': { 'from': 'partner_invoice_line_detail', "let": {"invoice_header_id": {'$toString': "$_id"}, 'partner_invoice_line_partner_owner_recid': '$partner_owner_recid', 'partner_invoice_line_invoice_header_ref_interne': '$invoice_header_ref_interne'}, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$valide", "1"]}, {'$eq': ["$invoice_header_ref_interne",'$$partner_invoice_line_invoice_header_ref_interne']}, {'$eq': ["$partner_owner_recid", '$$partner_invoice_line_partner_owner_recid']}, ] } } }, ], 'as': 'collection_partner_invoice_line' } }, { '$unwind': '$collection_partner_invoice_line' }, {'$group': { '_id': { "Type Client": "$order_header_is_company", "Type Client public": "Client Type Particulier", }, "TotalAmount_HT": { "$sum": {'$toDouble': '$collection_partner_invoice_line.order_line_invoiced_amount'}}, "count": {"$sum": 1} } }, { '$sort': {'count': -1} }, ]) E_pipe_qry_ressource_humaine__ressource_humaine_contrat__partner_agenda = ([ {'$project': {'list_competence': 0, }}, {'$lookup': { 'from': 'ressource_humaine_contrat', 'let': {'rh_id': {'$toString': '$_id'}, 'rh_partner_owner_recid': '$partner_recid'}, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ['$valide', '1']}, {'$eq': ['$rh_id', '$$rh_id']}, {'$eq': ['$partner_owner_recid', '$$rh_partner_owner_recid']} ] } } }, {"$project": {"_id": 0, }} ], 'as': 'collection_ressource_humaine_contrat' } }, { '$unwind': '$collection_ressource_humaine_contrat' }, {'$lookup': { 'from': 'agenda', "let": {"rh_id": {'$toString': "$_id"}, 'rh_partner_owner_recid':'$partner_recid'}, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$valide", "1"]}, {'$eq': ["$related_collection_recid", '$$rh_id']}, {'$eq': ["$partner_owner_recid", '$$rh_partner_owner_recid']}, ] } } }, ], 'as': 'collection_agenda' } }, ]) F1_pipe_qry_invoice_header_partner__invoice_line_detail__partner_type_pouvoir_public = ([ {"$addFields": { "mysy_date_debut_session": { '$dateFromString': { 'dateString': '$date_du', 'format': "%d/%m/%Y" } } } }, {'$project': {'_id': 1, 'email': 1, 'session_id': 1, 'nom': 1, 'prenom':1, 'partner_owner_recid':1, 'valide':1, 'type_apprenant':1}}, {'$match': {'session_id':'66cdeb5d7e8061b7b6f9b066'} }, {'$lookup': { 'from': 'session_formation', 'let': {'session_id': "$session_id", 'partner_owner_recid': '$partner_owner_recid'}, 'pipeline': [ {'$project': {'_id': 1, 'code_session': 1, 'class_internal_url': 1, 'date_debut': 1, 'date_fin':1, 'nb_participant':1, 'partner_owner_recid':1, 'valide':1}}, {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$session_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_owner_recid", '$$partner_owner_recid']} ] } } }, ], 'as': 'session_formation_collection' } }, { '$unwind': '$session_formation_collection' }, { "$lookup": { 'from': 'myclass', 'localField': 'session_formation_collection.class_internal_url', 'foreignField': 'internal_url', "pipeline": [{'$project': {'title': 1, 'internal_url': 1, 'external_code': 1, 'published': 1, 'duration':1, 'duration_unit':1}} ], "as": "myclass_collection" } }, { '$unwind': '$myclass_collection' }, {'$lookup': { 'from': 'type_apprenant', "let": {'type_apprenant_code': "$type_apprenant", }, 'pipeline': [ {'$project': {'_id': 1, 'code': 1, 'description': 1, 'valide':1}}, {'$match': {'$expr': {'$and': [ {'$eq': ["$valide", "1"]}, {'$eq': ["$code",'$$type_apprenant_code']}, ] } } }, ], 'as': 'type_apprenante_collection' } }, { '$unwind': '$type_apprenante_collection' }, {'$group': { '_id': { "Type Apprenant": "$type_apprenant", "Type Apprenant Description": "$type_apprenante_collection.description", }, "TotalAmount_HT": { "$sum": 1}, "count": {"$sum": 1} } }, { '$sort': {'count': -1} }, ]) 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 " def Get_Qery_Generate_BPF_From_Inscription(diction): try: diction = mycommon.strip_dictionary(diction) """ Verification des input acceptés """ field_list = ['token', 'periode_start_date', 'periode_end_date', 'filter_value', ] 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 liste ") return False, " Les informations fournies sont incorrectes", """ Verification de l'identité et autorisation de l'entité qui appelle cette API """ token = "" if ("token" in diction.keys()): if diction['token']: token = diction['token'] local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction) if (local_status is not True): return local_status, my_partner filt_client_id = {} if ("filter_client_id" in diction.keys() and diction['filter_client_id']): filt_client_id = {'order_header_client_id': str(diction['filter_client_id'])} filt_periode_start_date = "" if ("periode_start_date" in diction.keys() and diction['periode_start_date']): filt_periode_start_date = str(diction['periode_start_date'])[0:10] local_status = mycommon.CheckisDate(filt_periode_start_date) if (local_status is False): mycommon.myprint(str( inspect.stack()[0][3]) + " Le filtre : 'date de debut' n'est pas au format jj/mm/aaaa.") return False, " Le filtre : 'date de debut' n'est pas au format jj/mm/aaaa." filt_periode_end_date = "" if ("periode_end_date" in diction.keys() and diction['periode_end_date']): filt_periode_end_date = str(diction['periode_end_date'])[0:10] local_status = mycommon.CheckisDate(filt_periode_end_date) if (local_status is False): mycommon.myprint(str( inspect.stack()[0][3]) + " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa.") return False, " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa." """ Si la valeur de 'filter_value' est m0 ou m1, on va aller recuperer les date du mois correspondant. On ecrase les valeur de filt_session_start_date et filt_session_end_date """ if ('filter_value' in diction.keys()): # print(" filter_value = ", diction['filter_value']) if (str(diction['filter_value']) == "m0"): # On recupere les date du mois en cours local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date() if (local_status is False): return local_status, start_current_month_date filt_periode_start_date = start_current_month_date filt_periode_end_date = end_current_month_date # print(" ### filt_session_start_date = ", filt_session_start_date, " ### filt_session_end_date = ", filt_session_end_date) elif (str(diction['filter_value']) == "m1"): # On recupere les date du mois en cours local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date() if (local_status is False): return local_status, start_current_month_date filt_periode_start_date = start_current_month_date filt_periode_end_date = end_current_month_date filt_periode_start_date_ISODATE = datetime.strptime(str(filt_periode_start_date), '%d/%m/%Y') filt_periode_end_date_ISODATE = datetime.strptime(str(filt_periode_end_date), '%d/%m/%Y') RetObject = [] val_tmp = 0 """ Voici une requete qui fait une jointure entre - Inscription, Client, Type_Client, Facture """ C1_qery_match = {'$and': [{"partner_owner_recid": str(my_partner['recid'])}, {"valide": '1'}, { 'mysy_invoice_date': {'$gte': filt_periode_start_date_ISODATE, '$lte': filt_periode_end_date_ISODATE}}, ]} Inscription_Client_Type_Client_Facture_pipe_qry = ([ {'$match': {'invoiced':'1'} }, {'$lookup': { 'from': 'partner_client', "let": {'facture_client_rattachement_id': "$facture_client_rattachement_id", 'partner_owner_recid': '$partner_owner_recid'}, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$facture_client_rattachement_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_recid", '$$partner_owner_recid']}, ] } } }, ], 'as': 'partner_client_collection' } }, { '$unwind': '$partner_client_collection' }, {'$lookup': { 'from': 'partner_client_type', "let": {'client_type_id': "$partner_client_collection.client_type_id", 'partner_recid': '$partner_recid', }, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$client_type_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_client_collection.partner_recid", '$$partner_recid']}, ] } } }, ], 'as': 'partner_client_type_collection' } }, {'$lookup': { 'from': 'partner_invoice_header', "let": {'facture_client_rattachement_id': "$facture_client_rattachement_id", 'invoiced_ref': "$invoiced_ref", 'partner_owner_recid': '$partner_owner_recid' }, 'pipeline': [ { "$addFields": { "mysy_invoice_date": { '$dateFromString': { 'dateString': '$invoice_date', 'format': "%d/%m/%Y" } } } }, {'$match': {'$expr': {'$and': [ {'$eq': ["$invoice_header_ref_interne", '$$invoiced_ref']}, {'$eq': ["$order_header_client_id", '$$facture_client_rattachement_id']}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}, ] } } }, ], 'as': 'partner_invoice_header_collection' } }, ]) print(" ### Get_Qery_Generate_BPF_From_Inscription Inscription_Client_Type_Client_Facture_pipe_qry = ", Inscription_Client_Type_Client_Facture_pipe_qry) Inscription_Client_Type_Client_Facture_pipe_qry_Client_Financeur = ([ {'$match': {'invoiced': '1'}}, {'$lookup': { 'from': 'partner_client', "let": {'facture_client_rattachement_id': "$facture_client_rattachement_id", 'partner_owner_recid': '$partner_owner_recid'}, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$facture_client_rattachement_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_recid", '$$partner_owner_recid']}, {'$eq': ["$is_financeur", '1']}, ] } } }, ], 'as': 'partner_client_collection' } }, { '$unwind': '$partner_client_collection' }, {'$lookup': { 'from': 'partner_client_type', "let": {'client_type_id': "$partner_client_collection.client_type_id", 'partner_recid': '$partner_recid', }, 'pipeline': [ {'$match': {'$expr': {'$and': [ {'$eq': ["$_id", {'$convert': { 'input': "$$client_type_id", 'to': "objectId", 'onError': {'error': 'true'}, 'onNull': {'isnull': 'true'} }}]}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_client_collection.partner_recid", '$$partner_recid']}, ] } } }, ], 'as': 'partner_client_type_collection' } }, {'$lookup': { 'from': 'partner_invoice_header', "let": {'facture_client_rattachement_id': "$facture_client_rattachement_id", 'invoiced_ref': "$invoiced_ref", 'partner_owner_recid': '$partner_owner_recid' }, 'pipeline': [ { "$addFields": { "mysy_invoice_date": { '$dateFromString': { 'dateString': '$invoice_date', 'format': "%d/%m/%Y" } } } }, {'$match': {'$expr': {'$and': [ {'$eq': ["$invoice_header_ref_interne", '$$invoiced_ref']}, {'$eq': ["$order_header_client_id", '$$facture_client_rattachement_id']}, {'$eq': ["$valide", "1"]}, {'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}, ] } } }, ], 'as': 'partner_invoice_header_collection' } }, ]) print(" ### Get_Qery_Generate_BPF_From_Inscription Inscription_Client_Type_Client_Facture_pipe_qry_Client_Financeur = ", Inscription_Client_Type_Client_Facture_pipe_qry) 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 "