fix(erpsetup): restore the letter head source, ignore <tbody> from UI saves
ci / shared (pull_request) Successful in 13s
ci / test (pull_request) Successful in 25m56s
ci / image (pull_request) Skipped

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 <tbody>, which made content and
footer look changed on every run. Field comparison now ignores <tbody>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-13 11:07:50 +02:00
1 parent 8e2d8db4bf
commit c0a7db4e56
2 files changed
+40 -2

No files matched your search

+10 -2
View File
@@ -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 <tbody> 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("<tbody>", "", "</tbody>", "")
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 {
+30
View File
@@ -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 <tbody>, nothing else changed.
lh["content"] = strings.ReplaceAll(letterHeadHTML, "<tr>", "<tbody><tr>")
lh["footer"] = strings.ReplaceAll(letterFooterHTML, "</table>", "</tbody></table>")
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"])
}
}