Incoming invoices for invoice@ (orca-infra #121, Collectives ERP/08), with the split agreed on 2026-10-20: Strato forwards the originals to DUO, ERPNext's Email Account "Eingangsrechnung" reads the mailbox, and this service only turns those mails into drafts.
What it does per mail
Mail
Result
e-invoice (XRechnung XML, ZUGFeRD PDF)
E Invoice Import draft. eu_einvoice reads and validates it; the person maps supplier and lines, submits the import and creates the Purchase Invoice from it (the app's own flow)
other PDF, supplier known by sender address or domain
draft Purchase Invoice: supplier, posting date = mail date, one placeholder line EINGANGSRECHNUNG at 0, the original attached again
no PDF/XML, unknown/freemail/own-domain sender, or ERPNext refuses the draft
ToDo on the mail, assigned to INTAKE_ASSIGN_TO
It never submits, cancels, changes or deletes a document, and never touches the mail. The client refuses docstatus; a test pins the written doctypes to Purchase Invoice, E Invoice Import, File and ToDo.
No state of its own: which mails are done is read from ERPNext (intake_communication, unique on both doctypes; ToDo reference). Cancelling a ToDo makes the next run try again, for example after the supplier has been created.
Logs carry Communication and document names and counts only, no senders, subjects or amounts.
No amounts yet: extraction from plain PDFs via LiteLLM is a follow-up PR (PDF→text in the image, plus its own LiteLLM key).
erpsetup
It adds:
the custom fields Purchase Invoice.intake_communication and E Invoice Import.intake_communication (Link to the Communication, unique, read-only; Frappe stores an empty unique field as NULL, so hand-made invoices do not collide);
the unit Stück, the item group Eingangsrechnungen and the item EINGANGSRECHNUNG (purchase only, non-stock);
the item's default expense account, SKR04 6300 Sonstige betriebliche Aufwendungen. If that account is missing, the step reports "missing (not created)".
Run
ERP_BASE_URL=https://erp.breakpilot.com ERP_API_KEY=… ERP_API_SECRET=… go run ./cmd/invoiceintake -once -dry-run
As a service: image /invoiceintake, every INTAKE_INTERVAL (10m). Other settings: INTAKE_SINCE, INTAKE_ASSIGN_TO, INTAKE_EMAIL_ACCOUNT (Eingangsrechnung), INTAKE_COMPANY (Breakpilot GmbH), INTAKE_OWN_DOMAINS (breakpilot.com).
The API user only needs the standard roles Accounts User, Purchase User and Inbox User, plus the Email Account under its User Emails, so no permission tables are changed. Those roles could submit, but the service never does.
Tests
go test ./internal/invoiceintake ./internal/erpsetup runs against a fake ERPNext. It covers:
the e-invoice path, the plain-PDF draft (by address and by domain) and every ToDo case;
idempotency, including a fresh process;
a cancelled ToDo being retried;
a refused draft;
server errors on the e-invoice import (retried, then treated as a plain PDF);
Incoming invoices for invoice@ (orca-infra #121, Collectives ERP/08), with the split agreed on 2026-10-20: Strato forwards the originals to DUO, ERPNext's Email Account "Eingangsrechnung" reads the mailbox, and this service only turns those mails into drafts.
## What it does per mail
| Mail | Result |
|---|---|
| e-invoice (XRechnung XML, ZUGFeRD PDF) | **E Invoice Import** draft. eu_einvoice reads and validates it; the person maps supplier and lines, submits the import and creates the Purchase Invoice from it (the app's own flow) |
| other PDF, supplier known by sender address or domain | **draft Purchase Invoice**: supplier, posting date = mail date, one placeholder line `EINGANGSRECHNUNG` at 0, the original attached again |
| no PDF/XML, unknown/freemail/own-domain sender, or ERPNext refuses the draft | **ToDo** on the mail, assigned to `INTAKE_ASSIGN_TO` |
- It never submits, cancels, changes or deletes a document, and never touches the mail. The client refuses `docstatus`; a test pins the written doctypes to Purchase Invoice, E Invoice Import, File and ToDo.
- No state of its own: which mails are done is read from ERPNext (`intake_communication`, unique on both doctypes; ToDo reference). Cancelling a ToDo makes the next run try again, for example after the supplier has been created.
- Logs carry Communication and document names and counts only, no senders, subjects or amounts.
- No amounts yet: extraction from plain PDFs via LiteLLM is a follow-up PR (PDF→text in the image, plus its own LiteLLM key).
## erpsetup
It adds:
- the custom fields `Purchase Invoice.intake_communication` and `E Invoice Import.intake_communication` (Link to the Communication, unique, read-only; Frappe stores an empty unique field as NULL, so hand-made invoices do not collide);
- the unit `Stück`, the item group `Eingangsrechnungen` and the item `EINGANGSRECHNUNG` (purchase only, non-stock);
- the item's default expense account, SKR04 **6300** Sonstige betriebliche Aufwendungen. If that account is missing, the step reports "missing (not created)".
## Run
```
ERP_BASE_URL=https://erp.breakpilot.com ERP_API_KEY=… ERP_API_SECRET=… go run ./cmd/invoiceintake -once -dry-run
```
As a service: image `/invoiceintake`, every `INTAKE_INTERVAL` (10m). Other settings: `INTAKE_SINCE`, `INTAKE_ASSIGN_TO`, `INTAKE_EMAIL_ACCOUNT` (Eingangsrechnung), `INTAKE_COMPANY` (Breakpilot GmbH), `INTAKE_OWN_DOMAINS` (breakpilot.com).
The API user only needs the standard roles **Accounts User**, **Purchase User** and **Inbox User**, plus the Email Account under its User Emails, so no permission tables are changed. Those roles could submit, but the service never does.
## Tests
`go test ./internal/invoiceintake ./internal/erpsetup` runs against a fake ERPNext. It covers:
- the e-invoice path, the plain-PDF draft (by address and by domain) and every ToDo case;
- idempotency, including a fresh process;
- a cancelled ToDo being retried;
- a refused draft;
- server errors on the e-invoice import (retried, then treated as a plain PDF);
- dry run, bad key, and paging over 1234 mails.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
New cmd/invoiceintake (orca-infra #121, Collectives ERP/08). It reads the
mails of ERPNext's Email Account "Eingangsrechnungen" through the REST API
(no IMAP of its own; Strato forwards the originals to DUO) and, per mail:
- e-invoice (XML first, then PDF): E Invoice Import draft, eu_einvoice
reads and validates it; the person maps and creates the Purchase Invoice
- other PDF: draft Purchase Invoice for the supplier matched by sender
address or domain, one placeholder line, the original attached again
- no PDF/XML, unknown sender, or a refused draft: a ToDo on the mail
It never submits, changes or deletes anything and keeps no state: done
mails are read back from ERPNext (intake_communication, unique; ToDo
reference). A cancelled ToDo asks for another try. Dry run with -once
-dry-run; logs carry document names and counts, no senders or subjects.
erpsetup gains the two marker fields, the placeholder item EINGANGSRECHNUNG
(unit Stück, group Eingangsrechnungen) and its expense account SKR04 6300.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Incoming invoices for invoice@ (orca-infra #121, Collectives ERP/08), with the split agreed on 2026-10-20: Strato forwards the originals to DUO, ERPNext's Email Account "Eingangsrechnung" reads the mailbox, and this service only turns those mails into drafts.
What it does per mail
EINGANGSRECHNUNGat 0, the original attached againINTAKE_ASSIGN_TOdocstatus; a test pins the written doctypes to Purchase Invoice, E Invoice Import, File and ToDo.intake_communication, unique on both doctypes; ToDo reference). Cancelling a ToDo makes the next run try again, for example after the supplier has been created.erpsetup
It adds:
Purchase Invoice.intake_communicationandE Invoice Import.intake_communication(Link to the Communication, unique, read-only; Frappe stores an empty unique field as NULL, so hand-made invoices do not collide);Stück, the item groupEingangsrechnungenand the itemEINGANGSRECHNUNG(purchase only, non-stock);Run
As a service: image
/invoiceintake, everyINTAKE_INTERVAL(10m). Other settings:INTAKE_SINCE,INTAKE_ASSIGN_TO,INTAKE_EMAIL_ACCOUNT(Eingangsrechnung),INTAKE_COMPANY(Breakpilot GmbH),INTAKE_OWN_DOMAINS(breakpilot.com).The API user only needs the standard roles Accounts User, Purchase User and Inbox User, plus the Email Account under its User Emails, so no permission tables are changed. Those roles could submit, but the service never does.
Tests
go test ./internal/invoiceintake ./internal/erpsetupruns against a fake ERPNext. It covers:🤖 Generated with Claude Code