feat: add abilty to export report-center records

This commit is contained in:
sokumon 2025-11-11 22:02:19 +05:30
parent 673959565c
commit 0cdbe2f0bf
2 changed files with 36 additions and 4 deletions

View file

@ -7,7 +7,8 @@
"engine": "InnoDB",
"field_order": [
"sidebar",
"links"
"links",
"app"
],
"fields": [
{
@ -22,12 +23,18 @@
"fieldtype": "Table",
"label": "Links",
"options": "Report Center Link"
},
{
"fieldname": "app",
"fieldtype": "Autocomplete",
"label": "App",
"options": "Installed Applications"
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2025-11-10 12:51:46.093654",
"modified": "2025-11-11 20:47:20.792274",
"modified_by": "Administrator",
"module": "Desk",
"name": "Report Center",

View file

@ -1,8 +1,11 @@
# Copyright (c) 2025, Frappe Technologies and contributors
# For license information, please see license.txt
# import frappe
import os
import frappe
from frappe.model.document import Document
from frappe.modules.utils import create_directory_on_app_path, get_app_level_directory_path
class ReportCenter(Document):
@ -15,7 +18,29 @@ class ReportCenter(Document):
from frappe.desk.doctype.report_center_link.report_center_link import ReportCenterLink
from frappe.types import DF
app: DF.Autocomplete | None
links: DF.Table[ReportCenterLink]
sidebar: DF.Link | None
# end: auto-generated types
pass
def on_update(self):
if frappe.conf.developer_mode:
if self.app:
self.export_report_center()
def export_report_center(self):
folder_path = create_directory_on_app_path("report_center", self.app)
file_path = os.path.join(folder_path, f"{frappe.scrub(self.name)}.json")
doc_export = self.as_dict(no_nulls=True, no_private_properties=True)
with open(file_path, "w+") as doc_file:
doc_file.write(frappe.as_json(doc_export) + "\n")
def on_trash(self):
if frappe.conf.developer_mode and self.app:
self.delete_file()
def delete_file(self):
folder_path = create_directory_on_app_path("report_center", self.app)
file_path = os.path.join(folder_path, f"{frappe.scrub(self.name)}.json")
if os.path.exists(file_path):
os.remove(file_path)