shahid
March 30, 2021, 11:24am
1
Hi everyone,
i am trying to customize print format for offline pos,
i am trying to implement if statement condition but i think if statement is not working, however i tried with 2,3 syntax, can anybody guide for the right syntax for JS print format?
{% for d in taxes %}
{% if(d.account_head == "CGST 6% - E"){ %}
{% cgst += d.tax_amount %}
{% } %}
{% if d.account_head == "CGST 6% - E" %}
{% cgst += d.tax_amount %}
{% endif %}
{% endfor %}
the aim is to use In/includes instead of == but its also not working.
Try
{% for d in taxes %}
{% if "CGST 6% - E" in d.account_head %}
{% cgst += d.tax_amount %}
{% endif %}
{% endfor %}
shahid
March 30, 2021, 11:50am
3
dj12djdjs:
hi @dj12djdjs ,
now its not even opening the print.
{% var cgst = 0 %}
{% var sgst = 0 %}
{% for d in taxes %}
{% if "CGST 6% - E" in d.account_head %}
{% cgst += d.tax_amount %}
{% endif %}
{% endfor %}
Use set not var
{% set cgst = 0 %}
{% set sgst = 0 %}
{% for d in taxes %}
{% if "CGST 6% - E" in d.account_head %}
{% cgst += d.tax_amount %}
{% endif %}
{% endfor %}
This isn’t formatted with Java Script. It is compiled with Python+Jinja
shahid
March 30, 2021, 11:59am
5
i tried it already, now again i tried but same error.
{% set cgst = 0 %}
{% set sgst = 0 %}
{% for d in taxes %}
{% if "CGST 6% - E" in d.account_head %}
{% cgst += d.tax_amount %}
{% endif %}
{% endfor %}
It seems += does not work in Jinja ether. Try this.
{% set cgst = 0 %}
{% set sgst = 0 %}
{% for d in taxes %}
{% if "CGST 6% - E" in d.account_head %}
{% set cgst = cgst + d.tax_amount %}
{% endif %}
{% endfor %}
shahid
March 30, 2021, 12:09pm
7
if i am using set, it gives error, when using var it doesn’t give error but if statement not working.
shahid
March 30, 2021, 12:10pm
8
{% var cgst = 0 %}
{% var sgst = 0 %}
{% for d in taxes %}
{% cgst += d.tax_amount %}
{% endfor %}
this code is calculating the result, but i need to filter using if statement.
shahid
March 30, 2021, 12:19pm
9
{% var cgst = 0 %}
{% var sgst = 0 %}
{% var test = 0 %}
{% for d in taxes %}
{% cgst += d.tax_amount %}
{% if "KFC - E" in d.account_head %}
{% test = 1 %}
{% else %}
{% test = 0 %}
{% endif %}
{% endfor %}
{{ test }}
I’ll admit I’m confused now. Are you not using Jinja as a template language?
shahid
March 30, 2021, 2:11pm
11
No its JS. for offline pos print.
This is for loop correct syntax use the following syntax.
{%- for d in taxes -%}
— Conditions
{%- endfor -%}
shahid
March 31, 2021, 11:57am
14
thanks for reply @Vaibhav_Parmar but the question is if statement is not working, loop is working fine.
You need a second loop I think. You can’t use “in” operator for d.account_head variable.