Skip to content
Extraits de code Groupes Projets
Valider 942fb043 rédigé par Juliana's avatar Juliana
Parcourir les fichiers

[ADD]Add function to create json

parent 257f5e6a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
/> />
<button <button
name="delete_file" name="delete_file"
string="Supprimer le fichier" string="Supprimer le justificatif"
type="object" type="object"
attrs="{'invisible': [('proof_file', '=', False)]}" attrs="{'invisible': [('proof_file', '=', False)]}"
/> />
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
/> />
<button <button
name="delete_file" name="delete_file"
string="Supprimer le fichier" string="Supprimer le justificatif"
type="object" type="object"
attrs="{'invisible': [('proof_file', '=', False)]}" attrs="{'invisible': [('proof_file', '=', False)]}"
/> />
......
...@@ -45,7 +45,6 @@ class AdefpatProjectJustifZip(models.TransientModel): ...@@ -45,7 +45,6 @@ class AdefpatProjectJustifZip(models.TransientModel):
for project in project_ids: for project in project_ids:
compteur += 1 compteur += 1
path = "PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Projets/" + project.name path = "PATH:'/app:company_home/st:sites/cm:odoo/cm:documentLibrary/cm:Projets/" + project.name
# virtual_json["nodes"]["nodes"].append({
json_file.append({ json_file.append({
"id": "1" + str(compteur), "id": "1" + str(compteur),
"name": project.name, "name": project.name,
...@@ -116,24 +115,11 @@ class AdefpatProjectJustifZip(models.TransientModel): ...@@ -116,24 +115,11 @@ class AdefpatProjectJustifZip(models.TransientModel):
"nodes": json_file, "nodes": json_file,
}] }]
} }
if self.type_convention_id:
js = json.dumps(virtual_json, indent=4) file_name = "justifs_projets_"+ str(date.today()) + "_" + self.type_convention_id.name + ".json"
prop = { else:
'cmis:secondaryObjectTypeIds': ['P:adefpat:justificatif'], file_name = "justifs_projets_"+ str(date.today()) +".json"
} self.create_json_file(file_name, virtual_json)
# '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'))
@api.multi @api.multi
def build_facture_fournisseur(self): def build_facture_fournisseur(self):
...@@ -151,43 +137,21 @@ class AdefpatProjectJustifZip(models.TransientModel): ...@@ -151,43 +137,21 @@ class AdefpatProjectJustifZip(models.TransientModel):
}, },
] ]
} }
if self.type_convention_id:
js = json.dumps(virtual_json, indent=4) file_name = "justifs_factures_fournisseurs_"+ str(date.today()) + "_" + self.type_convention_id.name + ".json"
prop = { else:
'cmis:secondaryObjectTypeIds': ['P:adefpat:justificatif'], file_name = "justifs_factures_fournisseurs_"+ str(date.today()) +".json"
} self.create_json_file(file_name, virtual_json)
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'))
@api.multi @api.multi
def build_facture_client(self): def build_facture_client(self):
if self.type_convention_id: if self.type_convention_id:
virtual_json = { 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 +"'"
"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 +"'",
}
},
]
}
else: else:
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 = { virtual_json = {
"name": "Factures clients", "name": "Factures clients",
"nodes": [{ "nodes": [{
...@@ -196,31 +160,16 @@ class AdefpatProjectJustifZip(models.TransientModel): ...@@ -196,31 +160,16 @@ class AdefpatProjectJustifZip(models.TransientModel):
"description": "Factures clients", "description": "Factures clients",
"search": { "search": {
"language": "fts-alfresco", "language": "fts-alfresco",
"query": "(PATH:'/app:company_home/st:sites/cm:odootest/cm:documentLibrary/cm:Factures_x0020_clients_x0020_Justifs//*') AND (+adefpat:factureStartDate:['" + str( "query": query,
self.period_start) + "' TO '" + str(
self.period_end) + "'])",
} }
}, },
] ]
} }
if self.type_convention_id:
js = json.dumps(virtual_json, indent=4) file_name = "justifs_factures_clients_"+ str(date.today()) + "_" + self.type_convention_id.name + ".json"
prop = { else:
'cmis:secondaryObjectTypeIds': ['P:adefpat:justificatif'], file_name = "justifs_factures_clients_"+ str(date.today()) +".json"
} self.create_json_file(file_name, virtual_json)
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'))
@api.multi @api.multi
def build_expense_zip(self): def build_expense_zip(self):
...@@ -228,8 +177,17 @@ class AdefpatProjectJustifZip(models.TransientModel): ...@@ -228,8 +177,17 @@ class AdefpatProjectJustifZip(models.TransientModel):
compteur = 0 compteur = 0
json_file = [] json_file = []
for user in user_ids: for user in user_ids:
if user.has_group('base.group_user'): 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 compteur += 1
json_file.append({ json_file.append({
"id": "1" + str(compteur), "id": "1" + str(compteur),
...@@ -237,9 +195,7 @@ class AdefpatProjectJustifZip(models.TransientModel): ...@@ -237,9 +195,7 @@ class AdefpatProjectJustifZip(models.TransientModel):
"description": user.name, "description": user.name,
"search": { "search": {
"language": "fts-alfresco", "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( "query": query,
self.period_start) + "' TO '" + str(
self.period_end) + "'])",
} }
}) })
...@@ -252,18 +208,27 @@ class AdefpatProjectJustifZip(models.TransientModel): ...@@ -252,18 +208,27 @@ class AdefpatProjectJustifZip(models.TransientModel):
"nodes": json_file, "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) js = json.dumps(virtual_json, indent=4)
prop = { prop = {
'cmis:secondaryObjectTypeIds': ['P:adefpat:justificatif'], 'cmis:secondaryObjectTypeIds': ['P:adefpat:justificatif'],
} }
# 'adefpat:financementConvention': str(self.type_convention_id.name),
backend = self.env['cmis.backend'].search([], limit=1) backend = self.env['cmis.backend'].search([], limit=1)
json_file_cmis = self.env.user.company_id.proof_justif_cmis json_file_cmis = self.env.user.company_id.proof_justif_cmis
repo = backend.get_cmis_repository().getObject(json_file_cmis) repo = backend.get_cmis_repository().getObject(json_file_cmis)
try: try:
file = repo.createDocument( file = repo.createDocument(
name="justifs_frais_" + str(date.today()) + ".json", name=file_name,
properties=prop, properties=prop,
contentFile=js, contentFile=js,
contentType="application/json" contentType="application/json"
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter