コード例 #1
0
def get_server_obj(doc, doclist = [], basedoctype = ''):
	# for test
	import webnotes
	from webnotes.modules import scrub, get_doctype_module
	from webnotes.plugins import get_code_and_execute

	# get doctype details
	module = get_doctype_module(doc.doctype) or "core"
		
	if not module:
		return
		
	DocType = get_doctype_class(doc.doctype, module)
	
	if webnotes.flags.in_import:
		return DocType(doc, doclist)

	# custom?
	namespace = {"DocType": DocType}
	get_code_and_execute(module, "DocType", doc.doctype, namespace=namespace)
	if namespace.get("CustomDocType"):
		return namespace["CustomDocType"](doc, doclist)
	else:
		return DocType(doc, doclist)
コード例 #2
0
def run(report_name, filters=None):
    from webnotes.plugins import get_code_and_execute

    report = webnotes.doc("Report", report_name)

    if filters and isinstance(filters, basestring):
        filters = json.loads(filters)

    if not webnotes.has_permission(report.ref_doctype, "report"):
        webnotes.msgprint(
            _("Must have report permission to access this report."),
            raise_exception=True)

    if report.report_type == "Query Report":
        if not report.query:
            webnotes.msgprint(_("Must specify a Query to run"),
                              raise_exception=True)

        if not report.query.lower().startswith("select"):
            webnotes.msgprint(_("Query must be a SELECT"),
                              raise_exception=True)

        result = [list(t) for t in webnotes.conn.sql(report.query, filters)]
        columns = [c[0] for c in webnotes.conn.get_description()]
    else:
        module = webnotes.conn.get_value("DocType", report.ref_doctype,
                                         "module")
        if report.is_standard == "Yes":
            method_name = scrub(module) + ".report." + scrub(
                report.name) + "." + scrub(report.name) + ".execute"
            columns, result = webnotes.get_method(method_name)(
                webnotes._dict(filters))
        else:
            namespace = get_code_and_execute(module, "Report", report.name)
            columns, result = namespace["execute"](filters or {})

    result = get_filtered_data(report.ref_doctype, columns, result)

    if cint(report.add_total_row) and result:
        result = add_total_row(result, columns)

    return {"result": result, "columns": columns}
コード例 #3
0
ファイル: query_report.py プロジェクト: Kazrak/wnframework
def run(report_name, filters=None):
	from webnotes.plugins import get_code_and_execute
	
	report = webnotes.doc("Report", report_name)
	
	if filters and isinstance(filters, basestring):
		filters = json.loads(filters)

	if not webnotes.has_permission(report.ref_doctype, "report"):
		webnotes.msgprint(_("Must have report permission to access this report."), 
			raise_exception=True)
	
	if report.report_type=="Query Report":
		if not report.query:
			webnotes.msgprint(_("Must specify a Query to run"), raise_exception=True)
	
	
		if not report.query.lower().startswith("select"):
			webnotes.msgprint(_("Query must be a SELECT"), raise_exception=True)
		
		result = [list(t) for t in webnotes.conn.sql(report.query, filters)]
		columns = [c[0] for c in webnotes.conn.get_description()]
	else:
		module = webnotes.conn.get_value("DocType", report.ref_doctype, "module")
		if report.is_standard=="Yes":
			method_name = scrub(module) + ".report." + scrub(report.name) + "." + scrub(report.name) + ".execute"
			columns, result = webnotes.get_method(method_name)(webnotes._dict(filters))
		else:
			namespace = get_code_and_execute(module, "Report", report.name)
			columns, result = namespace["execute"](filters or {})
	
	result = get_filtered_data(report.ref_doctype, columns, result)
	
	if cint(report.add_total_row) and result:
		result = add_total_row(result, columns)
	
	return {
		"result": result,
		"columns": columns
	}