feat(parties): the register fills the row, a compact Företagsuppgifter, and the party for agents (v1 expand + MCP) (#2315)
* feat(parties): the register fills the row, Företagsuppgifter shrinks to what only the register knows, and agents get the party Founder feedback on the first Företagsuppgifter (2026-09-05): the org number twice, the VAT number twice, the legal name repeating the heading, and Kontaktuppgifter showing dashes while the block above had the phone, e-mail and address from SCB. - After a fetch the register's contact details land on the supplier and customer rows that point at the party: an empty field, or one still carrying what the register said last time, takes the new value; a value a person typed stays. Shown as "från SCB" on the row (by equality with the registry fact, no source column). - Företagsuppgifter becomes one status line (legal form, active or not, registrations, a Bolagsverket warning when there is one), industry, seat with registration date, and size. Identity stays in the header (org number now formatted) and Kontaktuppgifter. The legal name shows only when it differs from the row's name. - lib/parties/registry-summary.ts reads the coded SCB facts once for the page, the v1 API and MCP; lib/parties/party-api.ts is the agent shape. - v1: party_id on supplier and customer list rows and detail; ?expand=party on detail embeds identity, the register summary, what the ledger has seen and payment identities. MCP: party_id on gnubok_list_suppliers/customers rows and gnubok_get_party (by party, supplier or customer id). Read-only; the parties resource follows. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * chore(parties): regenerate the API skill for the party expansion; tighten the get_party description Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * chore(mcp): gnubok_get_party is search-only, keeping tools/list under its byte budget 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:
co-authored by
Claude Fable 5.1
Jakob Wennberg
parent
f33628f005
commit
0ad83b8d71
@@ -27,6 +27,8 @@ import { getCountryName } from '@/lib/vat/country-codes'
|
||||
import type { Customer, CustomerType, CreateCustomerInput } from '@/types'
|
||||
import { DetailPageSkeleton } from '@/components/common/DetailPageSkeleton'
|
||||
import { PartyFactsSection } from '@/components/parties/PartyFactsSection'
|
||||
import { usePartyDossier } from '@/components/parties/use-party-dossier'
|
||||
import { fromRegistry, addressRowsFromRegistry } from '@/lib/parties/registry-summary'
|
||||
|
||||
const CUSTOMER_TYPE_KEY: Record<CustomerType, string> = {
|
||||
individual: 'type_individual',
|
||||
@@ -60,8 +62,13 @@ export default function CustomerDetailPage({
|
||||
const { toast } = useToast()
|
||||
const { canWrite } = useCanWrite()
|
||||
const t = useTranslations('customer_detail')
|
||||
const tParties = useTranslations('parties')
|
||||
const errorLocale = useLocale() as ErrorLocale
|
||||
const [customer, setCustomer] = useState<CustomerWithRelations | null>(null)
|
||||
const partyId = customer && customer.customer_type !== 'individual' ? ((customer as { party_id?: string | null }).party_id ?? null) : null
|
||||
const party = usePartyDossier(partyId)
|
||||
const registryAddress = party.registry?.contact.address ? addressRowsFromRegistry(party.registry.contact.address) : null
|
||||
const scbNote = (isFromRegistry: boolean) => (isFromRegistry ? <span className="block text-xs text-muted-foreground">{tParties('facts_from_registry')}</span> : null)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [isEditOpen, setIsEditOpen] = useState(false)
|
||||
const [isUpdating, setIsUpdating] = useState(false)
|
||||
@@ -264,8 +271,12 @@ export default function CustomerDetailPage({
|
||||
) : (
|
||||
<DefEmpty />
|
||||
)}
|
||||
{scbNote(fromRegistry(customer.email, party.registry?.contact.email))}
|
||||
</DefRow>
|
||||
<DefRow label={t('def_phone')}>
|
||||
{customer.phone || <DefEmpty />}
|
||||
{scbNote(fromRegistry(customer.phone, party.registry?.contact.phone))}
|
||||
</DefRow>
|
||||
<DefRow label={t('def_phone')}>{customer.phone || <DefEmpty />}</DefRow>
|
||||
<DefRow label={t('def_address')}>
|
||||
{customer.address_line1 || customer.city ? (
|
||||
<div>
|
||||
@@ -274,6 +285,11 @@ export default function CustomerDetailPage({
|
||||
{(customer.postal_code || customer.city) && (
|
||||
<p>{[customer.postal_code, customer.city].filter(Boolean).join(' ')}</p>
|
||||
)}
|
||||
{scbNote(
|
||||
!!registryAddress &&
|
||||
fromRegistry(customer.address_line1, registryAddress.address_line1) &&
|
||||
fromRegistry(customer.city, registryAddress.city),
|
||||
)}
|
||||
{customer.country && <p>{getCountryName(customer.country, errorLocale)}</p>}
|
||||
</div>
|
||||
) : (
|
||||
@@ -282,8 +298,19 @@ export default function CustomerDetailPage({
|
||||
</DefRow>
|
||||
</DetailSection>
|
||||
|
||||
{(customer as { party_id?: string | null }).party_id && customer.customer_type !== 'individual' ? (
|
||||
<PartyFactsSection partyId={(customer as { party_id?: string | null }).party_id as string} canWrite={canWrite} onChanged={() => void fetchCustomer()} />
|
||||
{partyId && party.dossier ? (
|
||||
<PartyFactsSection
|
||||
partyId={partyId}
|
||||
rowName={customer.name}
|
||||
canWrite={canWrite}
|
||||
dossier={party.dossier}
|
||||
registry={party.registry}
|
||||
scbEnabled={party.scbEnabled}
|
||||
onChanged={async () => {
|
||||
await party.reload()
|
||||
await fetchCustomer()
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<DetailSection kicker={t('section_business')}>
|
||||
|
||||
@@ -20,6 +20,9 @@ import { DestructiveConfirmDialog, useDestructiveConfirm } from '@/components/ui
|
||||
import type { Supplier, SupplierType, CreateSupplierInput, SupplierInvoice } from '@/types'
|
||||
import { DetailPageSkeleton } from '@/components/common/DetailPageSkeleton'
|
||||
import { PartyFactsSection } from '@/components/parties/PartyFactsSection'
|
||||
import { usePartyDossier } from '@/components/parties/use-party-dossier'
|
||||
import { fromRegistry, addressRowsFromRegistry } from '@/lib/parties/registry-summary'
|
||||
import { formatOrgNumber } from '@/lib/utils'
|
||||
|
||||
// Supplier invoices carry their own currency; "kr" is only correct for SEK.
|
||||
function amountWithCurrency(amount: number, currency?: string | null): string {
|
||||
@@ -43,7 +46,12 @@ export default function SupplierDetailPage() {
|
||||
const router = useRouter()
|
||||
const { toast } = useToast()
|
||||
const t = useTranslations('supplier_detail')
|
||||
const tParties = useTranslations('parties')
|
||||
const [supplier, setSupplier] = useState<Supplier & { stats?: SupplierStats } | null>(null)
|
||||
const partyId = (supplier as { party_id?: string | null } | null)?.party_id ?? null
|
||||
const party = usePartyDossier(partyId)
|
||||
const registryAddress = party.registry?.contact.address ? addressRowsFromRegistry(party.registry.contact.address) : null
|
||||
const scbNote = (isFromRegistry: boolean) => (isFromRegistry ? <span className="block text-xs text-muted-foreground">{tParties('facts_from_registry')}</span> : null)
|
||||
const [invoices, setInvoices] = useState<SupplierInvoice[]>([])
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [isEditOpen, setIsEditOpen] = useState(false)
|
||||
@@ -197,7 +205,7 @@ export default function SupplierDetailPage() {
|
||||
<h1 className="font-display text-2xl leading-8 tracking-tight">{supplier.name}</h1>
|
||||
<p className="mt-1 text-sm text-muted-foreground">
|
||||
{supplierTypeLabels[supplier.supplier_type]}
|
||||
{supplier.org_number ? ` · ${t('kicker_org', { number: supplier.org_number })}` : ''}
|
||||
{supplier.org_number ? ` · ${t('kicker_org', { number: formatOrgNumber(supplier.org_number) })}` : ''}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -264,13 +272,30 @@ export default function SupplierDetailPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{(supplier as { party_id?: string | null }).party_id ? (
|
||||
<PartyFactsSection partyId={(supplier as { party_id?: string | null }).party_id as string} canWrite={canWrite} onChanged={() => void fetchSupplier()} />
|
||||
{partyId && party.dossier ? (
|
||||
<PartyFactsSection
|
||||
partyId={partyId}
|
||||
rowName={supplier.name}
|
||||
canWrite={canWrite}
|
||||
dossier={party.dossier}
|
||||
registry={party.registry}
|
||||
scbEnabled={party.scbEnabled}
|
||||
onChanged={async () => {
|
||||
await party.reload()
|
||||
await fetchSupplier()
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<DetailSection kicker={t('contact_section_title')}>
|
||||
<DefRow label={t('def_email')}>{supplier.email || <DefEmpty />}</DefRow>
|
||||
<DefRow label={t('def_phone')}>{supplier.phone || <DefEmpty />}</DefRow>
|
||||
<DefRow label={t('def_email')}>
|
||||
{supplier.email || <DefEmpty />}
|
||||
{scbNote(fromRegistry(supplier.email, party.registry?.contact.email))}
|
||||
</DefRow>
|
||||
<DefRow label={t('def_phone')}>
|
||||
{supplier.phone || <DefEmpty />}
|
||||
{scbNote(fromRegistry(supplier.phone, party.registry?.contact.phone))}
|
||||
</DefRow>
|
||||
<DefRow label={t('def_address')}>
|
||||
{supplier.address_line1 || supplier.city ? (
|
||||
<div>
|
||||
@@ -279,12 +304,22 @@ export default function SupplierDetailPage() {
|
||||
{(supplier.postal_code || supplier.city) && (
|
||||
<p>{[supplier.postal_code, supplier.city].filter(Boolean).join(' ')}</p>
|
||||
)}
|
||||
{scbNote(
|
||||
!!registryAddress &&
|
||||
fromRegistry(supplier.address_line1, registryAddress.address_line1) &&
|
||||
fromRegistry(supplier.city, registryAddress.city),
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<DefEmpty />
|
||||
)}
|
||||
</DefRow>
|
||||
{supplier.vat_number && <DefRow label={t('def_vat')}>{supplier.vat_number}</DefRow>}
|
||||
{supplier.vat_number && (
|
||||
<DefRow label={t('def_vat')}>
|
||||
{supplier.vat_number}
|
||||
{scbNote(fromRegistry(supplier.vat_number, party.registry?.vat_number))}
|
||||
</DefRow>
|
||||
)}
|
||||
</DetailSection>
|
||||
|
||||
<DetailSection kicker={t('payment_section_title')}>
|
||||
|
||||
Reference in New Issue
Block a user