コード例 #1
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)
コード例 #2
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)
コード例 #3
0
	def _run_report_async(self, path, doc, data=None, params=None, pformat="pdf", ncopies=1, for_all_sites=0):

		data = data or {}
		hashmap = jr.HashMap()
		pram, pram_server, copies = self.do_params(data, params, pformat, doc)
		pram_copy_index = copies.get("pram_copy_index", -1)
		pram_copy_page_index = copies.get("pram_copy_page_index", -1)

		path_join = os.path.join
		resp = []
		custom = doc.get("jasper_custom_fields")

		pram.extend(self.get_param_hook(doc, data, pram_server))

		self.populate_hashmap(pram, hashmap, doc.jasper_report_name)

		copies = [_("Original"), _("Duplicate"), _("Triplicate")]
		conn = ""
		if doc.query:
			conn = "jdbc:mysql://" + (frappe.conf.db_host or '127.0.0.1') + ":" + (frappe.conf.db_port or "3306") + "/" + frappe.conf.db_name + "?user="******"&password="******"report_name"))
			batch.outtype = print_format.index(pformat)
			batch.batchReport.setType(batch.outtype)
			batch.batchReport.setFileName(batch.reportName)
			reqId = uuid.uuid4().hex
			batch.outputPath = path_join(batch.compiled_path, reqId)
			frappe.create_folder(batch.outputPath)
			batch.batchReport.setOutputPath(batch.outputPath + os.sep + batch.reportName)
			batch.sessionId = "local_report_" + reqId

			res = self.prepareResponse({"reportURI": os.path.relpath(batch.outputPath, batch.jasper_path) + os.sep + batch.reportName + "." + pformat}, batch.sessionId)
			res["status"] = None
			res["report_name"] = data.get("report_name")
			resp.append(res)

			batch.batchReport.setTaskHandler(self.frappe_task)
			result = {"fileName": batch.reportName + "." + pformat, "uri":batch.outputPath + os.sep + batch.reportName + "." + pformat, "last_updated": res.get("reqtime"), 'session_expiry': utils.get_expiry_period(batch.sessionId)}
			self.insert_jasper_reqid_record(batch.sessionId, {"data":{"result":result, "report_name": data.get("report_name"), "last_updated": frappe.utils.now(),'session_expiry': utils.get_expiry_period()}})

			frappe.local.batch = batch

		lang = data.get("params", {}).get("locale", None) or "EN"
		cur_doctype = data.get("cur_doctype")
		ids = data.get('ids', [])[:]
		virtua = 0
		if doc.jasper_virtualizer:
			virtua = cint(frappe.db.get_value('JasperServerConfig', fieldname="jasper_virtualizer_pages")) or 0

		if custom and not frappe.local.fds:
			default = ['jasper_erpnext_report.jasper_reports.FrappeDataSource.JasperCustomDataSourceDefault']
			jds_method = utils.jasper_run_method_once_with_default("jasper_custom_data_source", data.get("report_name"), default)
			frappe.local.fds = jds_method

		for m in range(ncopies):
			if pram_copy_index != -1:
				values = pram[pram_copy_index].get("value","")
				pram_copy_name = pram[pram_copy_index].get("name","")
				if not values or not values[0]:
					hashmap.put(pram_copy_name, copies[m])
				else:
					hashmap.put(pram_copy_name, frappe.utils.strip(values[m], ' \t\n\r'))
			if pram_copy_page_index != -1:
				pram_copy_page_name = pram[pram_copy_page_index].get("name","")
				hashmap.put(pram_copy_page_name, str(m) + _(" of ") + str(ncopies))

			mparams = jr.HashMap()
			mparams.put("path_jasper_file", frappe.local.batch.compiled_path + os.sep)
			mparams.put("reportName", frappe.local.batch.reportName)
			mparams.put("outputPath", frappe.local.batch.outputPath + os.sep)
			mparams.put("params", hashmap)
			mparams.put("conn", conn)
			mparams.put("type", jr.Integer(frappe.local.batch.outtype))
			mparams.put("lang", lang)
			mparams.put("virtua", jr.Integer(virtua))
			#used for xml datasource
			mparams.put("numberPattern", frappe.db.get_default("number_format"))
			mparams.put("datePattern", frappe.db.get_default("date_format") + " HH:mm:ss")

			self._export_report(mparams, data.get("report_name"), data.get("grid_data"), frappe.local.batch.sessionId, cur_doctype, custom, ids, frappe.local.fds)
			if pram_copy_index != -1 and ncopies > 1:
				hashmap = jr.HashMap()
				self.populate_hashmap(pram, hashmap, doc.jasper_report_name)

		return resp
コード例 #4
0
    def _run_report_async(self,
                          path,
                          doc,
                          data=None,
                          params=None,
                          pformat="pdf",
                          ncopies=1,
                          for_all_sites=0):
        data = data or {}
        hashmap = jr.HashMap()
        pram, pram_server, copies = self.do_params(data, params, pformat)
        pram_copy_index = copies.get("pram_copy_index", -1)
        pram_copy_page_index = copies.get("pram_copy_page_index", -1)

        path_join = os.path.join
        resp = []
        custom = doc.get("jasper_custom_fields")

        pram.extend(self.get_param_hook(doc, data, pram_server))

        self.populate_hashmap(pram, hashmap, doc.jasper_report_name)

        copies = [_("Original"), _("Duplicate"), _("Triplicate")]
        conn = ""
        if doc.query:
            conn = "jdbc:mariadb://" + (frappe.conf.db_host or 'localhost') + ":" + (frappe.conf.db_port or "3306") + "/" + frappe.conf.db_name + "?user="******"&password="******"report_name"))
            batch.outtype = print_format.index(pformat)
            batch.batchReport.setType(batch.outtype)
            batch.batchReport.setFileName(batch.reportName)
            reqId = uuid.uuid4().hex
            batch.outputPath = path_join(batch.compiled_path, reqId)
            frappe.create_folder(batch.outputPath)
            batch.batchReport.setOutputPath(batch.outputPath + os.sep +
                                            batch.reportName)
            batch.sessionId = "local_report_" + reqId

            res = self.prepareResponse(
                {
                    "reportURI":
                    os.path.relpath(batch.outputPath, batch.jasper_path) +
                    os.sep + batch.reportName + "." + pformat
                }, batch.sessionId)
            res["status"] = None
            res["report_name"] = data.get("report_name")
            resp.append(res)
            result = {
                "fileName": batch.reportName + "." + pformat,
                "uri":
                batch.outputPath + os.sep + batch.reportName + "." + pformat,
                "last_updated": res.get("reqtime"),
                'session_expiry': utils.get_expiry_period(batch.sessionId)
            }
            self.insert_jasper_reqid_record(
                batch.sessionId, {
                    "data": {
                        "result": result,
                        "report_name": data.get("report_name"),
                        "last_updated": frappe.utils.now(),
                        'session_expiry': utils.get_expiry_period()
                    }
                })

            frappe.local.batch = batch

        lang = data.get("params", {}).get("locale", None) or "EN"
        cur_doctype = data.get("cur_doctype")
        ids = data.get('ids', [])[:]
        virtua = 0
        if doc.jasper_virtualizer:
            virtua = cint(
                frappe.db.get_value('JasperServerConfig',
                                    fieldname="jasper_virtualizer_pages")) or 0

        if custom and not frappe.local.fds:
            default = [
                'jasper_erpnext_report.jasper_reports.FrappeDataSource.JasperCustomDataSourceDefault'
            ]
            jds_method = utils.jasper_run_method_once_with_default(
                "jasper_custom_data_source", data.get("report_name"), default)
            frappe.local.fds = jds_method

        for m in range(ncopies):
            if pram_copy_index != -1:
                values = pram[pram_copy_index].get("value", "")
                pram_copy_name = pram[pram_copy_index].get("name", "")
                if not values or not values[0]:
                    hashmap.put(pram_copy_name, copies[m])
                else:
                    hashmap.put(pram_copy_name,
                                frappe.utils.strip(values[m], ' \t\n\r'))
            if pram_copy_page_index != -1:
                pram_copy_page_name = pram[pram_copy_page_index].get(
                    "name", "")
                hashmap.put(pram_copy_page_name,
                            str(m) + _(" of ") + str(ncopies))

            mparams = jr.HashMap()
            mparams.put("path_jasper_file",
                        frappe.local.batch.compiled_path + os.sep)
            mparams.put("reportName", frappe.local.batch.reportName)
            mparams.put("outputPath", frappe.local.batch.outputPath + os.sep)
            mparams.put("params", hashmap)
            mparams.put("conn", conn)
            mparams.put("type", jr.Integer(frappe.local.batch.outtype))
            mparams.put("lang", lang)
            mparams.put("virtua", jr.Integer(virtua))
            #used for xml datasource
            mparams.put("numberPattern",
                        frappe.db.get_default("number_format"))
            mparams.put("datePattern",
                        frappe.db.get_default("date_format") + " HH:mm:ss")

            self._export_report(mparams, data.get("report_name"),
                                data.get("grid_data",
                                         None), frappe.local.batch.sessionId,
                                cur_doctype, custom, ids, frappe.local.fds)
            if pram_copy_index != -1 and ncopies > 1:
                hashmap = jr.HashMap()
                self.populate_hashmap(pram, hashmap, doc.jasper_report_name)

        return resp