Skip to content

Commit 760d655

Browse files
committed
feat(api): add debug info to Odoo sync responses v2.1.12
1 parent bcb87d8 commit 760d655

File tree

3 files changed

+65
-21
lines changed

3 files changed

+65
-21
lines changed

api/server.ts

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -602,48 +602,72 @@ async function testOdooConnection(
602602
}
603603
}
604604

605+
interface OdooFetchResult {
606+
success: boolean
607+
suppliers: OdooSupplier[]
608+
error?: string
609+
debug: {
610+
url: string
611+
auth_uid: unknown
612+
supplier_ids_count: number
613+
supplier_ids_type: string
614+
suppliers_result_type: string
615+
suppliers_count: number
616+
timing_ms: number
617+
}
618+
}
619+
605620
async function fetchOdooSuppliers(
606621
url: string,
607622
database: string,
608623
username: string,
609624
apiKey: string
610-
): Promise<{ success: boolean; suppliers: OdooSupplier[]; error?: string }> {
625+
): Promise<OdooFetchResult> {
611626
const normalizedUrl = normalizeOdooUrl(url)
627+
const startTime = Date.now()
628+
const debug: OdooFetchResult['debug'] = {
629+
url: normalizedUrl,
630+
auth_uid: null,
631+
supplier_ids_count: 0,
632+
supplier_ids_type: 'unknown',
633+
suppliers_result_type: 'unknown',
634+
suppliers_count: 0,
635+
timing_ms: 0
636+
}
637+
612638
try {
613-
console.log('[Odoo] Authenticating to:', normalizedUrl)
614-
615639
// Authenticate first
616640
const uid = await odooXmlRpc(normalizedUrl, 'common', 'authenticate', [
617641
database, username, apiKey, {}
618642
])
619643

620-
console.log('[Odoo] Auth result uid:', uid)
644+
debug.auth_uid = uid
621645

622646
if (!uid || uid === false) {
623-
return { success: false, suppliers: [], error: 'Authentication failed' }
647+
debug.timing_ms = Date.now() - startTime
648+
return { success: false, suppliers: [], error: 'Odoo authentication failed - check credentials', debug }
624649
}
625650

626651
// Search for suppliers (partners with supplier_rank > 0)
627-
console.log('[Odoo] Searching for suppliers...')
628652
const supplierIds = await odooXmlRpc(normalizedUrl, 'object', 'execute_kw', [
629653
database, uid, apiKey,
630654
'res.partner', 'search',
631655
[[['supplier_rank', '>', 0]]],
632-
{ limit: 5000 } // Reasonable limit
656+
{ limit: 5000 }
633657
])
634658

635-
console.log('[Odoo] Supplier IDs result:', typeof supplierIds, Array.isArray(supplierIds) ? supplierIds.length : supplierIds)
659+
debug.supplier_ids_type = typeof supplierIds + (Array.isArray(supplierIds) ? '[]' : '')
636660

637661
// Ensure supplierIds is an array
638662
const ids = Array.isArray(supplierIds) ? supplierIds : []
663+
debug.supplier_ids_count = ids.length
639664

640665
if (ids.length === 0) {
641-
console.log('[Odoo] No suppliers found')
642-
return { success: true, suppliers: [] }
666+
debug.timing_ms = Date.now() - startTime
667+
return { success: true, suppliers: [], debug }
643668
}
644669

645670
// Read supplier details
646-
console.log('[Odoo] Reading', ids.length, 'supplier details...')
647671
const suppliersResult = await odooXmlRpc(normalizedUrl, 'object', 'execute_kw', [
648672
database, uid, apiKey,
649673
'res.partner', 'read',
@@ -653,15 +677,22 @@ async function fetchOdooSuppliers(
653677
]]
654678
])
655679

656-
console.log('[Odoo] Suppliers result type:', typeof suppliersResult, Array.isArray(suppliersResult) ? suppliersResult.length : 'not array')
680+
debug.suppliers_result_type = typeof suppliersResult + (Array.isArray(suppliersResult) ? '[]' : '')
657681

658682
// Ensure result is an array
659683
const suppliers = Array.isArray(suppliersResult) ? suppliersResult as OdooSupplier[] : []
684+
debug.suppliers_count = suppliers.length
685+
debug.timing_ms = Date.now() - startTime
660686

661-
return { success: true, suppliers }
687+
return { success: true, suppliers, debug }
662688
} catch (err) {
663-
console.error('[Odoo] Error:', err)
664-
return { success: false, suppliers: [], error: String(err) }
689+
debug.timing_ms = Date.now() - startTime
690+
return {
691+
success: false,
692+
suppliers: [],
693+
error: `Odoo API error: ${err instanceof Error ? err.message : String(err)}`,
694+
debug
695+
}
665696
}
666697
}
667698

@@ -3498,12 +3529,15 @@ export async function buildServer(): Promise<FastifyInstance> {
34983529
})
34993530
.eq('id', integration.id)
35003531

3501-
return reply.code(400).send({ error: 'Sync failed', message: odooSuppliers.error })
3532+
return reply.code(400).send({
3533+
error: 'Sync failed',
3534+
message: odooSuppliers.error,
3535+
debug: odooSuppliers.debug // Include debug info in error response
3536+
})
35023537
}
35033538

35043539
// Safety check - ensure suppliers is an array
35053540
const suppliers = Array.isArray(odooSuppliers.suppliers) ? odooSuppliers.suppliers : []
3506-
console.log(`[Odoo Sync] Found ${suppliers.length} suppliers from Odoo`)
35073541

35083542
if (suppliers.length === 0) {
35093543
return {
@@ -3512,7 +3546,8 @@ export async function buildServer(): Promise<FastifyInstance> {
35123546
updated: 0,
35133547
skipped: 0,
35143548
errors: 0,
3515-
message: 'No suppliers found in Odoo with supplier_rank > 0'
3549+
message: 'No suppliers found in Odoo with supplier_rank > 0',
3550+
debug: odooSuppliers.debug
35163551
}
35173552
}
35183553

@@ -3607,7 +3642,8 @@ export async function buildServer(): Promise<FastifyInstance> {
36073642
updated,
36083643
skipped,
36093644
errors,
3610-
message: `Synced ${created + updated} suppliers from Odoo`
3645+
message: `Synced ${created + updated} suppliers from Odoo`,
3646+
debug: odooSuppliers.debug
36113647
}
36123648
})
36133649

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blue-plm",
3-
"version": "2.1.11",
3+
"version": "2.1.12",
44
"description": "Product Lifecycle Management for engineering teams",
55
"main": "dist-electron/main.js",
66
"scripts": {

src/components/sidebar/SuppliersView.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ export function SuppliersView() {
100100
})
101101

102102
const data = await response.json()
103+
104+
// Log debug info to console for troubleshooting
105+
console.log('[Odoo Sync] Response:', response.status, data)
106+
if (data.debug) {
107+
console.log('[Odoo Sync] Debug info:', data.debug)
108+
}
103109

104110
if (response.ok) {
105111
addToast('success', `Synced ${data.created} new, ${data.updated} updated suppliers`)
@@ -109,7 +115,9 @@ export function SuppliersView() {
109115
addToast('warning', 'Odoo not configured. Go to Settings > Google Drive & ERP to set it up.')
110116
setActiveView('settings')
111117
} else {
112-
addToast('error', data.message || 'Sync failed')
118+
// Show more detailed error
119+
const debugInfo = data.debug ? ` (auth: ${data.debug.auth_uid ? 'ok' : 'failed'}, found: ${data.debug.supplier_ids_count})` : ''
120+
addToast('error', (data.message || 'Sync failed') + debugInfo)
113121
}
114122
}
115123
} catch (err) {

0 commit comments

Comments
 (0)