fix(invoiceintake): UBL e-invoice goes to the plain draft at once
ci / shared (pull_request) Successful in 13s
ci / test (pull_request) Successful in 24m56s
ci / image (pull_request) Skipped

eu_einvoice reads CII only and answers a UBL XRechnung with a 500
("Invalid XML, found tag …ubl…Invoice"). The intake took that for a
transient error and retried three runs (30 min) before the plain
draft. A wrong root element is now treated like the 417 "not an
e-invoice": next file, then the draft with the original attached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-29 13:42:48 +01:00
1 parent ee8ae87917
commit daca82ecf6
2 files changed
+30 -1

No files matched your search

+10
View File
@@ -268,6 +268,8 @@ func (in *Intake) einvoice(ctx context.Context, m communication, invoices []file
return "", true, err // the API user's roles, not the file
case s/100 == 4:
continue // not an e-invoice ("No machine-readable data …")
case s/100 == 5 && wrongSyntax(err):
continue // e.g. UBL: a retry can't change the file
case s/100 == 5:
in.retries[m.Name]++
in.cfg.Log("%s: e-invoice import failed (%v), try %d of %d", m.Name, err, in.retries[m.Name], maxEInvoiceRetries)
@@ -279,6 +281,14 @@ func (in *Intake) einvoice(ctx context.Context, m communication, invoices []file
return "", false, nil
}
// wrongSyntax: eu_einvoice reads CII only and answers a UBL XRechnung (or any
// XML with another root element) with a 500, "Invalid XML, found tag
// {…ubl…}Invoice where {…}CrossIndustryInvoice was expected". Retrying only
// delays the plain draft by three runs.
func wrongSyntax(err error) bool {
return strings.Contains(messageOf(err), "Invalid XML, found tag")
}
func (in *Intake) attach(ctx context.Context, doctype, name string, files []file) error {
var errs []error
for _, f := range files {
+20 -1
View File
@@ -20,6 +20,7 @@ type fakeERP struct {
docs map[string][]map[string]any
writes []string // "POST <doctype>" in order
einvErr int // status for E Invoice Import of a file without "einv" in its name
einvMsg string // its exception text, "" = eu_einvoice's "no machine-readable data"
failPI int // status for every Purchase Invoice create, 0 = accept
}
@@ -153,7 +154,11 @@ func (f *fakeERP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
if doctype == "E Invoice Import" && !strings.Contains(fmt.Sprint(doc["einvoice"]), "einv") {
reply(f.einvErr, map[string]any{"exception": "frappe.exceptions.ValidationError: No machine-readable data was found in the PDF file."})
msg := f.einvMsg
if msg == "" {
msg = "frappe.exceptions.ValidationError: No machine-readable data was found in the PDF file."
}
reply(f.einvErr, map[string]any{"exception": msg})
return
}
if doctype == "Purchase Invoice" && f.failPI != 0 {
@@ -350,6 +355,20 @@ func TestEInvoiceServerErrorIsRetriedThenPlain(t *testing.T) {
}
}
func TestEInvoiceWrongSyntaxIsPlainAtOnce(t *testing.T) {
f, in := setup(t)
f.einvErr = http.StatusInternalServerError
f.einvMsg = "TypeError: Invalid XML, found tag {urn:oasis:names:specification:ubl:schema:xsd:Invoice-2}Invoice where {urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100}CrossIndustryInvoice was expected"
f.mail("c1", "billing@hetzner.example", "ubl.xml")
res := run(t, in)
if len(res) != 1 || res[0].Outcome != Draft {
t.Fatalf("results %+v", res)
}
if in.retries["c1"] != 0 {
t.Errorf("retries %d", in.retries["c1"])
}
}
func TestDryRunCreatesNothing(t *testing.T) {
f, in := setup(t)
in.cfg.DryRun = true