Support #12260
openSupport #12257: Vendor Management flow Issues
Vendor ID vs. Database ID Mismatch (Empty Tables & Crashed Pages)
100%
Description
Code Location: vendorInvoiceController.js:L2951, L4697
What is happening in code: When vendors are created, they get a human-readable custom code like "vn_100234". Invoices, batches, and purchase orders save vendor_id = "vn_100234". However, API endpoints like getAllVendorInvoices and getVendorProductsAndBatches query the database using the 24-character MongoDB internal ID ("65a8e2...").
Real-Life Example:
You open the Vendor Details page for "Green Leaf Nursery Ltd" (vn_100234).
You click the Invoice History or Batches tab.
The frontend asks the backend: "Give me all invoices for vendor 65a8e2f910b2...".
The database searches for invoices with vendor_id: "65a8e2f910b2...", but finds zero matches because all invoices have vendor_id: "vn_100234".
Business Impact: The screen shows "No Invoices Found" or crashes with a CastError, even though you have 20 invoices on file for that vendor.
Simple Fix: Standardize all lookups to resolve the vendor document first:
const vendorDoc = mongoose.isValidObjectId(vendorId)
? await Vendor.findById(vendorId).select("vendor_id")
: await Vendor.findOne({ vendor_id: vendorId }).select("vendor_id");
const resolvedId = vendorDoc ? vendorDoc.vendor_id : vendorId;
Subtasks
Related issues
Updated by Divya Inapakurthi 5 days ago
- Due date set to 11/23/2026
- Status changed from New to Resolved
- Assignee set to Divya Inapakurthi