fix: print the posted discount and tax amounts
ERPNext takes an Additional Discount off the items' net amounts and, for a discount on Grand Total, splits it between net and taxes: each charge is booked at tax_amount_after_discount_amount and Total Taxes and Charges sums those. The print showed the discount as entered and the pre-discount tax_amount, so on a Grand Total discount the VAT line disagreed with the invoice. The totals includes now print the discount's net share (sum of item.distributed_discount_amount), Net Total, and each charge after discount, so the lines add up to Grand Total whichever total the discount applies on and with inclusive or exclusive tax. A discount that is not distributed (cash / non-trade) stays after the charges.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,6 +1,11 @@
|
|||||||
{#- ERPNext's templates/print_formats/includes/taxes.html, but a discount on Net Total is
|
{#- ERPNext's templates/print_formats/includes/taxes.html, printing the amounts that are posted.
|
||||||
followed by the Net Total line so the print reads Total, discount, Net Total, charges.
|
|
||||||
A discount on Grand Total stays after the charges, as upstream. -#}
|
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) -%}
|
{%- 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 -%}">
|
||||||
@@ -11,20 +16,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{%- endmacro -%}
|
{%- 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 -%}
|
||||||
|
|
||||||
<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 doc.discount_amount and doc.apply_discount_on == "Net Total" -%}
|
{%- if net_discount -%}
|
||||||
{{ amount_row(_(doc.meta.get_label("discount_amount")), "- " ~ doc.get_formatted("discount_amount", doc)) }}
|
{{ 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 -%}
|
||||||
{%- for charge in data -%}
|
{%- 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) -%}
|
{%- 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", doc)) }}
|
{{ amount_row(charge.get_formatted("description"), charge.get_formatted("tax_amount_after_discount_amount", doc)) }}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
{%- if doc.discount_amount and doc.apply_discount_on == "Grand Total" -%}
|
{%- if doc.discount_amount and not net_discount -%}
|
||||||
{{ amount_row(_(doc.meta.get_label("discount_amount")), "- " ~ doc.get_formatted("discount_amount", doc)) }}
|
{{ amount_row(_(doc.meta.get_label("discount_amount")), "- " ~ doc.get_formatted("discount_amount", doc)) }}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{#- ERPNext's templates/print_formats/includes/total.html, except that with inclusive tax the
|
{#- ERPNext's templates/print_formats/includes/total.html, except that with inclusive tax the
|
||||||
"Total (Without Tax)" line is the total before an Additional Discount on Net Total:
|
"Total (Without Tax)" line is the net total before the Additional Discount: net_total already
|
||||||
net_total already has that discount taken off, so the print would show the same figure
|
has the discount's net share (item.distributed_discount_amount) taken off, and the taxes
|
||||||
before and after the discount line. -#}
|
include prints that share and Net Total right below this line. -#}
|
||||||
<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 %}
|
||||||
{%- set before_discount = doc.net_total + (doc.discount_amount if doc.apply_discount_on == "Net Total" else 0) -%}
|
{%- 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">
|
||||||
|
|||||||
Reference in New Issue
Block a user