fix: llm_response_json already parsed object i split-view modal v2.2.27
This commit is contained in:
parent
bdf76a2a80
commit
14ccd5accf
@ -2120,17 +2120,36 @@ async function openQuickVendorCreate(fileId, filename) {
|
|||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
const ext = data.extraction || {};
|
const ext = data.extraction || {};
|
||||||
|
|
||||||
|
// llm_response_json kan være allerede-parsed objekt (FastAPI/JSONB) eller string
|
||||||
let ai = {};
|
let ai = {};
|
||||||
try { ai = JSON.parse(ext.llm_response_json || '{}'); } catch(e) {}
|
const rawLlm = ext.llm_response_json;
|
||||||
|
if (rawLlm) {
|
||||||
|
if (typeof rawLlm === 'string') {
|
||||||
|
try { ai = JSON.parse(rawLlm); } catch(e) { console.warn('llm_response_json parse error:', e); }
|
||||||
|
} else if (typeof rawLlm === 'object') {
|
||||||
|
ai = rawLlm; // allerede parsed af browser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const name = ext.vendor_name || ai.vendor_name || '';
|
// Vendor navn: prøv extraction tabel først, derefter LLM JSON
|
||||||
const cvr = (ext.vendor_cvr || ai.vendor_cvr || '').replace(/^DK/i, '').trim();
|
const name = ext.vendor_name || ai.vendor_name || ai.supplier_name || '';
|
||||||
const addr = ai.vendor_address || '';
|
// Vendor CVR: strip "DK" prefix
|
||||||
|
const cvr = (ext.vendor_cvr || ai.vendor_cvr || ai.supplier_cvr || '').toString().replace(/^DK/i, '').trim();
|
||||||
|
// Vendor email
|
||||||
|
const email = ai.vendor_email || ai.supplier_email || '';
|
||||||
|
// Vendor adresse: prøv samlet adresse eller separate felter
|
||||||
|
const addr = ai.vendor_address || ai.supplier_address ||
|
||||||
|
[ai.vendor_street || ai.supplier_street,
|
||||||
|
(ai.vendor_postal_code || ai.postal_code || '') + ' ' + (ai.vendor_city || ai.city || '')
|
||||||
|
].filter(Boolean).join(', ') || '';
|
||||||
|
|
||||||
if (name) document.getElementById('qvName').value = name;
|
if (name) document.getElementById('qvName').value = name;
|
||||||
if (cvr) document.getElementById('qvCVR').value = cvr;
|
if (cvr) document.getElementById('qvCVR').value = cvr;
|
||||||
if (addr) {
|
if (email) document.getElementById('qvEmail').value = email;
|
||||||
// Try to split address into street / postal / city
|
|
||||||
|
if (addr && addr.trim()) {
|
||||||
|
// Forsøg at splitte adresse i gade / postnr / by
|
||||||
const parts = addr.split(/,|\n/).map(s => s.trim()).filter(Boolean);
|
const parts = addr.split(/,|\n/).map(s => s.trim()).filter(Boolean);
|
||||||
if (parts.length >= 1) document.getElementById('qvAddress').value = parts[0];
|
if (parts.length >= 1) document.getElementById('qvAddress').value = parts[0];
|
||||||
if (parts.length >= 2) {
|
if (parts.length >= 2) {
|
||||||
@ -2143,6 +2162,21 @@ async function openQuickVendorCreate(fileId, filename) {
|
|||||||
document.getElementById('qvCity').value = postalCity;
|
document.getElementById('qvCity').value = postalCity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Separate felter fra AI hvis ingen samlet adresse
|
||||||
|
if (ai.vendor_street || ai.supplier_street)
|
||||||
|
document.getElementById('qvAddress').value = ai.vendor_street || ai.supplier_street || '';
|
||||||
|
if (ai.vendor_postal_code || ai.postal_code)
|
||||||
|
document.getElementById('qvPostal').value = ai.vendor_postal_code || ai.postal_code || '';
|
||||||
|
if (ai.vendor_city || ai.city)
|
||||||
|
document.getElementById('qvCity').value = ai.vendor_city || ai.city || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vis status hvis ingen relevante data fundet
|
||||||
|
if (!name && !cvr) {
|
||||||
|
const statusEl = document.getElementById('qvStatusAlert');
|
||||||
|
statusEl.className = 'alert alert-warning py-2 small';
|
||||||
|
statusEl.textContent = 'Ingen AI-data fundet for denne fil endnu. Kør fakturaen igennem igen (↺) og prøv derefter.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user