def _export_report(self, mparams, report_name, grid_data, sessionId, cur_doctype, custom, ids, jds_method):
		try:

			data = None
			cols = None
			fds = None

			if custom:
				jds = jds_method(ids, cur_doctype)
				fds = jr.FDataSource(_JasperCustomDataSource(jds))

			if grid_data and grid_data.get("data", None):
				data, cols = self._export_query_report(grid_data)
				if not data or not cols:
					print "Error in report {}. There is no data.".format(report_name)
					return

			frappe.local.batch.batchReport.addToBatch(mparams, data, cols, fds)

		except Exception, e:
			import time
			print "Error in report %s, error is: %s" % (report_name, e)
			s = "{0}".format(str(e))
			cache = frappe.cache()
			t = int(time.time())
			cache.set(("site.all:jasper:" + sessionId).encode('utf-8'), json.dumps({"e": s, "t": t}))
			print "str(sessionId) {} s {}".format(str(sessionId), cache.get("site.all:jasper:".encode('utf-8') + sessionId.encode('utf-8')))
    def _export_report(self, mparams, report_name, grid_data, sessionId, cur_doctype, custom, ids, jds_method):
        from jasper_erpnext_report.jasper_reports.FrappeDataSource import _JasperCustomDataSource

        data = None
        cols = None
        fds = None

        if grid_data and grid_data.get("data", None):
            data, cols = self._export_query_report(grid_data)
            if not data or not cols:
                print "Error in report {}. There is no data.".format(report_name)
                frappe.throw(_("Error in report {}. There is no data.".format(report_name)))
                return

        if custom:
            jds = jds_method(ids, data, cols, cur_doctype)
            fds = jr.FDataSource(_JasperCustomDataSource(jds))

            # check if there is a scriptlet hook for this report.
        jscriptlet_method = utils.jasper_run_method_once_with_default("jasper_scriptlet", report_name, None)
        if jscriptlet_method:
            from jasper_erpnext_report.jasper_reports.ScriptletDefault import _JasperCustomScriptlet

            JasperScriptlet = jr.JavaFrappeScriptlet()
            JasperScriptlet.setFrappeScriptlet(
                _JasperCustomScriptlet(
                    JasperScriptlet, jscriptlet_method(JasperScriptlet, ids, data, cols, cur_doctype, report_name)
                )
            )
            mparams.get("params").put("REPORT_SCRIPTLET", JasperScriptlet)
        else:
            """
				check if there is a scriptlet hook for this report in frappe-bench/sites/site_name/jasper_hooks folder.
				The folder have the following structure where jasper_hooks is the root(package):
					jasper_hooks/report name/hook name.py
					Example: jasper_hooks/Table 1 Custom/jasper_scriptlet.py -> where Table 1 Custom is the name of report and jasper_scriptlet.py
					is the name of the hook.
				Note: All the folders must have __init__.py to make it a package
				This strucutre is to help development. There is no need to make a frappe app only to control reports.
			"""
            from jasper_erpnext_report.utils.utils import get_hook_module
            from jasper_erpnext_report.jasper_reports.ScriptletDefault import _JasperCustomScriptlet

            jscriptlet_module = get_hook_module("jasper_scriptlet", report_name)
            if jscriptlet_module:
                JasperScriptlet = jr.JavaFrappeScriptlet()
                JasperScriptlet.setFrappeScriptlet(
                    _JasperCustomScriptlet(
                        JasperScriptlet,
                        jscriptlet_module.get_data(JasperScriptlet, ids, data, cols, cur_doctype, report_name),
                    )
                )
                mparams.get("params").put("REPORT_SCRIPTLET", JasperScriptlet)

        frappe.local.batch.batchReport.addToBatch(mparams, data, cols, fds)
	def _export_report(self, mparams, report_name, grid_data, sessionId, cur_doctype, custom, ids, jds_method):

		data = None
		cols = None
		fds = None

		if custom:
			jds = jds_method(ids, cur_doctype)
			fds = jr.FDataSource(_JasperCustomDataSource(jds))

		if grid_data and grid_data.get("data", None):
			data, cols = self._export_query_report(grid_data)
			if not data or not cols:
				print "Error in report {}. There is no data.".format(report_name)
				return

		frappe.local.batch.batchReport.addToBatch(mparams, data, cols, fds)
示例#4
0
	def _export_report(self, mparams, report_name, grid_data, sessionId, cur_doctype, custom, ids, jds_method):
		from jasper_erpnext_report.jasper_reports.FrappeDataSource import _JasperCustomDataSource

		data = None
		cols = None
		fds = None

		if grid_data and grid_data.get("data", None):
			data, cols = self._export_query_report(grid_data)
			if not data or not cols:
				print "Error in report {}. There is no data.".format(report_name)
				frappe.throw(_("Error in report {}. There is no data.".format(report_name)))
				return

		if custom:
			jds = jds_method(ids, data, cols, cur_doctype)
			fds = jr.FDataSource(_JasperCustomDataSource(jds))

		#check if there is a scriptlet hook for this report.
		jscriptlet_method = utils.jasper_run_method_once_with_default("jasper_scriptlet", report_name, None)
		if jscriptlet_method:
			from jasper_erpnext_report.jasper_reports.ScriptletDefault import _JasperCustomScriptlet

			JasperScriptlet = jr.JavaFrappeScriptlet()
			JasperScriptlet.setFrappeScriptlet(_JasperCustomScriptlet(JasperScriptlet, jscriptlet_method(JasperScriptlet, ids, data, cols, cur_doctype, report_name)))
			mparams.get("params").put("REPORT_SCRIPTLET", JasperScriptlet)
		else:
			"""
				check if there is a scriptlet hook for this report in frappe-bench/sites/site_name/jasper_hooks folder.
				The folder have the following structure where jasper_hooks is the root(package):
					jasper_hooks/report name/hook name.py
					Example: jasper_hooks/Table 1 Custom/jasper_scriptlet.py -> where Table 1 Custom is the name of report and jasper_scriptlet.py
					is the name of the hook.
				Note: All the folders must have __init__.py to make it a package
				This strucutre is to help development. There is no need to make a frappe app only to control reports.
			"""
			from jasper_erpnext_report.utils.utils import get_hook_module
			from jasper_erpnext_report.jasper_reports.ScriptletDefault import _JasperCustomScriptlet

			jscriptlet_module = get_hook_module("jasper_scriptlet", report_name)
			if jscriptlet_module:
				JasperScriptlet = jr.JavaFrappeScriptlet()
				JasperScriptlet.setFrappeScriptlet(_JasperCustomScriptlet(JasperScriptlet, jscriptlet_module.get_data(JasperScriptlet, ids, data, cols, cur_doctype, report_name)))
				mparams.get("params").put("REPORT_SCRIPTLET", JasperScriptlet)

		frappe.local.batch.batchReport.addToBatch(mparams, data, cols, fds)
    def _export_report(self, mparams, report_name, grid_data, sessionId,
                       cur_doctype, custom, ids, jds_method):

        data = None
        cols = None
        fds = None

        if custom:
            jds = jds_method(ids, cur_doctype)
            fds = jr.FDataSource(_JasperCustomDataSource(jds))

        if grid_data and grid_data.get("data", None):
            data, cols = self._export_query_report(grid_data)
            if not data or not cols:
                print "Error in report {}. There is no data.".format(
                    report_name)
                return

        frappe.local.batch.batchReport.addToBatch(mparams, data, cols, fds)