From c0a7db4e5643ebdf50fee98bbd8dbb4890982aa8 Mon Sep 17 00:00:00 2001
From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Date: Tue, 13 Oct 2026 11:07:50 +0200
Subject: [PATCH] fix(erpsetup): restore the letter head source, ignore
from UI saves
The live letter head had source "Image" (saved in the UI on 2026-10-06), so
documents printed an image header instead of the HTML one. erpsetup compared
only content and footer and would never have put it back; it now also
compares source and footer_source.
The same UI save wrapped the table rows in , which made content and
footer look changed on every run. Field comparison now ignores .
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
---
internal/erpsetup/erpsetup.go | 12 ++++++++++--
internal/erpsetup/erpsetup_test.go | 30 ++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/internal/erpsetup/erpsetup.go b/internal/erpsetup/erpsetup.go
index 7f35b0c..ecadcec 100644
--- a/internal/erpsetup/erpsetup.go
+++ b/internal/erpsetup/erpsetup.go
@@ -156,7 +156,7 @@ func Run(ctx context.Context, cfg Config) ([]Step, error) {
[][]any{{"file_url", "=", logoFileURL}}, logoFileDoc()); err != nil {
return r.steps, err
}
- if err := r.ensureFields(ctx, "Letter Head", letterHeadName, "letter head "+letterHeadName, letterHeadDoc(), "content", "footer"); err != nil {
+ if err := r.ensureFields(ctx, "Letter Head", letterHeadName, "letter head "+letterHeadName, letterHeadDoc(), "source", "footer_source", "content", "footer"); err != nil {
return r.steps, err
}
for _, pf := range printFormats() {
@@ -271,7 +271,7 @@ func (r *runner) ensureFields(ctx context.Context, doctype, name, what string, d
_ = json.Unmarshal(body, &cur)
patch := map[string]any{}
for _, k := range keys {
- if fmt.Sprint(cur.Data[k]) != fmt.Sprint(doc[k]) {
+ if !sameValue(cur.Data[k], doc[k]) {
patch[k] = doc[k]
}
}
@@ -430,6 +430,14 @@ func (r *runner) call(ctx context.Context, method, path string, body any) (int,
return resp.StatusCode, raw, nil
}
+// sameValue compares a stored field with the wanted one. Frappe's HTML
+// editor wraps table rows in when a document is saved in the UI;
+// that is not a change of ours and must not show up as one on every run.
+func sameValue(got, want any) bool {
+ norm := strings.NewReplacer("", "", "", "")
+ return norm.Replace(fmt.Sprint(got)) == norm.Replace(fmt.Sprint(want))
+}
+
func truncate(b []byte) string {
s := strings.TrimSpace(string(b))
if len(s) > 300 {
diff --git a/internal/erpsetup/erpsetup_test.go b/internal/erpsetup/erpsetup_test.go
index 3f56857..2fa3124 100644
--- a/internal/erpsetup/erpsetup_test.go
+++ b/internal/erpsetup/erpsetup_test.go
@@ -487,3 +487,33 @@ func TestProductWordingIsNoLegalCheck(t *testing.T) {
}
}
}
+
+func TestLetterHeadSourceIsRestoredAndTbodyIgnored(t *testing.T) {
+ f := newFake()
+ srv := httptest.NewServer(f)
+ defer srv.Close()
+ if _, err := Run(context.Background(), cfg(srv.URL)); err != nil {
+ t.Fatal(err)
+ }
+ lh := f.docs["Letter Head"][letterHeadName]
+ // Saved once in the UI: the editor added , nothing else changed.
+ lh["content"] = strings.ReplaceAll(letterHeadHTML, "", "
")
+ lh["footer"] = strings.ReplaceAll(letterFooterHTML, "", "
")
+ steps, err := Run(context.Background(), cfg(srv.URL))
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, s := range steps {
+ if s.What == "letter head "+letterHeadName && s.Result != "exists" {
+ t.Fatalf("tbody alone must not count as a change: %s", s.Result)
+ }
+ }
+ // The source was switched to Image: that is a change and is put back.
+ lh["source"] = "Image"
+ if _, err := Run(context.Background(), cfg(srv.URL)); err != nil {
+ t.Fatal(err)
+ }
+ if lh["source"] != "HTML" {
+ t.Fatalf("source not restored: %v", lh["source"])
+ }
+}
--
2.54.1