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.
This commit is contained in:
2026-09-17 10:30:43 +00:00
parent 4a19c60ba2
commit 68f0817125
3 changed files with 24 additions and 11 deletions
@@ -3,9 +3,14 @@
ERPNext takes an Additional Discount off the items' net amounts (item.distributed_discount_amount; 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 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 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 pre-discount tax_amount, so the lines do not add up to Grand Total.
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. -#} 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) -%} {%- macro amount_row(label, value) -%}
<div class="row"> <div class="row">
<div class="col-xs-5 {%- if doc.align_labels_right %} text-right{%- endif -%}"> <div class="col-xs-5 {%- if doc.align_labels_right %} text-right{%- endif -%}">
@@ -20,11 +25,16 @@
{{ frappe.format_value(value, {"fieldtype": "Currency", "options": "currency"}, doc) }} {{ frappe.format_value(value, {"fieldtype": "Currency", "options": "currency"}, doc) }}
{%- endmacro -%} {%- endmacro -%}
{%- set net_discount = doc.get("items")|map(attribute="distributed_discount_amount")|select|sum -%} {%- 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 -%}
<div class="row"> <div class="row">
<div class="col-xs-6"></div> <div class="col-xs-6"></div>
<div class="col-xs-6"> <div class="col-xs-6">
{%- 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("discount_amount")), "- " ~ currency(net_discount)) }}
{{ amount_row(_(doc.meta.get_label("net_total")), doc.get_formatted("net_total", doc)) }} {{ amount_row(_(doc.meta.get_label("net_total")), doc.get_formatted("net_total", doc)) }}
{%- endif -%} {%- endif -%}
@@ -1,14 +1,16 @@
{#- ERPNext's templates/print_formats/includes/total.html, except that with inclusive tax the {#- ERPNext's templates/print_formats/includes/total.html, paired with the taxes include:
"Total (Without Tax)" line is the net total before the Additional Discount: net_total already with inclusive tax and a discount on Grand Total the Total line is the tax-inclusive item
has the discount's net share (item.distributed_discount_amount) taken off, and the taxes total (the discount is printed as entered below it); with inclusive tax otherwise it is
include prints that share and Net Total right below this line. -#} 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 -%}
<div class="row {% if df.bold %}important{% endif %} data-field"> <div class="row {% if df.bold %}important{% endif %} data-field">
{% if doc.flags.show_inclusive_tax_in_print %} {% if doc.flags.show_inclusive_tax_in_print and not gross_discount %}
{%- set before_discount = doc.net_total + (doc.get("items")|map(attribute="distributed_discount_amount")|select|sum) -%}
<div class="col-xs-5 {%- if doc.align_labels_right %} text-right{%- endif -%}"> <div class="col-xs-5 {%- if doc.align_labels_right %} text-right{%- endif -%}">
<label>{{ _("Total (Without Tax)") }}</label></div> <label>{{ _("Total (Without Tax)") }}</label></div>
<div class="col-xs-7 text-right value"> <div class="col-xs-7 text-right value">
{{ frappe.format_value(before_discount, {"fieldtype": "Currency", "options": "currency"}, doc) }} {{ frappe.format_value(doc.net_total + net_discount, {"fieldtype": "Currency", "options": "currency"}, doc) }}
</div> </div>
{% else %} {% else %}
<div class="col-xs-5 {%- if doc.align_labels_right %} text-right{%- endif -%}"> <div class="col-xs-5 {%- if doc.align_labels_right %} text-right{%- endif -%}">
+1
View File
@@ -50,6 +50,7 @@ Amount,จำนวนเงิน
Total,รวม Total,รวม
Total (Without Tax),รวมก่อนภาษี Total (Without Tax),รวมก่อนภาษี
Net Total,ยอดรวมสุทธิ Net Total,ยอดรวมสุทธิ
Total After Discount,ยอดรวมหลังหักส่วนลด
Total Taxes and Charges,รวมภาษีและค่าธรรมเนียม Total Taxes and Charges,รวมภาษีและค่าธรรมเนียม
Grand Total,ยอดรวมทั้งสิ้น Grand Total,ยอดรวมทั้งสิ้น
Rounded Total,ยอดรวมปัดเศษ Rounded Total,ยอดรวมปัดเศษ
1 Net Payable After Withholding Tax ยอดชำระสุทธิหลังหักภาษี ณ ที่จ่าย
50 Total รวม
51 Total (Without Tax) รวมก่อนภาษี
52 Net Total ยอดรวมสุทธิ
53 Total After Discount ยอดรวมหลังหักส่วนลด
54 Total Taxes and Charges รวมภาษีและค่าธรรมเนียม
55 Grand Total ยอดรวมทั้งสิ้น
56 Rounded Total ยอดรวมปัดเศษ