default report for prepared

This commit is contained in:
shriharishastry 2018-06-28 19:27:35 +05:30
parent 191942c6d2
commit 73c38eabb2
5 changed files with 29 additions and 35 deletions

View file

@ -182,7 +182,7 @@
"collapsible": 0,
"columns": 0,
"fieldname": "status",
"fieldtype": "Data",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
@ -193,6 +193,7 @@
"label": "Status",
"length": 0,
"no_copy": 0,
"options": "Queued\nCompleted",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@ -217,7 +218,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-06-25 20:39:52.013412",
"modified": "2018-06-28 18:36:17.700311",
"modified_by": "Administrator",
"module": "Core",
"name": "Prepared Report",

View file

@ -16,6 +16,7 @@ from frappe.utils.csvutils import to_csv, read_csv_content_from_attached_file
from frappe.desk.form.load import get_attachments
from frappe.utils.file_manager import download_file
class PreparedReport(Document):
def before_insert(self):
self.status = "Queued"

View file

@ -6,7 +6,7 @@
"doctype": "Report",
"idx": 3,
"is_standard": "Yes",
"modified": "2018-06-28 17:01:25.658374",
"modified": "2018-06-28 18:54:09.529507",
"modified_by": "Administrator",
"module": "Core",
"name": "Permitted Documents For User",

View file

@ -13,6 +13,7 @@ from frappe.model.utils import render_include
from frappe.translate import send_translations
from frappe.utils.csvutils import read_csv_content_from_attached_file
import frappe.desk.reportview
from frappe.utils.csvutils import read_csv_content_from_attached_file
from frappe.permissions import get_role_permissions
from six import string_types, iteritems
@ -149,19 +150,20 @@ def run(report_name, filters=None, user=None):
raise_exception=True)
if report.prepared_report:
doc_list = frappe.get_list("Prepared List", filters={"status": "Completed", "report_name":report_name })
doc_list = frappe.get_list("Prepared Report", filters={"status": "Completed", "ref_report_doctype": report})
columns = []
result = []
if len(doc_list):
doc = frappe.get_doc("Prepared Report", doc_list[0])
data = read_csv_content_from_attached_file(doc)
columns
columns = data[0]
result = data[1:]
return {
"message": "Prepared Report",
"prepared_report": True,
"data": {
"columns": [],
"result": []
"columns": columns,
"result": result
}
}
else:

View file

@ -207,12 +207,7 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
if(flags) {
const prepared_data = flags.data
this.init_report_with_data(prepared_data);
this.page.add_inner_button(__("Download Report"), function () {
frappe.call({
method:"frappe.core.doctype.prepared_report.prepared_report.download_attachment",
args: {"dn": flags.name}
});
});
this.toggle_to_button();
return;
}
if(!this.prepared_report){
@ -235,16 +230,17 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
init_report_with_data(data) {
if (data.prepared_report){
this.prepared_report = true;
this.toggle_to_button(true, data.file_attachment);
}else{
this.toggle_message(false);
if (data.result && data.result.length) {
this.render_chart(data);
this.render_report(data);
} else {
this.toggle_nothing_to_show(true);
}
this.toggle_to_button();
data = data.data;
}
this.toggle_message(false);
if (data.result && data.result.length) {
this.render_chart(data);
this.render_report(data);
} else {
this.toggle_nothing_to_show(true);
}
}
render_background_report() {
@ -632,19 +628,13 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
toggle_nothing_to_show(flag) {
this.toggle_message(flag, __('Nothing to show'));
}
toggle_to_button(flag, attachment){
if (flag) {
if(attachment){
this.$message.find('div').html("<p>Download recent generated Prepared Report <a target='_blank' href="+attachment+">here</a>.");
}
this.$message.find('div').append("<button class='btn btn-primary prepared-report'>Generate Prepared Report</button>");
this.$message.find('.prepared-report').click(() => this.render_background_report());
this.$message.show();
} else {
this.$message.hide();
}
this.$report.toggle(!flag);
this.$chart.toggle(!flag);
toggle_to_button(){
this.page.add_inner_button(__("Download Report"), function () {
frappe.call({
method:"frappe.core.doctype.prepared_report.prepared_report.download_attachment",
args: {"dn": flags.name}
});
});
}
toggle_message(flag, message) {
if (flag) {