diff --git a/wizard/adefpat_project_justif_zip_wizard.py b/wizard/adefpat_project_justif_zip_wizard.py index 01f9310988374cfdfff7de1b634850fc48c9f519..cc073afe9f760a0bc68f37bf7d9bdec62833cb97 100644 --- a/wizard/adefpat_project_justif_zip_wizard.py +++ b/wizard/adefpat_project_justif_zip_wizard.py @@ -28,9 +28,36 @@ class AdefpatProjectJustifZip(models.TransientModel): string="Type de convention de financement", ) - # function will trigger from the show report button @api.multi - def build_folder(self): + def build_folder_bilan(self): + json_file = [] + json_file_proj = self.build_json_project("11") + json_file.append(json_file_proj) + json_file_ff = self.build_json_file_facture_fournisseur("21") + json_file.append(json_file_ff) + json_file_fc = self.build_json_file_facture_client("31") + json_file.append(json_file_fc) + json_file_frais = self.build_json_file_expense_zip("41") + json_file.append(json_file_frais) + + virtual_json = { + "name": "Bilan", + "nodes": [{ + "id": "1", + "name": "Bilan", + "description": "Bilan", + "nodes": json_file, + }] + } + if self.type_convention_id: + file_name = "bilan"+ str(datetime.now().strftime("%y-%m-%d-%H-%M")) + "_" + self.type_convention_id.name + else: + file_name = "bilan"+ str(datetime.now().strftime("%y-%m-%d-%H-%M")) + json_file_cmis = self.env.user.company_id.proof_justif_cmis + self.create_json_file(file_name, virtual_json, json_file_cmis) + + @api.multi + def build_json_project(self, bilan_nb=None): # Get Projects with at least 1 task on period project_ids = self.env["project.task"].search([ ("date_deadline", "<=", self.period_end), @@ -47,12 +74,12 @@ class AdefpatProjectJustifZip(models.TransientModel): compteur += 1 path = "PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Projets/" + project.name json_file.append({ - "id": "1" + str(compteur), + "id": bilan_nb + str(compteur), "name": project.name, "description": project.name, "nodes":[ { - "id": "1" + str(compteur) + "1", + "id": bilan_nb + str(compteur) + "1", "name": "CR séance", "description": "Compte-Rendus des séances d’accompagnement", "search": { @@ -61,7 +88,7 @@ class AdefpatProjectJustifZip(models.TransientModel): } }, { - "id": "1" + str(compteur) + "2", + "id": bilan_nb + str(compteur) + "2", "name": "GAP", "description": "Compte-Rendus des séances de GAP", "search": { @@ -70,7 +97,7 @@ class AdefpatProjectJustifZip(models.TransientModel): }, }, { - "id": "1" + str(compteur) + "3", + "id": bilan_nb + str(compteur) + "3", "name": "Evaluation CF", "description": "Evaluation finale du consultant formateur", "search": { @@ -79,7 +106,7 @@ class AdefpatProjectJustifZip(models.TransientModel): }, }, { - "id": "1" + str(compteur) + "4", + "id": bilan_nb + str(compteur) + "4", "name": "Evaluation stagiaire", "description": "Questionnaire de satisfaction de chaque stagiaire", "search": { @@ -88,7 +115,7 @@ class AdefpatProjectJustifZip(models.TransientModel): }, }, { - "id": "1" + str(compteur) + "5", + "id": bilan_nb + str(compteur) + "5", "name": "Consultations", "description": "Consultations", "search": { @@ -97,7 +124,7 @@ class AdefpatProjectJustifZip(models.TransientModel): }, }, { - "id": "1" + str(compteur) + "6", + "id": bilan_nb + str(compteur) + "6", "name": "Conventions", "description": "Conventions", "search": { @@ -110,12 +137,18 @@ class AdefpatProjectJustifZip(models.TransientModel): virtual_json = { "name": "Justificatifs Projets", "nodes": [{ - "id": "1", + "id": bilan_nb, "name": "Justificatifs Projets", "description": "Justificatifs Projets", "nodes": json_file, }] } + return virtual_json + + @api.multi + def build_folder(self): + virtual_json = self.build_json_project("1") + if self.type_convention_id: file_name = "justifs_projets_"+ str(datetime.now().strftime("%y-%m-%d-%H-%M")) + "_" + self.type_convention_id.name else: @@ -124,21 +157,29 @@ class AdefpatProjectJustifZip(models.TransientModel): self.create_json_file(file_name, virtual_json, json_file_cmis) @api.multi - def build_facture_fournisseur(self): - + def build_json_file_facture_fournisseur(self, bilan_nb=None): virtual_json = { - "name" : "Factures fournisseurs", - "nodes" : [{ - "id" : "1", - "name" : "Factures fournisseurs", - "description" : "Factures fournisseurs", - "search" : { - "language" : "fts-alfresco", - "query" : "(PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Factures_x0020_fournisseurs//*') AND (+adefpat:factureEndDate:['" + str(self.period_start) + "' TO '" + str(self.period_end) +"'] OR +adefpat:factureSartDate:['" + str(self.period_start) + "' TO '" + str(self.period_end) +"'])", - } - }, + "name": "Factures fournisseurs", + "nodes": [{ + "id": bilan_nb, + "name": "Factures fournisseurs", + "description": "Factures fournisseurs", + "search": { + "language": "fts-alfresco", + "query": "(PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Factures_x0020_fournisseurs//*') AND (+adefpat:factureEndDate:['" + str( + self.period_start) + "' TO '" + str( + self.period_end) + "'] OR +adefpat:factureSartDate:['" + str( + self.period_start) + "' TO '" + str(self.period_end) + "'])", + } + }, ] } + return virtual_json + + @api.multi + def build_facture_fournisseur(self): + + virtual_json = self.build_json_file_facture_fournisseur("1") if self.type_convention_id: file_name = "justifs_factures_fournisseurs_" + str(datetime.now().strftime("%y-%m-%d-%H-%M")) + "_" + self.type_convention_id.name else: @@ -147,8 +188,7 @@ class AdefpatProjectJustifZip(models.TransientModel): return self.create_json_file(file_name, virtual_json, json_file_cmis) @api.multi - def build_facture_client(self): - + def build_json_file_facture_client(self, bilan_nb=None): if self.type_convention_id: query = "(PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Factures_x0020_clients//*') AND (+adefpat:factureStartDate:['" + str(self.period_start) + "' TO '" + str(self.period_end) +"']) AND =adefpat:factureTypeConvention:'"+ self.type_convention_id.name +"'" else: @@ -158,7 +198,7 @@ class AdefpatProjectJustifZip(models.TransientModel): virtual_json = { "name": "Factures clients", "nodes": [{ - "id": "1", + "id": bilan_nb, "name": "Factures clients", "description": "Factures clients", "search": { @@ -168,6 +208,12 @@ class AdefpatProjectJustifZip(models.TransientModel): }, ] } + return virtual_json + + @api.multi + def build_facture_client(self): + + virtual_json = self.build_json_file_facture_client("1") if self.type_convention_id: file_name = "justifs_factures_clients_" + str(datetime.now().strftime("%y-%m-%d-%H-%M")) + "_" + self.type_convention_id.name else: @@ -176,7 +222,7 @@ class AdefpatProjectJustifZip(models.TransientModel): return self.create_json_file(file_name, virtual_json, json_file_cmis) @api.multi - def build_expense_zip(self): + def build_json_file_expense_zip(self, bilan_nb=None): user_ids = self.env["res.users"].search([("active", "=", True)]) compteur = 0 @@ -194,7 +240,7 @@ class AdefpatProjectJustifZip(models.TransientModel): self.period_end) + "'])" compteur += 1 json_file.append({ - "id": "1" + str(compteur), + "id": bilan_nb + str(compteur), "name": user.name, "description": user.name, "search": { @@ -206,12 +252,18 @@ class AdefpatProjectJustifZip(models.TransientModel): virtual_json = { "name": "Justificatifs Frais", "nodes": [{ - "id": "1", + "id": bilan_nb, "name": "Justificatifs Frais", "description": "Justificatifs Frais", "nodes": json_file, }] } + return virtual_json + + @api.multi + def build_expense_zip(self): + + virtual_json = self.build_json_file_expense_zip("1") if self.type_convention_id: file_name = "justifs_frais_" + str( datetime.now().strftime("%y-%m-%d-%H-%M")) + "_" + self.type_convention_id.name diff --git a/wizard/adefpat_project_justif_zip_wizard.xml b/wizard/adefpat_project_justif_zip_wizard.xml index d93b807740ce77423c57bb2401e3a0866f6e572d..48e7f8d727c1511fb50d6755610e382dc3b5be29 100644 --- a/wizard/adefpat_project_justif_zip_wizard.xml +++ b/wizard/adefpat_project_justif_zip_wizard.xml @@ -15,6 +15,12 @@ </group> </group> <footer> + <button + class="btn btn-sm btn-primary" + name="build_folder_bilan" + string="Bilan" + type="object" + /> <button class="btn btn-sm btn-primary" name="build_folder"