Custom print format for core DocTypes via custom app

How can I create a custom “Print Format” from custom app for core DocTypes (for instance Sales Invoice)?

I’ve created a new “Print Format” as follows and added a .html file also in the same directory where it auto generated a .json file. I’ve also specified my custom app name in the module field while saving the print format.

But whenever I try to print from new print format I got an error message that says TemplateNotFound error.

It looks the template at wrong directory inside apps/erpnext/accounts/.... Why ? It is supposed to look for the template in my custom app my_app/print_format/format_name/format_name.html rather than apps/erpnext/erpnext/accounts/print_format/format_name/format_name.html, isn’t it ?

** The error **

  if self.get_redis_server_version() >= StrictVersion("4.0.0"):
05:33:36 web.1            | Traceback (most recent call last):
05:33:36 web.1            |   File "apps/frappe/frappe/website/context.py", line 61, in update_controller_context
05:33:36 web.1            |     ret = module.get_context(context)
05:33:36 web.1            |   File "apps/frappe/frappe/www/printview.py", line 56, in get_context
05:33:36 web.1            |     "body": get_rendered_template(
05:33:36 web.1            |   File "apps/frappe/frappe/www/printview.py", line 161, in get_rendered_template
05:33:36 web.1            |     template = get_template_from_string()
05:33:36 web.1            |   File "apps/frappe/frappe/www/printview.py", line 142, in get_template_from_string
05:33:36 web.1            |     return jenv.from_string(get_print_format(doc.doctype, print_format))
05:33:36 web.1            |   File "apps/frappe/frappe/www/printview.py", line 331, in get_print_format
05:33:36 web.1            |     frappe.throw(_("No template found at path: {0}").format(path), frappe.TemplateNotFoundError)
05:33:36 web.1            |   File "apps/frappe/frappe/__init__.py", line 503, in throw
05:33:36 web.1            |     msgprint(
05:33:36 web.1            |   File "apps/frappe/frappe/__init__.py", line 478, in msgprint
05:33:36 web.1            |     _raise_exception()
05:33:36 web.1            |   File "apps/frappe/frappe/__init__.py", line 433, in _raise_exception
05:33:36 web.1            |     raise raise_exception(msg)
05:33:36 web.1            | frappe.exceptions.TemplateNotFoundError: No template found at path: apps/erpnext/erpnext/accounts/print_format/ird_invoice/ird_invoice.html

Custom app print format

image

Print not working - No Preview

1 Like

Hi @lekhnath,

Check it, please.

Maybe, it helps.
Thanks.

1 Like

Thanks @NCP . Appreciated.

It seems I am not the only person who is facing this problem. I gave up and stick with boring and buggy web editor for now. I will use the built-in editor with a caution .

How about using {% include %} syntax? :grinning:

2 Likes

@pipech haha, that was pretty clever.

It worked. Thanks.

1 Like