from frappe.core.doctype.report.report import Report
import datetime
import frappe

class CustomReport(Report):
    def execute_script_report(self, filters):
        # save the timestamp to automatically set to prepared
        threshold = 99999999

        start_time = datetime.datetime.now()

        # The JOB
        if self.is_standard == "Yes":
            res = self.execute_module(filters)
        else:
            res = self.execute_script(filters)

        # automatically set as prepared
        execution_time = (datetime.datetime.now() - start_time).total_seconds()
        if execution_time > threshold and not self.prepared_report and not frappe.conf.developer_mode:
            frappe.enqueue(enable_prepared_report, report=self.name)

        frappe.cache.hset("report_execution_time", self.name, execution_time)

        return res