Samsul
July 19, 2023, 10:25am
1
How to update total_price which set in custom print format. I can’t update the variable value. How to update this variable value?
{% set total_price = 0 %}
{% for item in doc.items %}
{% set total_price = total_price + (item.price_list_rate * item.qty) %}
{% endfor %}
Hi,
Please try to change the code as follows:
{% for item in doc.items %}
{% set total_price += item.price_list_rate %}
{% endfor %}
Thanks,
Divyesh Mangroliya
Samsul
July 19, 2023, 10:32am
3
Thanks for your response. I try it. But doesn’t work again…
NCP
July 19, 2023, 10:34am
4
Hi @Samsul ,
Please try it.
{{ doc.items | sum(attribute='price_list_rate') }}
Then reload and check it.
Reference:
Hi @Ulter52 ,
Please apply it.
{{ doc.items | sum(attribute='discount_amount') }}
Then reload and check it.
Thank You!
Thank You!
Samsul
July 19, 2023, 10:44am
5
Thank you brother for your reply.
Actually, I need two fields value calculation. And also need update the set variable every loop.
Note: I already update my question code.
Thanks
NCP
July 19, 2023, 10:48am
6
Please try it.
{% set total = 0 %}
{% for item in doc.items %}
{% set line_total = item.price_list_rate * item.qty %}
{% set total = total + line_total %}
{% endfor %}
{{ total }}
Samsul
July 19, 2023, 11:09am
7
I already try your code like this:
{% set total_price = 0 %}
{% for item in doc.items %}
{% set line_total = item.price_list_rate * item.qty %}
{% set total_price = total_price + line_total %}
{% endfor %}
But It doesn’t work again. Show value 0.
NCP
July 19, 2023, 11:19am
8
Hi @Samsul ,
Please apply it.
{% set total = [0] %}
{% for item in doc.items %}
{% set line_total = item.price_list_rate * item.qty %}
{% if total.append(total.pop() + line_total) %}{% endif %}
{% endfor %}
Total: {{ total.pop() }}
Then reload and check it.
Thank You!
2 Likes
Samsul
July 19, 2023, 11:35am
9
It works perfectly.
Thank you so much