fix(invoiceintake): forwarded invoices get an enter-by-hand ToDo
A mail from our own domain or a freemail address no supplier has was forwarded by a person; no supplier record can match it, so the ToDo now says to enter the invoice by hand instead of suggesting a retry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e96bd39e21
commit
3d093f84af
2 files changed
+39
-13
No files matched your search
@@ -201,10 +201,15 @@ func (in *Intake) one(ctx context.Context, m communication) (Result, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
supplier, how, err := in.supplierFor(ctx, m.Sender)
|
||||
supplier, how, forwarded, err := in.supplierFor(ctx, m.Sender)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
if supplier == "" && forwarded {
|
||||
// The sender is us (or a freemail address): no supplier record can
|
||||
// ever match it, so a retry would only repeat this ToDo.
|
||||
return in.todo(ctx, res, "Weitergeleitete Rechnung ("+how+"). Eingangsrechnung von Hand aus der Anlage erfassen, dann diese Aufgabe schließen.")
|
||||
}
|
||||
if supplier == "" {
|
||||
return in.todo(ctx, res, "Lieferant nicht erkannt ("+how+"). Lieferanten anlegen oder seine E-Mail-Adresse am Kontakt eintragen, dann diese Aufgabe abbrechen: der nächste Lauf legt den Entwurf an. Oder die Eingangsrechnung von Hand erfassen und die Aufgabe schließen.")
|
||||
}
|
||||
@@ -334,43 +339,45 @@ func (in *Intake) self(ctx context.Context) (string, error) {
|
||||
// supplierFor finds the one supplier that sender belongs to: first by the
|
||||
// exact address (Supplier e-mail, or a Contact linked to a Supplier), then by
|
||||
// its domain unless that is a freemail or our own one. how says which, or why
|
||||
// none was found; it never contains the address itself.
|
||||
func (in *Intake) supplierFor(ctx context.Context, sender string) (string, string, error) {
|
||||
// none was found; it never contains the address itself. forwarded is true
|
||||
// when the sender is our own domain, or a freemail address no supplier has:
|
||||
// then the mail was forwarded by a person, and no supplier will ever match.
|
||||
func (in *Intake) supplierFor(ctx context.Context, sender string) (supplier, how string, forwarded bool, err error) {
|
||||
addr, err := mail.ParseAddress(sender)
|
||||
if err != nil {
|
||||
return "", "sender unreadable", nil
|
||||
return "", "Absender nicht lesbar", false, nil
|
||||
}
|
||||
email := strings.ToLower(addr.Address)
|
||||
domain := email[strings.LastIndex(email, "@")+1:]
|
||||
for _, own := range in.cfg.OwnDomains {
|
||||
if domain == strings.ToLower(own) {
|
||||
return "", "weitergeleitet aus eigener Domain", nil
|
||||
return "", "aus eigener Domain", true, nil
|
||||
}
|
||||
}
|
||||
s, err := in.suppliersMatching(ctx, "=", email)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", "", false, err
|
||||
}
|
||||
if len(s) == 1 {
|
||||
return s[0], "address", nil
|
||||
return s[0], "address", false, nil
|
||||
}
|
||||
if len(s) > 1 {
|
||||
return "", "Adresse passt zu mehreren Lieferanten", nil
|
||||
return "", "Adresse passt zu mehreren Lieferanten", false, nil
|
||||
}
|
||||
if freemail[domain] {
|
||||
return "", "Freemail-Absender", nil
|
||||
return "", "von einer Freemail-Adresse", true, nil
|
||||
}
|
||||
s, err = in.suppliersMatching(ctx, "like", "%@"+domain)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", "", false, err
|
||||
}
|
||||
switch len(s) {
|
||||
case 1:
|
||||
return s[0], "domain", nil
|
||||
return s[0], "domain", false, nil
|
||||
case 0:
|
||||
return "", "Absender-Domain " + domain + " keinem Lieferanten zugeordnet", nil
|
||||
return "", "Absender-Domain " + domain + " keinem Lieferanten zugeordnet", false, nil
|
||||
}
|
||||
return "", "Domain " + domain + " passt zu mehreren Lieferanten", nil
|
||||
return "", "Domain " + domain + " passt zu mehreren Lieferanten", false, nil
|
||||
}
|
||||
|
||||
func (in *Intake) suppliersMatching(ctx context.Context, op, value string) ([]string, error) {
|
||||
|
||||
@@ -398,3 +398,22 @@ func TestManyMailsArePagedAndChunked(t *testing.T) {
|
||||
t.Fatalf("second run handled %d", len(res))
|
||||
}
|
||||
}
|
||||
|
||||
func TestForwardedMailsSayEnterByHand(t *testing.T) {
|
||||
f, in := setup(t)
|
||||
f.mail("c1", "Me <someone.else@breakpilot.com>", "r.pdf")
|
||||
f.mail("c2", "other@gmail.com", "r.pdf")
|
||||
f.mail("c3", "news@shop.example", "r.pdf")
|
||||
res := run(t, in)
|
||||
if len(res) != 3 {
|
||||
t.Fatalf("results %+v", res)
|
||||
}
|
||||
for _, r := range res[:2] {
|
||||
if !strings.HasPrefix(r.Reason, "Weitergeleitete Rechnung") || strings.Contains(r.Reason, "abbrechen") {
|
||||
t.Errorf("%s: %q", r.Communication, r.Reason)
|
||||
}
|
||||
}
|
||||
if !strings.HasPrefix(res[2].Reason, "Lieferant nicht erkannt") {
|
||||
t.Errorf("unknown supplier: %q", res[2].Reason)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user