{#- 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, so the lines do not add up to Grand Total. Inclusive tax with a discount on Grand Total: the Total line is the tax-inclusive item total and the discount is printed as entered; Total After Discount is then broken down into Net Total and the charges. Otherwise the Total line is the net before the discount, so the discount is its net share, followed by Net Total and the charges. A discount that is not distributed (cash / non-trade) comes off the grand total only and 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 -%} {%- set gross_discount = net_discount and doc.apply_discount_on == "Grand Total" and doc.flags.show_inclusive_tax_in_print -%}
{%- if gross_discount -%} {{ amount_row(_(doc.meta.get_label("discount_amount")), "- " ~ doc.get_formatted("discount_amount", doc)) }} {{ amount_row(_("Total After Discount"), currency(doc.total - doc.discount_amount)) }} {{ amount_row(_(doc.meta.get_label("net_total")), doc.get_formatted("net_total", doc)) }} {%- elif 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 -%}