{#- ERPNext's templates/print_formats/includes/taxes.html, printing the amounts that are posted. ERPNext takes an Additional Discount off the items' net amounts (item.distributed_discount_amount; a discount on Grand Total is split between net and taxes) and books each charge at tax_amount_after_discount_amount, while upstream prints the discount as entered and the pre-discount tax_amount. Here: the net share of the discount, Net Total, then the charges as booked. A discount that is not distributed (cash / non-trade) comes off the grand total only, so it stays after the charges, as upstream. -#} {%- macro amount_row(label, value) -%}
{{ value }}
{%- endmacro -%} {%- macro currency(value) -%} {{ frappe.format_value(value, {"fieldtype": "Currency", "options": "currency"}, doc) }} {%- endmacro -%} {%- set net_discount = doc.get("items")|map(attribute="distributed_discount_amount")|select|sum -%}
{%- if net_discount -%} {{ amount_row(_(doc.meta.get_label("discount_amount")), "- " ~ currency(net_discount)) }} {{ amount_row(_(doc.meta.get_label("net_total")), doc.get_formatted("net_total", doc)) }} {%- endif -%} {%- for charge in data -%} {%- if (charge.tax_amount or print_settings.print_taxes_with_zero_amount) and (not charge.included_in_print_rate or doc.flags.show_inclusive_tax_in_print) -%} {{ amount_row(charge.get_formatted("description"), charge.get_formatted("tax_amount_after_discount_amount", doc)) }} {%- endif -%} {%- endfor -%} {%- if doc.discount_amount and not net_discount -%} {{ amount_row(_(doc.meta.get_label("discount_amount")), "- " ~ doc.get_formatted("discount_amount", doc)) }} {%- endif -%}