Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ One table for quotes, invoices and credit notes.
`document` FK, `paid_on`, `amount_cents`, `method`, `note`. Payment state (unpaid, partial, paid, credited) is derived, not stored: an invoice is settled by its payments plus the issued credit notes against it; "credited" when the credit notes alone cover the total. Outstanding = invoice total − issued credit notes − payments.

### Attachment
`document` or `expense` FK, `file`, `kind` (`original_pdf`, `receipt`, `other`), `sha256`, `source`. Never both. Neither only for a receipt waiting for an expense, fetched from the receipts folder (`source` `bonnetjesmap`, M20).
`document` or `expense` FK, `file`, `kind` (`original_pdf`, `receipt`, `other`), `sha256`, `source`. Never both. Neither only for a receipt waiting for an expense, fetched from the receipts folder (`source` `bonnetjesmap`, M20) or taken with a phone's camera (`source` `telefoon`, M20).

### Expense
`date`, `supplier`, `description`, `amount_cents` (**gross amount paid**, always stored gross: invariant 7 of CLAUDE.md), `vat_info_cents` (under the KOR informational; with the KOR off the input VAT, decided by the owner 2026-11-06, not built yet: issue "Voorbelasting op uitgaven"), `source`, `external_id`. Has lines, as in Moneybird (decided 2026-11-02, `huismus-intern/besluiten.md`): `amount_cents` and `vat_info_cents` are the sums of its lines, stored by one function (`huismus/expenses/lines.py`).
Expand Down Expand Up @@ -308,6 +308,7 @@ Decided by the owner on 2026-11-04 (`huismus-intern/backlog.md`); build choices
- **Never paid twice:** a receipt counts as read once the service answered, whatever the answer, and after a timeout (3 minutes; the work may have been done). Errors where the service did no work (unreachable, key refused, unknown model, busy or out of credit, a server error) are red above the tray and on Bonnetjes lezen, not on the overview, and the receipts wait for the next look.
- **What the user sees:** under each receipt in the tray "Huismus leest dit bonnetje…" while it waits for its turn, or "Niet gelezen: <reason>" when it stayed (a similar expense links to it); "Uitgave maken" stays. On the overview, below "n nieuwe bonnetjes" (which then counts only receipts that stay in the tray, or wait while the service fails), "n nieuwe uitgaven om na te kijken" with "Bekijken →" to Verwerken, counted from the last visit to Verwerken or the Nakijken list. While reading, nothing else changes on the overview. Code: `huismus/expenses/reading.py`, which `expenses.inbox` calls after each look.
- **Verwerken** (`/uitgaven/verwerken/`, `huismus/expenses/process_views.py`; decided by the product-owner agent on 2026-11-06, `huismus-intern/besluiten.md`, "Verwerken: één stapel, het bonnetje groot naast de velden"). One stack of everything that waits, one at a time: first the expenses to check (the order of Nakijken, date newest first), then the receipts without an expense (the tray's order, newest first), whether Huismus left them with a reason, is still reading them, or no service is set up (`huismus/expenses/batch.py`). Reached by the button "Verwerken (n)" on Uitgaven (n the whole stack, gone at 0; "Bonnetjes (n)" stays), "Bekijken →" of "n nieuwe uitgaven om na te kijken" on the overview, "Uitgave maken" in the tray, and "Klopt"/"Overslaan" on an expense's own page. On a wide screen (the 980px breakpoint) the receipt is large on the left, half the width, staying in view while the fields scroll: a photo whole, a PDF in the browser's own viewer with every page (the file may be framed by Huismus's own pages only, `X-Frame-Options: SAMEORIGIN`; app.js sets the frame's address on a wide screen only). On a phone the receipt is above the fields, a photo at most half the screen high, a PDF as its name (an iPhone shows only the first page of a frame); everywhere "Bonnetje openen" opens the file in a new tab. No PDF rendering on the server. An expense without a receipt shows "Geen bonnetje bij deze uitgave." with the expense page's upload. On the right the expense page's fields and lines: an expense with its notice ("Huismus las dit bonnetje met …" or the assistant's) and **Klopt**; a receipt with empty fields, the tray's line ("Niet gelezen: …" or "Huismus leest dit bonnetje…") in that same notice (none without one) and **Opslaan**. Both save through the expense page's code, take the mark away and go on to the next one (the first after this one in the stack as it was, else the top one left); **Overslaan** goes there without saving. At the top "3 van 24": the ones done in this round plus where this one is in what is left, of the ones done plus what is left; the number done (`?klaar=`, a hidden field in the form) counts only Klopt and Opslaan and is never stored. An error stays on the same item with the same count; "Regel toevoegen" without JS shows the same item with one line more, saving nothing. After the last one, or with nothing to do, "Niets meer te verwerken." and "Naar Uitgaven". No "Verwijderen" here: in the tray or on the expense. With the KOR off, VAT per line stays required, via Klopt and via Opslaan. The new-expense form without a receipt is unchanged; `/uitgaven/nieuw/?bonnetje=<pk>` opens Verwerken at that receipt.
- **The photo first, on a phone** (#188; the step chosen by the owner on 2026-11-15 with the new house style, build choices by the product-owner agent the same day, `huismus-intern/besluiten.md`). On a phone (JS: `(max-width: 760px) and (pointer: coarse)`) every link to the new-expense form opens the camera instead (`capture="environment"`); cancelling it opens the ordinary form, a browser that doesn't say "cancel" leaves the user where they tapped. The photo is sent at once with "Bonnetje uploaden…" (`/uitgaven/nieuw/foto/`, `huismus/expenses/photo_views.py`) and goes into the tray (`source` `telefoon`), so walking away never loses it; a refused file (too big, not a receipt) goes to the ordinary form with the upload's reason. Without a connection the page stays, with "Huismus is niet bereikbaar. Probeer het opnieuw als je verbinding hebt." and "Opnieuw proberen", which sends the same photo again. Then `/uitgaven/nieuw/foto/<pk>/`, "Nieuwe uitgave": the photo with "Opnieuw" (a new photo; the old one goes only once the new one is in, and only a photo taken this way that still waits in the tray), then one line: "Bedrag, zoals je het betaalde" (large), without the KOR "Btw" and "Btw-tarief" right under it, "Leverancier", "Datum" (today) and "Categorie". **Uitgave opslaan** saves through Verwerken's code, the receipt onto the expense, and goes to Uitgaven ("Uitgave opgeslagen."); **Alleen de foto bewaren** leaves it in the tray, starts Bonnetjes lezen if that is on, and goes to Uitgaven ("Bonnetje bewaard. Je vindt het bij Verwerken."). "Meer regels of een omschrijving" opens Verwerken at that receipt with what was typed and one line more, saving nothing. A wide screen or a mouse, the desktop app (never, even in a narrow window on a touch screen) and no JS keep the ordinary form.
- Not in part 2: a scheduled task in the Claude app, a notice from macOS or Windows (`huismus-intern/backlog.md`).
*Done when:* tests cover fetching (new, the same twice, a name taken in `Opgehaald`, files left with a reason, a file still syncing, a folder that's gone, saving or moving failing, the sample data), Dropbox and WebDAV against the fakes (the folder, unlinking, backups leaving it alone; on WebDAV also a name taken in `Opgehaald`, a file still being written, a refused password), the pages, making an expense from a receipt, looking sooner (a new file in a folder, the minute's wait, a skipped file once, a folder gone, the restore gate, Dropbox's wait against the fake with backoff and a forgotten cursor), the notice (new, seen, singular, off, sample data, only reading), and HEIC (a JPG with the original's name, upright and without metadata, at most 4032 px, the same JPG every time so it is fetched once and a failed move only moves next time, a damaged one or one of too many pixels left with a reason, the upload field); the pages are in `test_every_page.py`; a browser test sets up a folder, picks up now and makes an expense; strings exist in Dutch and English; `docs/hulp/bonnetjes.*.md` explains it. *Part 2:* tests cover the list, a photo (smaller, upright, PNG with transparency), a PDF with text, a scanned PDF, an unreadable PDF, an image of too many pixels, other attachments refused, and the receipt going onto the expense or nothing saved; `docs/hulp/bonnetjes.*.md` and `ai-assistenten.*.md` explain it. *Part 2b:* tests cover the mark from `add_expense`, the pill, the button and its count, the filter, "Klopt" (onward, the last one, an error keeps the mark), "Overslaan", the order, and saving; browser tests check three expenses with "Klopt" and "Overslaan", and three receipts made into expenses one after the other. *Verwerken:* tests cover the order of the stack, next after a save and round again, the count with `klaar`, Klopt, Opslaan with the receipt, Overslaan, an error, "Regel toevoegen" without JS, the KOR off, an expense without a receipt and its upload, items gone meanwhile, the empty stack, the PDF frame header, and English; browser tests process a photo, a PDF and a receipt at 1440 px (beside the fields, in view while scrolling, the PDF in a frame) and at 390 px (above the fields, no frame); the pages are in `test_every_page.py` with the demo receipts (`huismus/core/demo_receipts.py`). *Part 3:* tests against a fake service (never a real one) cover the page (a known service filled in, the address and key rules, saving tested first, the key never shown, kept when left empty, testing, turning off, left out of backups), and reading (an expense with the mark and the receipt, each reason to leave a receipt, VAT without the KOR, a duplicate, failures that retry and a timeout that doesn't, a receipt taken meanwhile, the sample data); browser tests choose a service and see a receipt become an expense; `docs/hulp/bonnetjes.*.md` and `ai-assistenten.*.md` explain it.

Expand Down
17 changes: 17 additions & 0 deletions docs/hulp/telefoon.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ home screen there's **Share**: use it to mail the PDF or save it to
Files. In the browser there's **Download**, and **Share** too if the browser
can share files.

## An expense with the camera

Tap **+** and then **Expense**, or **New expense** under Expenses: the camera
opens. Take a photo of the receipt. Huismus keeps it at once. Then fill in the
amount, then the supplier, the date and the category, and tap **Save
expense**.

No time? Tap **Just keep the photo**. The receipt then waits under
**Process** on the Expenses page, where you make it into an expense later.
Photo didn't work out? Tap **Retake**.

Can't reach Huismus, for example in a shop without your VPN? The photo stays
on your screen. Tap **Try again** once you're connected.

Rather use a photo from your library or a PDF? Close the camera: you get the
ordinary form.

## What's on your phone

Your records aren't on it. Everything stays on the server, and the app only
Expand Down
18 changes: 18 additions & 0 deletions docs/hulp/telefoon.nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ beginscherm staat daar **Delen**: zo mail je de pdf of bewaar je hem in
Bestanden. In de browser staat er **Downloaden**, en als de browser kan
delen ook **Delen**.

## Een uitgave met de camera

Tik op **+** en dan op **Uitgave**, of op **Nieuwe uitgave** bij Uitgaven: de
camera gaat open. Maak een foto van het bonnetje. Huismus bewaart hem meteen.
Daarna vul je het bedrag in, dan de leverancier, de datum en de categorie, en
tik je op **Uitgave opslaan**.

Geen tijd? Tik op **Alleen de foto bewaren**. Het bonnetje staat dan bij
**Verwerken** op de pagina Uitgaven, en daar maak je er later een uitgave van.
Is de foto mislukt, tik dan op **Opnieuw**.

Huismus is niet bereikbaar, bijvoorbeeld in de winkel zonder VPN? Dan blijft de
foto op je scherm staan. Tik op **Opnieuw proberen** als je weer verbinding
hebt.

Wil je liever een foto uit je fotobibliotheek of een pdf? Sluit dan de camera:
je krijgt het gewone formulier.

## Wat er op je telefoon staat

Niets van je administratie. Alles blijft op de server, en de app laat alleen
Expand Down
3 changes: 3 additions & 0 deletions docs/hulp/uitgaven.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ or a PDF. Huismus keeps a HEIC photo as a JPG. For a new expense you can do this
**Save**. An expense can have more than one receipt: add the others after
saving.

On your phone a new expense starts with the camera. See [On your
phone](telefoon.en.md).

Receipts from the road can also go in a folder that Huismus picks up
itself. See [Receipts on the road](bonnetjes.en.md).

Expand Down
3 changes: 3 additions & 0 deletions docs/hulp/uitgaven.nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ HEIC) of een pdf. Een HEIC-foto bewaart Huismus als JPG. Bij een nieuwe uitgave
**Opslaan** klikt. Een uitgave kan meer bonnetjes hebben: de rest voeg je toe
na het opslaan.

Op je telefoon begint een nieuwe uitgave met de camera. Zie [Op je
telefoon](telefoon.nl.md).

Bonnetjes van onderweg kun je ook in een map zetten die Huismus zelf
ophaalt. Zie [Bonnetjes onderweg](bonnetjes.nl.md).

Expand Down
82 changes: 82 additions & 0 deletions huismus/core/static/core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,85 @@ function showReceiptPdfs(root) {
wideScreen.addEventListener("change", () => showReceiptPdfs(document));
if (window.htmx) window.htmx.onLoad(showReceiptPdfs);
else showReceiptPdfs(document);

// The photo first (#188, expenses/photo_views.py): on a phone, a link to the
// new-expense form opens the camera instead. The photo is sent at once;
// Huismus puts it with the receipts and opens the page with the amount.
// Cancelling the camera opens the ordinary form, where a photo from the
// library, a PDF or no receipt at all is possible. On a wide screen, in the
// desktop app and without JS, the link is the ordinary form.
const phone = window.matchMedia("(max-width: 760px) and (pointer: coarse)");

// Capture, and no further: htmx's boost listens on the link itself.
document.addEventListener(
"click",
(event) => {
const camera = document.getElementById("camera");
const link = event.target.closest?.("a[href]");
if (!camera || !link || !phone.matches || event.defaultPrevented) return;
if (link.pathname !== camera.dataset.newExpense || link.search) return;
event.preventDefault();
event.stopPropagation();
link.closest("[popover]")?.hidePopover();
const input = camera.querySelector("input[type=file]");
input.value = "";
// Browsers that don't say "cancel" leave the user where they tapped.
input.oncancel = () => window.location.assign(link.href);
input.click();
},
true,
);

// A photo taken, from that hidden form or from "Opnieuw" on the photo page:
// sent with fetch, so a failed connection leaves the photo here to send
// again. A photo from the camera isn't always in the library too: a
// browser error page would lose it.
let unsent = null;

function cameraToast(id) {
for (const toast of document.querySelectorAll("[data-camera-toast]")) toast.remove();
const template = document.getElementById(id);
if (template) document.getElementById("toasts")?.append(template.content.cloneNode(true));
}

async function sendPhoto(form, file) {
unsent = { form, file };
cameraToast("camera-busy");
const data = new FormData(form);
data.set("file", file);
let response;
try {
// The header asks Huismus to say where to go (X-Huismus-Go) rather than
// to redirect: following a redirect here would use up the next page's
// message, such as why it refused the file (expenses/photo_views.py).
response = await fetch(form.action, {
method: "POST",
body: data,
headers: { "X-Huismus-Camera": "1" },
});
} catch {
// No answer at all: no connection with Huismus.
cameraToast("camera-offline");
return;
}
if (!response.ok) {
// Huismus answered, with an error.
cameraToast("camera-failed");
return;
}
unsent = null;
// Where Huismus sends it: the photo page, or the ordinary form with the
// reason it refused the file. Signed out meanwhile: the login page.
window.location.assign(response.headers.get("X-Huismus-Go") || response.url);
}

document.addEventListener("change", (event) => {
const input = event.target;
if (!input.matches?.("input[type=file][data-camera]") || !input.files.length) return;
input.oncancel = null;
sendPhoto(input.form, input.files[0]);
});

document.addEventListener("click", (event) => {
if (event.target.closest?.("[data-camera-retry]") && unsent) sendPhoto(unsent.form, unsent.file);
});
10 changes: 10 additions & 0 deletions huismus/core/static/core/huismus.css
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,16 @@ div.hint-banner:hover { border-color: var(--border); }
.process-receipt { position: static; }
.process-img { max-height: 50dvh; }
}
/* A new expense on a phone, the photo first (#188, expenses/photo.html):
the photo with "Opnieuw" on it, then the amount, large. */
.photo-shot { position: relative; padding: var(--s-3); }
.photo-shot .process-img { max-height: min(30dvh, 260px); }
.photo-again { position: absolute; right: var(--s-5); bottom: var(--s-5); }
.amount-xl .input { height: 60px; font-size: var(--fs-2xl); font-weight: var(--fw-semibold); }
.amount-xl .money::before { font-size: var(--fs-lg); }
/* Its bar: "Uitgave opslaan" with "Alleen de foto bewaren" under it. */
.actionbar.photo-actions { flex-direction: column; align-items: stretch; flex-wrap: nowrap; gap: 2px; }
.actionbar.photo-actions .btn { flex: none; }

.report { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-1); overflow: hidden; }
.report + .report { margin-top: var(--s-3); }
Expand Down
Loading
Loading