Custom Deliver Notes template

I found the DN template have the total order amount. but how can I add the total qty?

Does your DN have an existing field for the Total Qty? If yes, you can use the print format builder, and drag-drop the field to the DN Print Format template.

If you do not have a field and you are not planning to add it to the Delivery Note, then you can use Jinja to get the item quantities, compute the sum, and then display it to the print format.

For more info, you can check these out: Jinja templating Variables and Codes
ERPNExt Print Format Read Me by sbkolate: erpnext_print_format/ at master Β· sbkolate/erpnext_print_format Β· GitHub
Jinja Docs: Template Designer Documentation β€” Jinja Documentation (2.9.x)

Hope this helps

1 Like


You can add by Custom HTML

Total of Qty: {{ doc.items|sum(attribute='qty') }}

1 Like

I want to add the Total Qty on this field, but how to add?

Tried to add on the custom field but it does not work.

@alfredhy, Select the β€œCustom HTML” above the β€œTitle” field in your arrow and add @vinhnguyent090 HTML script. If you wanted to have it is a real field that you can select, you have to create a Custom Field in your DN and add a script for the calculation.


If you want to add new field total_qty. This way only show qty with new docs need to update total_qty field

The way show total_qty by Custom HTML apply new docs and old docs

#1 add new float filed total _qty

#2 write custom script count total_qty

frappe.ui.form.on("Delivery Note", "validate", function(frm) {
	total_qty = 0;
	$.each(frm.doc.items || [], function(i, d) {
		total_qty += flt(d.qty);
	frm.set_value("total_qty", total_qty);

#3 Add total_qty to print



The way show Total Qty by Custom HTML

I follow the steps but the qty is zero

Custom Field

Custom Script

Print Report format

The way add new total_qty not apply old docs,
if old doc you need save again to update total_qty field.
Or you can test with new doc,

If you want to show the total qty for old docs that were created BEFORE the total_qty field was created, then you’ll need to create a jinja script for this one.

You can try @vinhnguyent090’s suggestion on using Total of Qty: {{ doc.items|sum(attribute='qty') }} or you can do it the long way using a for loop.

{% set total_qty = 0 %}
{% for item in doc.items %}
     {% set total_qty = total_qty + item.qty %}
{% endfor %}

1.) Create a Custom HTML field in the print format.
2.) Edit the Custom HTML field and add the code to the field
3.) Test if it works by going to an Existing Delivery Note (refresh/reload the page if it’s already open)

1 Like

Thanks for the information.