I am calculating “total carton” in my sales invoice print format based on the qty entered in sales invoice and units_in_ctn field fetched from Item master. Grid is showing correct data. However when I use a variable to calculate total then it always show 0.0
{% set total_ctns = 0.0 %}
{% for item in doc.entries %}
{% set item_doc = frappe.get_doc("Item", item.item_code) %}
{% set ctns = (item.qty+item.schm)/item_doc.units_in_ctn %}
{% set total_ctns = total_ctns + ctns %}
---- SHOW DATA IN TABLE HERE
{%- endfor -%}
If I show this varible total_ctns in the for loop then it shows correct value, however after endfor it shows 0.00. Any help???
@rmehta means I have to create a new field in “Sales Invoice” doctype and then set the value of this field in print format? How can I set the value of this field in print format?
@rmehta I tried to create a variable total_ctns and then setting its value. However facing this issue
> self.handle_exception(exc_info, source_hint=source)
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 “”, line 33, in template
TemplateSyntaxError: expected token ‘=’, got ‘.’
mmm… I am not sure. Maybe you should do all calculations server side in custom fields and use the data in Jinja. Jinja is not optimized for processing.
@rmehta this are very small calculations and I think jinja is doing the job but not handling the scope of the variables correctly. Jinja is calculating the total_ctns but not able to retain the value of this varibale beyond the scope of for loop
The path “flows.jinja_filters.indent_refill_qty”: can you describe what “flows”, “jinja_filters” and “indent_refill_qty” are? Is this a dotted.path.to_function syntax? I’m trying to repeat your steps in my own custom app without success.
So an update on this: I got it working with @BhupeshGupta’s instructions and example, but it required a bench migrate for the changes in hooks.py to get picked up in the Jinja environment. I doesn’t really make sense to me what that would need to be done since other changes to hooks.py are dynamic. I hope I save somebody some future frustration with that.