Skip to content

Commit ce24a6c

Browse files
committed
fix(api): add fallback to is_company query for Odoo 17 v2.1.14
1 parent fc72547 commit ce24a6c

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

api/server.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,26 +648,46 @@ async function fetchOdooSuppliers(
648648
return { success: false, suppliers: [], error: 'Odoo authentication failed - check credentials', debug }
649649
}
650650

651-
// Search for suppliers - try supplier_rank first (Odoo 13+), fall back to supplier field (older)
652-
let supplierIds = await odooXmlRpc(normalizedUrl, 'object', 'execute_kw', [
651+
// Search for suppliers using multiple strategies
652+
let supplierIds: unknown = []
653+
let queryUsed = 'none'
654+
655+
// Strategy 1: supplier_rank > 0 (partners with purchase history in Odoo 13+)
656+
supplierIds = await odooXmlRpc(normalizedUrl, 'object', 'execute_kw', [
653657
database, uid, apiKey,
654658
'res.partner', 'search',
655659
[[['supplier_rank', '>', 0]]],
656660
{ limit: 5000 }
657661
])
662+
queryUsed = 'supplier_rank'
663+
664+
// Strategy 2: If no results, try 'supplier' boolean (older Odoo)
665+
if (!supplierIds || (Array.isArray(supplierIds) && supplierIds.length === 0)) {
666+
try {
667+
supplierIds = await odooXmlRpc(normalizedUrl, 'object', 'execute_kw', [
668+
database, uid, apiKey,
669+
'res.partner', 'search',
670+
[[['supplier', '=', true]]],
671+
{ limit: 5000 }
672+
])
673+
queryUsed = 'supplier_boolean'
674+
} catch {
675+
// Field might not exist, continue
676+
}
677+
}
658678

659-
// If no results with supplier_rank, try the older 'supplier' boolean field
679+
// Strategy 3: If still no results, get all companies (broad search)
660680
if (!supplierIds || (Array.isArray(supplierIds) && supplierIds.length === 0)) {
661681
supplierIds = await odooXmlRpc(normalizedUrl, 'object', 'execute_kw', [
662682
database, uid, apiKey,
663683
'res.partner', 'search',
664-
[[['supplier', '=', true]]],
684+
[[['is_company', '=', true], ['active', '=', true]]],
665685
{ limit: 5000 }
666686
])
667-
debug.supplier_ids_type = 'supplier_boolean'
687+
queryUsed = 'is_company'
668688
}
669689

670-
debug.supplier_ids_type = (debug.supplier_ids_type || 'supplier_rank') + ':' + typeof supplierIds + (Array.isArray(supplierIds) ? '[]' : '')
690+
debug.supplier_ids_type = queryUsed + ':' + typeof supplierIds + (Array.isArray(supplierIds) ? '[]' : '')
671691

672692
// Ensure supplierIds is an array
673693
const ids = Array.isArray(supplierIds) ? supplierIds : []

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.13",
3+
"version": "2.1.14",
44
"description": "Product Lifecycle Management for engineering teams",
55
"main": "dist-electron/main.js",
66
"scripts": {

0 commit comments

Comments
 (0)