feat(parties): one suggestion per legal person, rename on rebuild, review list for SCB matches, model reading for memos (#2274)

* fix(parties): one suggestion per legal person, and a later run may rename an untouched one

Found while walking the queue end to end: two voucher keys naming the same
company ("TIC identity · … The Intelligence Company AB (publ)" and
"Utbetalning leverantörsfaktura …, The Intelligence Company AB (publ)")
became two suggestions and, after Lägg upp, two suppliers; and a suggestion
made before the legal-form anchoring kept its sentence-long name for good,
because apply_party_suggestions never touched a name.

- Suggestions whose display name is anchored on a legal form read out of
  the voucher text (name_anchored) are grouped: one item, both keys as
  aliases, stats summed. Such a name also attaches to an existing party
  called exactly that, legal form included, unless an org number on either
  side says otherwise. Registered company names are unique in Sweden; a
  bank memo never groups or attaches by name.
- Migration 20260904030000: apply_party_suggestions renames a suggestion
  nobody has touched (no decision, no user or registry fact) to an anchored
  name from a later run, and reports 'renamed'. Confirmed and decided
  parties keep their names.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(parties): read legal_name for exact-name attach; say a row is foreign instead of offering SCB

next build: ExistingParty had no legal_name, so the exact-legal-name index
did not compile. The query now selects it.

Queue rows whose voucher text places the company abroad show
"Utländskt bolag (Nederländerna), finns inte i SCB" instead of a search
that cannot succeed; the promote dialog counts them separately from rows
that merely lack an org number; the dossier shows the country.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(parties): carry country on the dossier row

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* feat(parties): one review list for SCB matches, a model reading for bank memos, refresh demoted

- Review list ("Hitta org.nr (n)" in the queue toolbar): every suggestion
  SCB could hold but that lacks an org number is asked for, one row at a
  time under SCB's rate limit; rows with exactly one active match are
  shown ticked and approved in one click, the rest keep the per-row
  picker. Nothing is written before the click.
- Model reading (lib/parties/ai-name.ts, through getAiService): when the
  rules find no legal form or country in the texts, one call reads the
  counterpart out of the bank memo; kept as a 'model' fact, shown as
  "Läst ur verifikatet", used as the query, never as a hard key. On
  demand only, never when the queue builds.
- "Uppdatera förslag" moves from the page header to a ghost button in the
  toolbar: the queue builds itself now.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(parties): review list passes the dialog overflow guard; plural for match counts

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(parties): gate the model reading on the company's AI capability

Same gate as every other model call on company data: the capability the
company holds by plan and can switch off. No call, no fact, no reading
without it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-09-04 17:01:10 +02:00
committed by GitHub
co-authored by Claude Fable 5.1 Jakob Wennberg
parent be0478c219
commit c6ca119e73
18 changed files with 1014 additions and 41 deletions
+24
View File
@@ -8521,6 +8521,30 @@
"picker_foreign": "{name} looks like a foreign company{place}. The SCB register only covers Swedish companies.",
"picker_foreign_hint": "Add the contact with its name and VAT number instead, or search on another name if it is a Swedish company after all.",
"picker_try_instead": "Try instead",
"row_foreign": "Foreign company ({country}), not in the SCB register",
"promote_dialog_foreign": "{foreign} of {count} are foreign companies not in the SCB register; name and VAT number come from the documents.",
"fact_country": "Country",
"review_open": "Find org numbers ({count})",
"review_title": "Find org numbers in the company register",
"review_searching": "Asking SCB, {done} of {total} …",
"review_intro": "SCB was asked with the name in the voucher text. Rows with exactly one match are shown ticked; nothing is chosen until you approve.",
"review_col_book": "In the books",
"review_col_match": "Match in SCB",
"review_others": "Needs a choice or cannot be found",
"review_choose": "Choose",
"review_choose_n": "{count, plural, one {1 match} other {# matches}}",
"review_none": "No match",
"review_foreign": "Foreign company{place}",
"review_ai_read": "Read from the voucher: {name}",
"review_approve": "Approve {count}",
"review_approving": "Saving …",
"review_saved": "Saved",
"review_failed": "Failed",
"review_done_title": "{saved} org numbers saved",
"review_done_description": "The SCB details are fetched when you add them to the register.",
"review_done_failed": "{failed} could not be saved.",
"review_empty": "No rows are missing an org number.",
"picker_ai_read": "Read from the voucher: {name}.",
"fact_trade_name": "Trade name",
"open_dossier": "Open {name}",
"attn_create": "Create suggestions",
+24
View File
@@ -8521,6 +8521,30 @@
"picker_foreign": "{name} ser ut att vara ett utländskt bolag{place}. SCB:s register täcker bara svenska företag.",
"picker_foreign_hint": "Lägg upp kontakten med namn och momsnummer i stället, eller sök på ett annat namn om det ändå är ett svenskt bolag.",
"picker_try_instead": "Sök i stället på",
"row_foreign": "Utländskt bolag ({country}), finns inte i SCB",
"promote_dialog_foreign": "{foreign} av {count} är utländska bolag och finns inte i SCB; namn och momsnummer kommer från underlagen.",
"fact_country": "Land",
"review_open": "Hitta org.nr ({count})",
"review_title": "Hitta org.nr i företagsregistret",
"review_searching": "Frågar SCB, {done} av {total} …",
"review_intro": "SCB frågades med namnet i verifikatet. Rader med exakt en träff visas ikryssade; ingenting väljs utan att du godkänner.",
"review_col_book": "I bokföringen",
"review_col_match": "Träff i SCB",
"review_others": "Behöver ett val eller går inte att hitta",
"review_choose": "Välj",
"review_choose_n": "{count, plural, one {1 träff} other {# träffar}}",
"review_none": "Ingen träff",
"review_foreign": "Utländskt bolag{place}",
"review_ai_read": "Läst ur verifikatet: {name}",
"review_approve": "Godkänn {count}",
"review_approving": "Sparar …",
"review_saved": "Sparat",
"review_failed": "Misslyckades",
"review_done_title": "{saved} org.nr sparade",
"review_done_description": "Uppgifterna från SCB hämtas när du lägger upp dem.",
"review_done_failed": "{failed} gick inte att spara.",
"review_empty": "Inga rader saknar org.nr.",
"picker_ai_read": "Läst ur verifikatet: {name}.",
"fact_trade_name": "Firma",
"open_dossier": "Öppna {name}",
"attn_create": "Skapa förslag",