Merge pull request 'fix(invoiceintake): UBL e-invoice goes to the plain draft at once' (#105) from fix/intake-ubl-fastpath into main
ci / shared (push) Successful in 11s
ci / test (push) Successful in 27m7s
ci / image (push) Successful in 34s

This commit was merged in pull request #105.
This commit is contained in:
sharang committed 2026-10-29 13:08:27 +00:00
commit e80076559a
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