Detail custom print format using frappe.db_get_value

Hi,

I’m trying to use frappe.db.get_value to get some extra info during print, but I cannot get it to work.

Just a simple test:

  {{ frappe.db.get_value("Delivery Note", "DN00001", "customer") }}

will render a long traceback

> File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 89, in execute_cmd
> ret = frappe.call(method, **frappe.form_dict)
> File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 531, in call
> return fn(*args, **newargs)
> File "/home/erpnext/frappe-bench/apps/frappe/frappe/templates/pages/print.py", line 86, in get_html
> html = template.render(args, filters={"len": len})
> File "/home/erpnext/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
> return self.environment.handle_exception(exc_info, True)
> File "/home/erpnext/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
> reraise(exc_type, exc_value, tb)
> File "

Any ideas what I’m doing wrong?

Use frappe.get_value for this. Sorry its not documented… (like frappe.db.get_value)

Thanks for a quick reply, however frappe.get_value wouldn’t not work either.

Tracelog:

Traceback (innermost last):
  File "/home/frappe/press/benches/1409261320/apps/frappe/frappe/app.py", line 49, in application
    response = frappe.handler.handle()
  File "/home/frappe/press/benches/1409261320/apps/frappe/frappe/handler.py", line 66, in handle
    execute_cmd(cmd)
  File "/home/frappe/press/benches/1409261320/apps/frappe/frappe/handler.py", line 89, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/frappe/press/benches/1409261320/apps/frappe/frappe/__init__.py", line 531, in call
    return fn(*args, **newargs)
  File "/home/frappe/press/benches/1409261320/apps/frappe/frappe/templates/pages/print.py", line 86, in get_html
    html = template.render(args, filters={"len": len})
  File "/home/frappe/press/benches/1409261320/env/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/frappe/press/benches/1409261320/env/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "

Sorry there is not get_value either, you can use get_doc

Here are the available methods.

1 Like

Great!! This worked!

Dears,
I want to get item price inside item report, I wrote frappe.db.get_value(“Item Price”, {‘item_code’: doc.item_code, ‘price_list’: ‘Standard Buying’}, “rate”)
I tried frappe.get_doc(“Item Price”, {‘item_code’: doc.item_code, ‘price_list’: ‘Standard Buying’}, “rate”) but it’s not working either

Please help me with that

Use fieldname price_list_rate and check it again

It works, thank you so much :slight_smile:

try this

in hooks.py

jenv = {
	"methods": [
		"get_jinja_data:property_sales.property_sales.doctype.property_sales.property_sales.get_jinja_data"
	]
}

in py file

@frappe.whitelist()
def get_jinja_data(doc):
	return frappe.db.sql("""select outstanding_amount, datediff(CURDATE(), posting_date) as "outstanding_days" from `tabSales Invoice` a where associated_property_sales = %s and docstatus = 1 and outstanding_amount > 0""",doc.name, as_dict=True)

in jinja print format

get_jinja_data(doc)

1 Like