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
+108
View File
@@ -71,6 +71,7 @@
"invoices": "Invoices",
"sales_orders": "Orders",
"customers": "Customers",
"articles": "Articles",
"products": "Products",
"inventory": "Inventory",
"supplier_invoices": "Supplier invoices",
@@ -2057,6 +2058,13 @@
},
"invoice_editor": {
"back": "Back",
"article_label": "Article",
"article_placeholder": "Select article",
"article_free_text": "Custom line (free text)",
"save_as_article": "Save as article",
"save_article_need_description": "Enter a description before saving as an article",
"article_saved_title": "Article saved",
"save_article_failed": "Could not save the article",
"title_invoice": "New invoice",
"title_proforma": "New proforma invoice",
"title_delivery_note": "New delivery note",
@@ -3460,6 +3468,106 @@
"copy_banner_unknown_label": "(unknown number)",
"copy_banner_body": "A new, standalone voucher will be created with its own voucher series and number. This is NOT a correction or reversal of the original — use \"Skapa ändringsverifikation\" if you want to correct the source voucher."
},
"articles": {
"title": "Articles",
"new_article": "New article",
"add_article": "Add article",
"viewer_disabled_tooltip": "You only have viewer access in this company",
"load_failed_title": "Could not load articles",
"load_failed_description": "Check your connection and try again.",
"create_failed_title": "Could not create article",
"created_title": "Article created",
"created_description": "{name} has been added",
"search_placeholder": "Search articles",
"no_search_results_title": "No matches",
"no_search_results_description": "No articles match \"{term}\".",
"empty_title": "No articles yet",
"empty_description": "Add articles for goods and services to fill in invoice rows quickly.",
"empty_action": "Add article",
"type_vara": "Goods",
"type_tjanst": "Service",
"status_active": "Active",
"status_inactive": "Inactive",
"per_unit": "per {unit}",
"vat_label_value": "{rate} % VAT",
"col_number": "Article number",
"col_name": "Name",
"col_type": "Type",
"col_unit": "Unit",
"col_price": "Price excl. VAT",
"col_vat": "VAT",
"col_status": "Status"
},
"article_detail": {
"back": "Back to articles",
"edit": "Edit",
"deactivate": "Deactivate",
"edit_dialog_title": "Edit article",
"viewer_disabled_tooltip": "You only have viewer access in this company",
"type_vara": "Goods",
"type_tjanst": "Service",
"status_active": "Active",
"status_inactive": "Inactive",
"section_pricing": "Pricing",
"section_accounting": "Accounting",
"section_details": "Details",
"section_notes": "Notes",
"label_price": "Price excl. VAT",
"label_vat": "VAT",
"label_unit": "Unit",
"label_cost_price": "Cost price",
"label_revenue_account": "Revenue account",
"revenue_account_auto": "Derived automatically",
"label_housework": "ROT/RUT",
"label_name_en": "Name (English)",
"label_ean": "EAN/barcode",
"no_details": "No additional details",
"load_failed_title": "Could not load article",
"load_failed_description": "Article not found.",
"updated_title": "Article updated",
"update_failed_title": "Could not update article",
"retry": "Please try again.",
"deactivate_confirm_title": "Deactivate {name}",
"deactivate_confirm_description": "The article is hidden from lists and invoice pickers but its history is kept. You can reactivate it later.",
"deactivate_confirm_label": "Deactivate",
"deactivated_title": "Article deactivated",
"deactivate_failed_title": "Could not deactivate article"
},
"form_article": {
"type_label": "Type *",
"type_placeholder": "Choose type",
"type_vara": "Goods",
"type_tjanst": "Service",
"name_label": "Name *",
"name_placeholder": "E.g. Consulting hour",
"name_required": "Name is required",
"name_en_label": "Name (English)",
"name_en_placeholder": "E.g. Consulting hour",
"name_en_hint": "Used on English-language invoices.",
"unit_label": "Unit",
"price_label": "Price excl. VAT *",
"price_required": "Enter a price",
"vat_rate_label": "VAT",
"advanced_section": "Advanced",
"revenue_account_label": "Revenue account",
"revenue_account_placeholder": "e.g. 3041",
"revenue_account_hint": "Leave empty to derive the account automatically from the VAT rate.",
"cost_price_label": "Cost price",
"cost_price_hint": "Margin display only – never posted.",
"ean_label": "EAN/barcode",
"ean_placeholder": "e.g. 7350000000000",
"housework_label": "ROT/RUT",
"housework_placeholder": "Choose work type",
"housework_none": "None",
"housework_rot": "ROT",
"housework_rut": "RUT",
"housework_hint": "Pre-fills the work type on the invoice row for housework.",
"notes_label": "Notes",
"notes_placeholder": "Internal notes about the article...",
"submit_save": "Save article",
"submit_saving": "Saving...",
"viewer_disabled_tooltip": "You only have viewer access in this company"
},
"customers": {
"title": "Customers",
"new_customer": "New customer",