diff --git a/App/app/(portal)/po/import/actions.ts b/App/app/(portal)/po/import/actions.ts index aed7dff..85e7ea3 100644 --- a/App/app/(portal)/po/import/actions.ts +++ b/App/app/(portal)/po/import/actions.ts @@ -88,13 +88,13 @@ export async function importPo( let productId: string | undefined; if (existing) { productId = existing.id; - // Update lastPrice if we have a better price + // Update lastPrice / lastVendor on the product if (item.unitPrice > 0) { await db.product.update({ where: { id: existing.id }, data: { lastPrice: item.unitPrice, - lastVendorId: resolvedVendorId ?? undefined, + ...(resolvedVendorId ? { lastVendorId: resolvedVendorId } : {}), }, }); } @@ -113,6 +113,15 @@ export async function importPo( productId = newProduct.id; } + // Upsert per-vendor price so the item catalogue reflects actual invoice prices + if (productId && resolvedVendorId && item.unitPrice > 0) { + await db.productVendorPrice.upsert({ + where: { productId_vendorId: { productId, vendorId: resolvedVendorId } }, + update: { price: item.unitPrice }, + create: { productId, vendorId: resolvedVendorId, price: item.unitPrice }, + }); + } + resolvedLineItems.push({ ...item, productId }); }