diff --git a/views/account_views.xml b/views/account_views.xml index 204a339ef368b83d7595e401eaa262f4fa603a42..2b1a039677bb3230dbaac63b77e5406892b14b9c 100644 --- a/views/account_views.xml +++ b/views/account_views.xml @@ -17,7 +17,7 @@ /> <button name="delete_file" - string="Supprimer le fichier" + string="Supprimer le justificatif" type="object" attrs="{'invisible': [('proof_file', '=', False)]}" /> @@ -46,7 +46,7 @@ /> <button name="delete_file" - string="Supprimer le fichier" + string="Supprimer le justificatif" type="object" attrs="{'invisible': [('proof_file', '=', False)]}" /> diff --git a/wizard/adefpat_project_justif_zip_wizard.py b/wizard/adefpat_project_justif_zip_wizard.py index c5f554ecdeac97c28d14405cf3e0293a041d9fe9..b606180977be190e22348a651f99e7c7fab6a382 100644 --- a/wizard/adefpat_project_justif_zip_wizard.py +++ b/wizard/adefpat_project_justif_zip_wizard.py @@ -45,7 +45,6 @@ class AdefpatProjectJustifZip(models.TransientModel): for project in project_ids: compteur += 1 path = "PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Projets/" + project.name - # virtual_json["nodes"]["nodes"].append({ json_file.append({ "id": "1" + str(compteur), "name": project.name, @@ -116,24 +115,11 @@ class AdefpatProjectJustifZip(models.TransientModel): "nodes": json_file, }] } - - js = json.dumps(virtual_json, indent=4) - prop = { - 'cmis:secondaryObjectTypeIds': ['P:adefpat:justificatif'], - } - # 'adefpat:financementConvention': str(self.type_convention_id.name), - 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) - try: - file = repo.createDocument( - name="justifs_projets_"+ str(date.today()) +".json", - properties=prop, - contentFile=js, - contentType="application/json" - ) - except Exception as e: - raise UserError(json.loads(e.details).get('message')) + if self.type_convention_id: + file_name = "justifs_projets_"+ str(date.today()) + "_" + self.type_convention_id.name + ".json" + else: + file_name = "justifs_projets_"+ str(date.today()) +".json" + self.create_json_file(file_name, virtual_json) @api.multi def build_facture_fournisseur(self): @@ -151,76 +137,39 @@ class AdefpatProjectJustifZip(models.TransientModel): }, ] } - - 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) - try: - file = repo.createDocument( - name="justifs_factures_fournisseurs_"+ str(date.today()) +".json", - properties=prop, - contentFile=js, - contentType="application/json" - ) - except Exception as e: - raise UserError(json.loads(e.details).get('message')) + if self.type_convention_id: + file_name = "justifs_factures_fournisseurs_"+ str(date.today()) + "_" + self.type_convention_id.name + ".json" + else: + file_name = "justifs_factures_fournisseurs_"+ str(date.today()) +".json" + self.create_json_file(file_name, virtual_json) @api.multi def build_facture_client(self): if self.type_convention_id: - virtual_json = { - "name":"Factures clients", - "nodes":[{ - "id":"1", - "name":"Factures clients", - "description":"Factures clients", - "search":{ - "language":"fts-alfresco", - "query":"(PATH:'/app:company_home/st:sites/cm:odootest/cm:documentLibrary/cm:Factures_x0020_clients_x0020_Justifs//*') AND (+adefpat:factureStartDate:['" + str(self.period_start) + "' TO '" + str(self.period_end) +"']) AND =adefpat:factureTypeConvention:'"+ self.type_convention_id.name +"'", - } - }, - ] - } + query = "(PATH:'/app:company_home/st:sites/cm:odootest/cm:documentLibrary/cm:Factures_x0020_clients_x0020_Justifs//*') AND (+adefpat:factureStartDate:['" + str(self.period_start) + "' TO '" + str(self.period_end) +"']) AND =adefpat:factureTypeConvention:'"+ self.type_convention_id.name +"'" else: - virtual_json = { - "name": "Factures clients", - "nodes": [{ + query = "(PATH:'/app:company_home/st:sites/cm:odootest/cm:documentLibrary/cm:Factures_x0020_clients_x0020_Justifs//*') AND (+adefpat:factureStartDate:['" + str( + self.period_start) + "' TO '" + str( + self.period_end) + "'])" + virtual_json = { + "name": "Factures clients", + "nodes": [{ "id": "1", "name": "Factures clients", "description": "Factures clients", "search": { "language": "fts-alfresco", - "query": "(PATH:'/app:company_home/st:sites/cm:odootest/cm:documentLibrary/cm:Factures_x0020_clients_x0020_Justifs//*') AND (+adefpat:factureStartDate:['" + str( - self.period_start) + "' TO '" + str( - self.period_end) + "'])", - } - }, - ] - } - - js = json.dumps(virtual_json, indent=4) - prop = { - 'cmis:secondaryObjectTypeIds': ['P:adefpat:justificatif'], + "query": query, + } + }, + ] } - - 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) - try: - file = repo.createDocument( - name="justifs_factures_clients_"+ str(date.today()) +".json", - properties=prop, - contentFile=js, - contentType="application/json" - ) - except Exception as e: - raise UserError(json.loads(e.details).get('message')) + if self.type_convention_id: + file_name = "justifs_factures_clients_"+ str(date.today()) + "_" + self.type_convention_id.name + ".json" + else: + file_name = "justifs_factures_clients_"+ str(date.today()) +".json" + self.create_json_file(file_name, virtual_json) @api.multi def build_expense_zip(self): @@ -228,8 +177,17 @@ class AdefpatProjectJustifZip(models.TransientModel): compteur = 0 json_file = [] + for user in user_ids: if user.has_group('base.group_user'): + if self.type_convention_id: + query = "PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Justificatifs//*' AND =adefpat:justificatifUtilisateurs:'" + user.login + "' AND (+adefpat:justificatifDate:['" + str( + self.period_start) + "' TO '" + str( + self.period_end) + "']) AND =adefpat: justificatifTypeConvention:'" + self.type_convention_id.name + "'" + else: + query = "PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Justificatifs//*' AND =adefpat:justificatifUtilisateurs:'" + user.login + "' AND (+adefpat:justificatifDate:['" + str( + self.period_start) + "' TO '" + str( + self.period_end) + "'])" compteur += 1 json_file.append({ "id": "1" + str(compteur), @@ -237,9 +195,7 @@ class AdefpatProjectJustifZip(models.TransientModel): "description": user.name, "search": { "language": "fts-alfresco", - "query": "PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Justificatifs//*' AND =adefpat:justificatifUtilisateurs:'"+ user.login +"' AND (+adefpat:justificatifDate:['" + str( - self.period_start) + "' TO '" + str( - self.period_end) + "'])", + "query": query, } }) @@ -252,18 +208,27 @@ class AdefpatProjectJustifZip(models.TransientModel): "nodes": json_file, }] } + if self.type_convention_id: + file_name = "justifs_frais_" + str( + date.today()) + "_" + self.type_convention_id.name + ".json" + else: + file_name = "justifs_frais_" + str( + date.today()) + ".json" + 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'], } - # 'adefpat:financementConvention': str(self.type_convention_id.name), 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) + try: file = repo.createDocument( - name="justifs_frais_" + str(date.today()) + ".json", + name=file_name, properties=prop, contentFile=js, contentType="application/json"