From 68f08171252099920d52f5c47800d65ddf4689b3 Mon Sep 17 00:00:00 2001 From: kurogeek Date: Thu, 17 Sep 2026 10:30:43 +0000 Subject: [PATCH] fix: gross discount layout for VAT-inclusive invoices With inclusive pricing and a discount on Grand Total the Total line is the tax-inclusive item total and the discount is printed as entered, followed by Total After Discount, which the Net Total and charge lines then break down. Other cases keep the net layout: Total (net before discount), the discount's net share, Net Total, charges. Thai label for Total After Discount. --- .../print_formats/includes/taxes.html | 18 ++++++++++++++---- .../print_formats/includes/total.html | 16 +++++++++------- default_thai_company/translations/th.csv | 1 + 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/default_thai_company/templates/print_formats/includes/taxes.html b/default_thai_company/templates/print_formats/includes/taxes.html index e8b75fb..105b191 100644 --- a/default_thai_company/templates/print_formats/includes/taxes.html +++ b/default_thai_company/templates/print_formats/includes/taxes.html @@ -3,9 +3,14 @@ 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. -#} + 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) -%}
@@ -20,11 +25,16 @@ {{ 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 net_discount -%} + {%- 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 -%} diff --git a/default_thai_company/templates/print_formats/includes/total.html b/default_thai_company/templates/print_formats/includes/total.html index ecd8bcc..1facbd6 100644 --- a/default_thai_company/templates/print_formats/includes/total.html +++ b/default_thai_company/templates/print_formats/includes/total.html @@ -1,14 +1,16 @@ -{#- ERPNext's templates/print_formats/includes/total.html, except that with inclusive tax the - "Total (Without Tax)" line is the net total before the Additional Discount: net_total already - has the discount's net share (item.distributed_discount_amount) taken off, and the taxes - include prints that share and Net Total right below this line. -#} +{#- ERPNext's templates/print_formats/includes/total.html, paired with the taxes include: + with inclusive tax and a discount on Grand Total the Total line is the tax-inclusive item + total (the discount is printed as entered below it); with inclusive tax otherwise it is + the net before the Additional Discount, since net_total already has the discount's net + share (item.distributed_discount_amount) taken off. -#} +{%- 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 doc.flags.show_inclusive_tax_in_print %} - {%- set before_discount = doc.net_total + (doc.get("items")|map(attribute="distributed_discount_amount")|select|sum) -%} + {% if doc.flags.show_inclusive_tax_in_print and not gross_discount %}
- {{ frappe.format_value(before_discount, {"fieldtype": "Currency", "options": "currency"}, doc) }} + {{ frappe.format_value(doc.net_total + net_discount, {"fieldtype": "Currency", "options": "currency"}, doc) }}
{% else %}
diff --git a/default_thai_company/translations/th.csv b/default_thai_company/translations/th.csv index fd179e4..dda2a59 100644 --- a/default_thai_company/translations/th.csv +++ b/default_thai_company/translations/th.csv @@ -50,6 +50,7 @@ Amount,จำนวนเงิน Total,รวม Total (Without Tax),รวมก่อนภาษี Net Total,ยอดรวมสุทธิ +Total After Discount,ยอดรวมหลังหักส่วนลด Total Taxes and Charges,รวมภาษีและค่าธรรมเนียม Grand Total,ยอดรวมทั้งสิ้น Rounded Total,ยอดรวมปัดเศษ