fix: resolve INK2/NE entity_type from companies table fallback (#217)
* fix: resolve INK2/NE entity_type from companies table fallback (#193) The entity_type check in INK2 and NE-bilaga engines read from company_settings where it is nullable, causing "only for aktiebolag" errors when the column is null. Now falls back to companies.entity_type (NOT NULL, always set). Reports page uses useCompany() context instead of /api/settings for tab visibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address Greptile review — surface fallback errors, avoid direct mutation - Surface Supabase errors in entity_type fallback queries instead of silently swallowing them (ink2-engine, ne-engine) - Use spread instead of direct mutation on Supabase result object (settings route) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: use separate variable to avoid const reassignment in settings route Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
bca00cc5bd
commit
73fb97052b
@@ -714,8 +714,19 @@ export async function generateINK2Declaration(
|
||||
.eq('company_id', companyId)
|
||||
.single()
|
||||
|
||||
// Validate entity type
|
||||
if (settings?.entity_type !== 'aktiebolag') {
|
||||
// Resolve entity_type: prefer company_settings, fall back to companies table (NOT NULL, always reliable)
|
||||
let entityType = settings?.entity_type
|
||||
if (!entityType) {
|
||||
const { data: company, error: companyError } = await supabase
|
||||
.from('companies')
|
||||
.select('entity_type')
|
||||
.eq('id', companyId)
|
||||
.single()
|
||||
if (companyError) throw new Error(`Failed to resolve entity type: ${companyError.message}`)
|
||||
entityType = company?.entity_type
|
||||
}
|
||||
|
||||
if (entityType !== 'aktiebolag') {
|
||||
throw new Error('INK2 declaration is only for aktiebolag (limited company)')
|
||||
}
|
||||
|
||||
|
||||
@@ -179,8 +179,19 @@ export async function generateNEDeclaration(
|
||||
.eq('company_id', companyId)
|
||||
.single()
|
||||
|
||||
// Check if it's enskild firma
|
||||
if (settings?.entity_type !== 'enskild_firma') {
|
||||
// Resolve entity_type: prefer company_settings, fall back to companies table (NOT NULL, always reliable)
|
||||
let entityType = settings?.entity_type
|
||||
if (!entityType) {
|
||||
const { data: company, error: companyError } = await supabase
|
||||
.from('companies')
|
||||
.select('entity_type')
|
||||
.eq('id', companyId)
|
||||
.single()
|
||||
if (companyError) throw new Error(`Failed to resolve entity type: ${companyError.message}`)
|
||||
entityType = company?.entity_type
|
||||
}
|
||||
|
||||
if (entityType !== 'enskild_firma') {
|
||||
throw new Error('NE declaration is only for enskild firma (sole proprietorship)')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user