Hi All, just trying to do a simple operand on a calculation I’m doing in a Print Format and I keep getting errors - probably because my Jinja/Jscript skills are poor LOL.
This is where I’m up to and while the calcuation works, trying to add an ABS, ROUND or CEIL keeps creating errors. Could someone help me with the structure I need?
This works but I want to end up with an integer, not a decimal value:
Thanks @makarand_b but I’m trying ABS as per my example above and getting long winded errors ending in:
File “”, line 321, in top-level template code
UndefinedError: ‘abs’ is undefined
Same with ceil and round.
Traceback (innermost last):
File “/home/frappe/v5press/benches/1606241137/apps/frappe/frappe/app.py”, line 57, in application
response = frappe.handler.handle()
File “/home/frappe/v5press/benches/1606241137/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/frappe/v5press/benches/1606241137/apps/frappe/frappe/handler.py”, line 36, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/frappe/v5press/benches/1606241137/apps/frappe/frappe/init.py”, line 806, in call
return fn(*args, **newargs)
File “/home/frappe/v5press/benches/1606241137/apps/frappe/frappe/templates/pages/print.py”, line 142, in get_html_and_style
no_letterhead=no_letterhead, trigger_print=trigger_print),
File “/home/frappe/v5press/benches/1606241137/apps/frappe/frappe/templates/pages/print.py”, line 121, in get_html
html = template.render(args, filters={“len”: len})
File “/home/frappe/v5press/benches/1606241137/env/lib/python2.7/site-packages/jinja2/environment.py”, line 989, in render
return self.environment.handle_exception(exc_info, True)
File “/home/frappe/v5press/benches/1606241137/env/lib/python2.7/site-packages/jinja2/environment.py”, line 754, in handle_exception
reraise(exc_type, exc_value, tb)
File “”, line 321, in top-level template code
UndefinedError: ‘abs’ is undefined
Not all frappe & python methods are available in Jinja templating that’s why it’s not able to find the ceil, round method hence the error. If you wish to use the math.ceil then you will need to configure the jinja environment.
you can find all the allowed / available function in jinja.py in frappe app.
You can add the math.ceil, round, and abs method in jinja.py or you can use the built-in filters provided by jinja itself.
{ 42.55 | round } is not css. It’s jinja (though to be proper jinja you’d need {{ double brackets }} ). Jinja is a templating language used alongside normal HTML to create print formats.