From 997b500767abb9e3615c6843d030c379f70ab01d Mon Sep 17 00:00:00 2001
From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Date: Mon, 19 Oct 2026 22:25:23 +0200
Subject: [PATCH] fix(erpsetup): print the VAT after discount; SEPA days on
offers
With a discount, ERPNext lowers net_total but keeps each tax row's
tax_amount at the pre-discount value. The document template printed
that value next to the gross discount, so the lines did not add up and
the VAT shown was too high (offer SAL-QTN-2026-00001: 212.61 printed,
191.60 charged). The totals now read Zwischensumme, Rabatt (net),
Summe netto, tax after discount, Gesamtbetrag.
Offers and order confirmations also name the debit term from the
payment term ("Einzug 21 Tage nach Rechnungsdatum").
Co-Authored-By: Claude Opus 5.5
+{%- 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) + } + } +}