feat(invoicing): artikelregister (product/article catalog) with per-article revenue account (#703)

* feat(invoicing): artikelregister (product/article catalog) with per-article revenue account

Add a lean, non-inventory article catalog (artikelregister) so users can define
reusable invoice-line presets (name, unit, price excl VAT, VAT rate) with an
optional per-article BAS class-3 revenue-account override.

- DB: articles table (RLS via user_company_ids(), audit + updated_at triggers,
  unique-per-company article_number), generate_article_number RPC (atomic +
  idempotent), company_settings counter, nullable invoice_items.revenue_account
  + article_id, pending_operations CHECK expansion.
- Engine: generatePerRateLines groups revenue by (vat_rate, account) —
  byte-identical with no override, balance-safe when split (last account absorbs
  the rounding remainder), reverse_charge/export still force 3308/3305.
- API: /api/articles CRUD (soft-deactivate); override validated against
  chart_of_accounts (active class-3) and frozen onto invoice lines at create.
- Propagation: override carried through send/mark-sent/credit/convert/cash and
  the staged commit paths (recurring deferred — documented inline).
- MCP: gnubok_list/create/update_article (staged, scoped, risk-tiered).
- UI: articles register (list/detail/form) + nav + bilingual i18n + invoice-line
  article picker & "Spara som artikel" quick-create.
- Tests: engine regression, route, and pg-real (RPC/RLS/triggers).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(mcp): strip ILIKE _ wildcard from gnubok_list_articles search

Underscore is a single-character ILIKE wildcard; stripping it (alongside the
existing %,()\* set) keeps a stray char in the article search from matching
every row. Read-only + RLS-scoped, so no security impact — addresses PR #703
reviewer + compliance-swarm CC6.3 notes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-06-09 21:05:37 +02:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 07ecb98389
commit c0b006fcc1
32 changed files with 3047 additions and 16 deletions
+34
View File
@@ -579,6 +579,11 @@ const INVOICE: Record<string, StructuredErrorEntry> = {
message_sv: 'Momssatsen är inte tillåten för denna kundtyp.',
message_en: 'The VAT rate is not allowed for this customer type.',
},
INVOICE_CREATE_REVENUE_ACCOUNT_INVALID: {
httpStatus: 400,
message_sv: 'Ett angivet försäljningskonto finns inte eller är inte ett aktivt intäktskonto (klass 3).',
message_en: 'A supplied revenue account does not exist or is not an active class-3 income account.',
},
INVOICE_CREATE_ROT_RUT_VALIDATION: {
httpStatus: 400,
message_sv: 'ROT/RUT-avdraget kunde inte valideras. Kontrollera personnummer och fastighetsbeteckning.',
@@ -1424,6 +1429,34 @@ const CUSTOMER: Record<string, StructuredErrorEntry> = {
},
}
const ARTICLE: Record<string, StructuredErrorEntry> = {
ARTICLE_NOT_FOUND: {
httpStatus: 404,
message_sv: 'Artikeln kunde inte hittas.',
message_en: 'Article not found.',
},
ARTICLE_DUPLICATE_NUMBER: {
httpStatus: 409,
message_sv: 'En artikel med samma artikelnummer finns redan.',
message_en: 'An article with that article number already exists.',
},
ARTICLE_CREATE_FAILED: {
httpStatus: 500,
message_sv: 'Artikeln kunde inte skapas.',
message_en: 'Failed to create article.',
},
ARTICLE_UPDATE_FAILED: {
httpStatus: 500,
message_sv: 'Artikeln kunde inte uppdateras.',
message_en: 'Failed to update article.',
},
ARTICLE_REVENUE_ACCOUNT_INVALID: {
httpStatus: 400,
message_sv: 'Försäljningskontot finns inte eller är inte ett aktivt intäktskonto (klass 3).',
message_en: 'The revenue account does not exist or is not an active class-3 income account.',
},
}
const SUPPLIER: Record<string, StructuredErrorEntry> = {
SUPPLIER_NOT_FOUND: {
httpStatus: 404,
@@ -2271,6 +2304,7 @@ const REGISTRY: Record<string, StructuredErrorEntry> = {
...PROVIDER_MIGRATION,
...DOCUMENT,
...CUSTOMER,
...ARTICLE,
...SUPPLIER,
...SUPPLIER_INVOICE_WAVE4,
...SALARY,