From 3970592d7c3e6b79980a6ace9dabb94956a7f406 Mon Sep 17 00:00:00 2001 From: Juliana <juliana@le-filament.com> Date: Tue, 19 Jul 2022 17:40:35 +0200 Subject: [PATCH] [ADD]Attach json file to folder virtual --- wizard/adefpat_project_justif_zip_wizard.py | 61 ++++++++++++++++----- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/wizard/adefpat_project_justif_zip_wizard.py b/wizard/adefpat_project_justif_zip_wizard.py index b606180..b81c1cc 100644 --- a/wizard/adefpat_project_justif_zip_wizard.py +++ b/wizard/adefpat_project_justif_zip_wizard.py @@ -11,6 +11,7 @@ from odoo.exceptions import UserError class AdefpatProjectJustifZip(models.TransientModel): _name = "adefpat.project.justif.zip.wizard" + _inherit = 'lefilament.alfresco' _description = "Wizard justifs zip projets" period_start = fields.Date("Début de période", required=True) @@ -116,9 +117,9 @@ class AdefpatProjectJustifZip(models.TransientModel): }] } if self.type_convention_id: - file_name = "justifs_projets_"+ str(date.today()) + "_" + self.type_convention_id.name + ".json" + file_name = "justifs_projets_"+ str(date.today()) + "_" + self.type_convention_id.name else: - file_name = "justifs_projets_"+ str(date.today()) +".json" + file_name = "justifs_projets_"+ str(date.today()) self.create_json_file(file_name, virtual_json) @api.multi @@ -138,9 +139,9 @@ class AdefpatProjectJustifZip(models.TransientModel): ] } if self.type_convention_id: - file_name = "justifs_factures_fournisseurs_"+ str(date.today()) + "_" + self.type_convention_id.name + ".json" + file_name = "justifs_factures_fournisseurs_"+ str(date.today()) + "_" + self.type_convention_id.name else: - file_name = "justifs_factures_fournisseurs_"+ str(date.today()) +".json" + file_name = "justifs_factures_fournisseurs_"+ str(date.today()) self.create_json_file(file_name, virtual_json) @api.multi @@ -166,9 +167,9 @@ class AdefpatProjectJustifZip(models.TransientModel): ] } if self.type_convention_id: - file_name = "justifs_factures_clients_"+ str(date.today()) + "_" + self.type_convention_id.name + ".json" + file_name = "justifs_factures_clients_"+ str(date.today()) + "_" + self.type_convention_id.name else: - file_name = "justifs_factures_clients_"+ str(date.today()) +".json" + file_name = "justifs_factures_clients_"+ str(date.today()) self.create_json_file(file_name, virtual_json) @api.multi @@ -210,28 +211,60 @@ class AdefpatProjectJustifZip(models.TransientModel): } if self.type_convention_id: file_name = "justifs_frais_" + str( - date.today()) + "_" + self.type_convention_id.name + ".json" + date.today()) + "_" + self.type_convention_id.name else: file_name = "justifs_frais_" + str( - date.today()) + ".json" + date.today()) self.create_json_file(file_name, virtual_json) def create_json_file(self, file_name, virtual_json): - js = json.dumps(virtual_json, indent=4) - prop = { - 'cmis:secondaryObjectTypeIds': ['P:adefpat:justificatif'], - } + backend = self.env['cmis.backend'].search([], limit=1) json_file_cmis = self.env.user.company_id.proof_justif_cmis - repo = backend.get_cmis_repository().getObject(json_file_cmis) + parent_path = backend.get_cmis_repository().getFolder( + json_file_cmis).getPaths() + + path_to_create = parent_path + [file_name] + path = '/'.join(path_to_create) try: + # Mise à jour des propriétés du dossier virtuel + cmis_folder = backend.get_folder_by_path(path) + + js = json.dumps(virtual_json, indent=4) + prop = { + 'cmis:secondaryObjectTypeIds': ['P:adefpat:justificatif'], + } + + repo = backend.get_cmis_repository().getObject(json_file_cmis) file = repo.createDocument( - name=file_name, + name=file_name + ".json", properties=prop, contentFile=js, contentType="application/json" ) + noderef_file_id = file.getProperties().get('alfcmis:nodeRef') + prop_folder = { + 'cmis:secondaryObjectTypeIds': [ + 'P:smf:customConfigSmartFolder', + 'P:cm:taggable', + 'P:up:UploadFolder', + 'P:cm:titled', + 'P:sys:localized' + ], + } + + cmis_folder.updateProperties(prop_folder) + noderef_folder_id = cmis_folder.getProperties().get('cmis:objectId') + url = '/alfresco/s/api/node/workspace/SpacesStore/' + noderef_folder_id + '/formprocessor' + result = self.alfresco_get_by_url( + url=url, + call_type='post', + json={ + "assoc_smf_custom-template-association_added": noderef_file_id + }, + backend=backend) + except Exception as e: raise UserError(json.loads(e.details).get('message')) \ No newline at end of file -- GitLab