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 @@ -220,7 +220,7 @@ Decided 2026-10-28 (the owner's request; details by the product-owner agent, `hu

### M13 — Step-by-step start
Decided 2026-10-28 (the owner's request; details by the product-owner agent, `huismus-intern/besluiten.md`). Huismus can be started without a Moneybird export. The welcome card on the empty overview offers two choices: "Stap voor stap beginnen" first, as the primary button, and "Importeren uit Moneybird" second, as a secondary one (besluit 2026-11-03), with the checklist (M8) below; nothing redirects.
- `/welkom/` walks through four steps, each a part of the settings page with its validation (a plain POST, no JS needed): **Bedrijf** (the fields the settings require, plus legal form, phone, website and VAT number as optional), **KOR** (switch, text, limit and warning percentage, M12), **Facturen** (payment terms, invoice and quote number format, with "Volgende als je vandaag uitgeeft: …") and **Logo** (upload, or skip). A step saves only its own fields; "Terug" goes to the previous step. Then a done page with the sparrow: "Eerste klant toevoegen" and "Naar het overzicht".
- `/welkom/` walks through four steps, each a part of the settings page with its validation (a plain POST, no JS needed): **Bedrijf** (the fields the settings require, plus legal form, phone, website and VAT number as optional), **KOR** (switch, text, limit and warning percentage, M12), **Facturen** (payment terms, invoice and quote number format, with "Volgende als je vandaag uitgeeft: …", and the next sequence number of each as on Facturen en nummering, section 7) and **Logo** (upload, or skip). A step saves only its own fields; "Terug" goes to the previous step. Then a done page with the sparrow: "Eerste klant toevoegen" and "Naar het overzicht".
- It always starts at step 1 with the saved values filled in; nothing records which steps were done. `/welkom/` stays reachable by its address, but only the empty overview links to it.
- The KOR text field gets the same suggestion as on the settings page (since M1); the wizard adds no text of its own.
- Not in this milestone: a step for the language or the first customer, a round after a Moneybird import, and a password step (M11: in the desktop app the done page links to Wachtwoord instead).
Expand Down Expand Up @@ -360,6 +360,7 @@ Collect **anonymised sample exports** (contacts, invoices per invoice/per line,
- **The customer as on the document.** An imported invoice or quote's contact snapshot takes the customer's name, address, e-mail, phone, VAT and KvK number from the document's own row in the export (as they were then), on top of the contact as it is now. A line keeps the unit of Moneybird's `aantal` ("2,5 uur" → unit "uur"; "x" is no unit). Only for documents imported from now on: a re-import never changes an imported document.
- **Original PDF is the legal record.** When a PDF ZIP is provided, attach the matching PDF as `original_pdf`; the UI shows it as the primary document for imported invoices. A re-rendered PDF is offered separately and labelled as such.
- **Numbering continues.** After import, the sequence continues after the highest imported number, using the configured number format. A format holds `{year}`, `{seq}` and `{customer}` (the contact's customer number), so Moneybird's default numbering (`{customer}{seq:04d}`: customer 58, sequence 97 is `580097`, one sequence across all customers) continues unchanged. Issuing refuses a contact without a customer number when the format needs one, and a number that already exists; either refusal leaves no gap. If existing numbers cannot be parsed against the format, the user sets the next number manually.
- **The next number by hand** (issue #141; product-owner agent 2026-11-15, `huismus-intern/besluiten.md`). For someone who comes from another package without an import, or whose imported numbers don't fit the format. Instellingen → Facturen en nummering and the start's Facturen step have, under each number format, "Volgnummer van je volgende factuur" / "… offerte": the `{seq}` the next one gets, in the sequence of today (this year's with a yearly reset), filled in with what it is now; empty or unchanged changes nothing. Only the sequence row changes; a number is still given only when issuing (invariant 2). Allowed only while Huismus itself has given no number to a document of that kind (invoices and credit notes together; quotes), in any year, imported ones not counted and a reopened one counted: after that the field is gone and the line says "Het nummer loopt vanzelf door sinds je eerste factuur in Huismus." Before that it may go up or down, but not to or below the highest `{seq}` already in the sequence that fits the format ("Kies 43 of hoger. Een lager nummer bestaat al."), nor onto a number that exists. Checked again under the write lock when saving, in one transaction with the other settings (`huismus/documents/numbering.py`, `set_next_sequence_number`). The import's numbering notice links to this page.
- **Settings from the export.** The web dry run proposes settings from the export itself, for the user to check instead of type: business details from the UBL of the newest invoice (a business moves and changes accounts over the years), the most common payment term, and Moneybird's number format `{customer}{seq:04d}` when every invoice and quote number follows it. The dry run applies the proposal inside its rolled-back transaction, so its report shows the result (numbering continuing); "commit" validates what the user confirmed like the settings page does, and saves it in the import's own transaction, before importing. Where a current setting differs, the dry run shows it. The CLI leaves Settings alone.
- **UBL as a cross-check, and the source of the lines** (decided 2026-11-02, `huismus-intern/besluiten.md`, "Moneybird-import: de UBL als tweede bron voor de regels" and its confirmation). A sent invoice's UBL (`sales_invoices_ubl_archive/<number>.xml`, same export) *fits* when its number, date, subtotal, VAT and total equal the invoice export's, it has as many lines as the line export, and no line has a discount of its own. Then Huismus takes each line's description, quantity, price without VAT and VAT rate from the UBL, and the unit from the line export in the same order; this always applies, also where the Excel lines add up. Where prices included VAT in Moneybird, the Excel line export gives the price with VAT and the UBL without, so this is what puts the right prices on those invoices. The totals stay Moneybird's own from the invoice export and are checked to the cent as before. Compared, `_x000D_` in Excel counts as a line break. A discount on the whole invoice in the UBL (an `AllowanceCharge`, or `AllowanceTotalAmount` not 0) puts the invoice under "Korting", lines at the price before discount, as for a discount in the Excel export. In the dry run, under "UBL-bestanden" in the invoices block (only when the export has UBL files): a UBL that doesn't fit (which fields; the Excel lines stay), a line of a fitting UBL that differs in more than a price including VAT (which fields; the UBL lines are taken), and an invoice already in Huismus whose lines differ from its UBL (it isn't changed; "Toch bewerken" is the way to fix it). These count as points to check and stop nothing. How many invoices had prices including VAT is always said; when nothing is reported, one line says the UBL files match. A UBL that can't be read (broken XML, another root element than `Invoice`, no number) and a UBL without an invoice in the export are named under "Let op". Reading and comparing: `huismus/imports/ubl.py`.
- **Moneybird's own reports as a cross-check** (decided 2026-11-02, `huismus-intern/besluiten.md`, "Moneybird-import: controle tegen Moneybirds omzetrapport" and its addition on the tolerance). Per export, the dry run compares the invoices as Huismus has them after importing (issued, of that export, including ones already there) with two reports in the same export: revenue per contact per month (`RevenueByContact`: the contact's current name, revenue excluding VAT by invoice date) and the year's sales invoice revenue and VAT in the VAT overview (`Tax Overview`, all rates together). Moneybird rounds these reports per line, differently from its invoices, so a difference of at most one cent per invoice line of Huismus in that cell (or that year) counts as equal; where Huismus has no invoice every cent counts. A difference is listed under "Moneybirds eigen rapporten" in the invoices block and counts as a point to check; it never stops the import, since every invoice is already checked to the cent against the invoice export. When everything matches, one line says so; without either report nothing is shown. A report in a layout Huismus doesn't know is named under "Let op" and not compared. Not compared: the debtor report (its meaning can't be derived from the export), the purchase side of the VAT overview, the split per rate and Moneybird's own "Totaal" row. Reading: `huismus/imports/reports.py`; comparing: `huismus/imports/report_check.py`.
Expand Down
4 changes: 3 additions & 1 deletion docs/hulp/beginnen.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Huismus needs for your first invoice:
2. **KOR:** whether you use the small business scheme (KOR), and if so the
text that goes under your invoices. More in [KOR and VAT](kor-en-btw.en.md).
3. **Invoices:** your default payment term and how Huismus numbers your
invoices and quotes. The default is usually fine.
invoices and quotes. The default is usually fine. Coming from another
package? Enter the sequence number that follows your last invoice, so
your numbers carry on.
4. **Logo:** your logo goes at the top of your invoices and quotes. This can
wait.

Expand Down
4 changes: 3 additions & 1 deletion docs/hulp/beginnen.nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ in wat Huismus nodig heeft voor je eerste factuur:
die onder je facturen komt. Meer daarover in
[KOR en btw](kor-en-btw.nl.md).
3. **Facturen:** je standaard betalingstermijn en hoe Huismus je facturen
en offertes nummert. Meestal is de standaard goed.
en offertes nummert. Meestal is de standaard goed. Kom je uit een ander
pakket, vul dan het volgnummer in dat na je laatste factuur komt. Dan
lopen je nummers door.
4. **Logo:** je logo komt bovenaan je facturen en offertes. Dit kan ook
later.

Expand Down
10 changes: 10 additions & 0 deletions docs/hulp/facturen.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ the number the invoice will get. With **Issue for good**:
Then download the PDF with **PDF**, or mail it with **Mail**. See
[Mail](mailen.en.md).

## Carrying on from another package

Coming from another package? Then you want your numbers to carry on. Go to
**Settings → Invoices and numbering** and under **Sequence number of your
next invoice** enter the number that follows your last invoice. If your last
invoice was 2026-0042, enter 43. Quotes work the same way.

You can do this until your first invoice in Huismus. After that the number
counts up by itself, so your series has no gap.

## Payments

The invoice shows its payment status: unpaid, partly paid, paid or overdue.
Expand Down
10 changes: 10 additions & 0 deletions docs/hulp/facturen.nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ bedrag en het nummer dat de factuur krijgt. Met **Definitief uitgeven**:
Daarna download je de pdf met **PDF**, of mail je hem met **Mailen**. Zie
[Mailen](mailen.nl.md).

## Doornummeren na een ander pakket

Kom je uit een ander pakket? Dan wil je dat je nummers doorlopen. Ga naar
**Instellingen → Facturen en nummering** en vul bij **Volgnummer van je
volgende factuur** het getal in dat na je laatste factuur komt. Was je
laatste factuur 2026-0042, dan vul je 43 in. Voor offertes werkt het net zo.

Dit kan tot je eerste factuur in Huismus. Daarna loopt het nummer vanzelf
door, zodat er geen gat in je reeks komt.

## Betalingen

Op de factuur zie je de betaalstatus: onbetaald, deels betaald, betaald of
Expand Down
85 changes: 84 additions & 1 deletion huismus/business/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
from django import forms
from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import UploadedFile
from django.db import transaction
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _

from huismus.core.forms import EuroCentsField
from huismus.documents import mail_texts
from huismus.documents.numbering import format_number
from huismus.documents.numbering import (
NumberingError,
check_next_sequence_number,
format_number,
next_sequence_number,
next_sequence_number_is_fixed,
set_next_sequence_number,
year_if_issued_today,
)

from . import smtp
from .logo import validate_and_sanitize_logo
Expand All @@ -22,6 +31,22 @@
)


# Not settings fields: they set the sequence (documents.numbering). Per
# field the kind of sequence, label and help.
NEXT_NUMBER_FIELDS = {
"next_invoice_number": (
"invoice",
_("Volgnummer van je volgende factuur"),
_("Kom je uit een ander pakket? Vul het volgnummer in dat na je laatste factuur komt."),
),
"next_quote_number": (
"quote",
_("Volgnummer van je volgende offerte"),
_("Kom je uit een ander pakket? Vul het volgnummer in dat na je laatste offerte komt."),
),
}


# Instellingen → Mailen: a subject and a body per kind and language.
MAIL_TEXT_FIELDS = [
(kind, part, language, mail_texts.field_name(kind, part, language))
Expand Down Expand Up @@ -254,3 +279,61 @@ def __init__(self, *args, fields, **kwargs):
for name in list(self.fields):
if name not in fields:
del self.fields[name]
# The next number by hand (issue #141), where the fields name it
# (Facturen en nummering, the start's Facturen step), and only for a
# kind Huismus never gave a number yet (invariant 3).
year = year_if_issued_today(self.instance.number_reset_yearly)
self.fixed_sequences = {}
for name, (kind, label, help_text) in NEXT_NUMBER_FIELDS.items():
if name not in fields:
continue
self.fixed_sequences[kind] = next_sequence_number_is_fixed(kind)
if not self.fixed_sequences[kind]:
self.fields[name] = forms.IntegerField(
label=label,
help_text=help_text,
min_value=1,
# Empty keeps the number as it is.
required=False,
initial=next_sequence_number(kind, year=year),
)

def _next_numbers(self):
"""(kind, format, year, value) per next-number field in the form,
from what the form saves: the number format and yearly reset may
change in the same save."""
reset_yearly = self.cleaned_data.get(
"number_reset_yearly", self.instance.number_reset_yearly
)
year = year_if_issued_today(reset_yearly)
for name, (kind, _label, _help) in NEXT_NUMBER_FIELDS.items():
value = self.cleaned_data.get(name)
template = self.cleaned_data.get(f"{kind}_number_format") or getattr(
self.instance, f"{kind}_number_format"
)
if name in self.fields and value is not None:
yield name, kind, template, year, value

def clean(self):
cleaned = super().clean()
if not self.errors:
for name, kind, template, year, value in self._next_numbers():
# Unchanged is not a change: no checks, so it never stops
# the rest of the form from saving.
if value == next_sequence_number(kind, year=year):
continue
try:
check_next_sequence_number(kind, template, year=year, value=value)
except NumberingError as error:
self.add_error(name, str(error))
return cleaned

def save(self, commit=True):
"""With the next numbers, in one transaction: a refusal (an invoice
issued since the check in clean()) leaves the settings unsaved too.
Raises NumberingError then; the view shows it."""
with transaction.atomic():
instance = super().save(commit)
for _name, kind, template, year, value in self._next_numbers():
set_next_sequence_number(kind, template, year=year, value=value)
return instance
2 changes: 2 additions & 0 deletions huismus/business/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class Topic:
"invoice_number_format",
"quote_number_format",
"number_reset_yearly",
"next_invoice_number",
"next_quote_number",
"default_language",
"currency",
),
Expand Down
12 changes: 8 additions & 4 deletions huismus/business/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from huismus.core import help
from huismus.core.appearance import theme_of
from huismus.documents.numbering import next_numbers_if_issued_today
from huismus.documents.numbering import NumberingError, next_numbers_if_issued_today

from . import smtp, topics
from .forms import MAIL_TEXT_FIELDS, MAIL_TEXT_PARTS, MAIL_TEXT_TITLES, SettingsPartForm
Expand Down Expand Up @@ -48,9 +48,13 @@ def topic_page(request, slug):
if request.method == "POST":
form = SettingsPartForm(request.POST, request.FILES, instance=instance, fields=topic.fields)
if form.is_valid():
form.save()
messages.success(request, _("Instellingen opgeslagen."))
return redirect("business:topic", slug=slug)
try:
form.save()
except NumberingError as error:
form.add_error(None, str(error))
else:
messages.success(request, _("Instellingen opgeslagen."))
return redirect("business:topic", slug=slug)
else:
form = SettingsPartForm(instance=instance, fields=topic.fields)

Expand Down
8 changes: 7 additions & 1 deletion huismus/core/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ class Step:
"Je betalingstermijn en hoe Huismus je facturen en offertes nummert. "
"Meestal is de standaard goed."
),
("default_payment_terms_days", "invoice_number_format", "quote_number_format"),
(
"default_payment_terms_days",
"invoice_number_format",
"quote_number_format",
"next_invoice_number",
"next_quote_number",
),
),
Step(
"logo",
Expand Down
14 changes: 9 additions & 5 deletions huismus/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from huismus.business.models import Settings
from huismus.documents.listing import expiry_hint
from huismus.documents.models import Document
from huismus.documents.numbering import next_numbers_if_issued_today
from huismus.documents.numbering import NumberingError, next_numbers_if_issued_today
from huismus.expenses.inbox_views import new_receipts_context
from huismus.reports.year_overview import compute_year_overview

Expand Down Expand Up @@ -240,10 +240,14 @@ def onboarding(request, slug):
if request.method == "POST":
form = SettingsPartForm(request.POST, request.FILES, instance=instance, fields=step.fields)
if form.is_valid():
form.save()
if index + 1 < len(STEPS):
return redirect("onboarding", STEPS[index + 1].slug)
return redirect("onboarding_done")
try:
form.save()
except NumberingError as error:
form.add_error(None, str(error))
else:
if index + 1 < len(STEPS):
return redirect("onboarding", STEPS[index + 1].slug)
return redirect("onboarding_done")
else:
form = SettingsPartForm(instance=instance, fields=step.fields)

Expand Down
Loading
Loading