From b4c184c26f52216545d148a5f6d68383f014a54d Mon Sep 17 00:00:00 2001
From: Sharang Parnerkar
+{%- if net_discount > 0.005 %}
+
@@ -288,7 +292,8 @@ Bitte sorgen Sie für ausreichende Kontodeckung.
+Zwischensumme {{ doc.get_formatted("total") }}
+{%- endif %}
Rabatt − {{ frappe.utils.fmt_money(net_discount, currency=doc.currency) }}
-{%- if doc.discount_amount %}Summe netto {{ doc.get_formatted("net_total") }} {% endif %}
-{%- for t in doc.taxes %}{% if t.tax_amount %}
-Rabatt − {{ doc.get_formatted("discount_amount") }}
+{%- for t in doc.taxes %}{% if t.tax_amount_after_discount_amount %}
+{{ t.description }}{% if t.rate and "%" not in t.description %} ({{ ("%g"|format(t.rate)) | replace(".", ",") }} %){% endif %} {{ t.get_formatted("tax_amount", doc) }}
{%- endif %}{% endfor %}
{{ t.description }}{% if t.rate and "%" not in t.description %} ({{ ("%g"|format(t.rate)) | replace(".", ",") }} %){% endif %} {{ t.get_formatted("tax_amount_after_discount_amount", doc) }} Gesamtbetrag {{ doc.get_formatted("rounded_total" if doc.rounded_total else "grand_total") }}
Bitte überweisen Sie den Rechnungsbetrag bis zum {{ frappe.utils.formatdate(doc.due_date) }} unter Angabe der Rechnungsnummer {{ doc.name }}.
{%- endif %} {%- elif not is_inv and sepa %} -Zahlungsart: SEPA-Lastschrift {{ "gemäß erteiltem SEPA-Lastschriftmandat" if has_mandate else "nach Erteilung eines gültigen SEPA-Lastschriftmandats" }}.
+{%- set term = frappe.db.get_value("Payment Term", doc.payment_schedule[0].payment_term, ["credit_days", "due_date_based_on"], as_dict=1) if doc.payment_schedule[0].payment_term else None -%} +Zahlungsart: SEPA-Lastschrift{% if term and term.credit_days and term.due_date_based_on == "Day(s) after invoice date" %}, Einzug {{ term.credit_days }} Tage nach Rechnungsdatum{% endif %}, {{ "gemäß erteiltem SEPA-Lastschriftmandat" if has_mandate else "nach Erteilung eines gültigen SEPA-Lastschriftmandats" }}.
{%- endif %} {%- if doc.get("terms") %}Vielen Dank für Ihr Vertrauen.
diff --git a/internal/erpsetup/erpsetup_test.go b/internal/erpsetup/erpsetup_test.go index 2fa3124..742f78a 100644 --- a/internal/erpsetup/erpsetup_test.go +++ b/internal/erpsetup/erpsetup_test.go @@ -517,3 +517,17 @@ func TestLetterHeadSourceIsRestoredAndTbodyIgnored(t *testing.T) { t.Fatalf("source not restored: %v", lh["source"]) } } + +// With a discount (above all one on the grand total) ERPNext lowers net_total +// but keeps tax_amount at the pre-discount value; the printed VAT must be the +// amount after the discount, and the lines must add up to the total. +func TestTotalsPrintTheTaxAfterDiscount(t *testing.T) { + if strings.Contains(documentHTML, `get_formatted("tax_amount", doc)`) || strings.Contains(documentHTML, `get_formatted("discount_amount")`) { + t.Fatal("totals print the pre-discount tax or the gross discount") + } + for _, want := range []string{`tax_amount_after_discount_amount`, `Zwischensumme`, `doc.total`, `Einzug {{ term.credit_days }} Tage`} { + if !strings.Contains(documentHTML, want) { + t.Errorf("document template lacks %q", want) + } + } +}