feat: hook for print format template loader (#25037)

* feat: hook for print format template loader

currently logic for how print format template should be loaded is hardcoded
added hook to allow for custom logic to be implemented by other apps.

if hook returns falsy value, then default logic will be used.

* chore: use Walrus Operator and handle Empty Hooks
This commit is contained in:
Maharshi Patel 2024-02-26 20:20:25 +05:30 committed by GitHub
parent 501297b71c
commit ce2d91c751
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -162,7 +162,13 @@ def get_rendered_template(
def get_template_from_string():
return jenv.from_string(get_print_format(doc.doctype, print_format))
if print_format.custom_format:
template = None
if hook_func := frappe.get_hooks("get_print_format_template"):
template = frappe.get_attr(hook_func[-1])(jenv=jenv, print_format=print_format)
if template:
pass
elif print_format.custom_format:
template = get_template_from_string()
elif print_format.format_data: