KI-AGENT: MCP-Belegpositionen für Angebote normalisieren
This commit is contained in:
@@ -216,6 +216,38 @@ const normalizeEntityId = (value) => {
|
||||
if (value === null || typeof value === "undefined") return null
|
||||
return typeof value === "object" ? (value.id ?? null) : value
|
||||
}
|
||||
const normalizeCreatedDocumentRow = (row) => {
|
||||
let normalizedRow = row
|
||||
|
||||
if (typeof normalizedRow === "string") {
|
||||
try {
|
||||
normalizedRow = JSON.parse(normalizedRow)
|
||||
} catch {
|
||||
normalizedRow = {
|
||||
id: uuidv4(),
|
||||
mode: "text",
|
||||
text: normalizedRow,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!normalizedRow || typeof normalizedRow !== "object" || Array.isArray(normalizedRow)) {
|
||||
normalizedRow = {
|
||||
id: uuidv4(),
|
||||
mode: "text",
|
||||
text: String(row ?? ""),
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...normalizedRow,
|
||||
id: normalizedRow.id || uuidv4(),
|
||||
linkedEntitys: Array.isArray(normalizedRow.linkedEntitys) ? normalizedRow.linkedEntitys : [],
|
||||
}
|
||||
}
|
||||
const normalizeCreatedDocumentRows = (rows) => Array.isArray(rows)
|
||||
? rows.map((row) => normalizeCreatedDocumentRow(row))
|
||||
: []
|
||||
const setupPage = async () => {
|
||||
|
||||
await setupData()
|
||||
@@ -227,6 +259,7 @@ const setupPage = async () => {
|
||||
if (route.params.id) {
|
||||
console.log(route.params)
|
||||
itemInfo.value = await useEntities("createddocuments").selectSingle(route.params.id,'',false)
|
||||
itemInfo.value.rows = normalizeCreatedDocumentRows(itemInfo.value.rows)
|
||||
itemInfo.value.taxType = normalizeTaxTypeValue(itemInfo.value.taxType)
|
||||
await setContactPersonData()
|
||||
checkCompatibilityWithInputPrice()
|
||||
@@ -235,6 +268,8 @@ const setupPage = async () => {
|
||||
|
||||
if (!itemInfo.value.deliveryDateType) itemInfo.value.deliveryDateType = "Lieferdatum"
|
||||
|
||||
itemInfo.value.rows = normalizeCreatedDocumentRows(itemInfo.value.rows)
|
||||
|
||||
if (itemInfo.value.rows.find(i => i.agriculture)) {
|
||||
processDieselPosition()
|
||||
}
|
||||
@@ -284,7 +319,7 @@ const setupPage = async () => {
|
||||
mode: "title",
|
||||
text: `${doc.title} vom ${dayjs(doc.documentDate).format("DD.MM.YYYY")}`
|
||||
},
|
||||
...doc.rows
|
||||
...normalizeCreatedDocumentRows(doc.rows)
|
||||
])
|
||||
|
||||
})
|
||||
@@ -305,7 +340,7 @@ const setupPage = async () => {
|
||||
|
||||
console.log(linkedDocuments)
|
||||
|
||||
if (linkedDocuments.find(i => i.rows.find(x => x.agriculture.dieselUsage))) {
|
||||
if (linkedDocuments.find(i => normalizeCreatedDocumentRows(i.rows).find(x => x.agriculture?.dieselUsage))) {
|
||||
console.log("has diesel")
|
||||
|
||||
//Remove Existing Total Diesel Pos
|
||||
@@ -347,7 +382,7 @@ const setupPage = async () => {
|
||||
text: linkedDocument.title,
|
||||
})
|
||||
|
||||
itemInfo.value.rows.push(...linkedDocument.rows)
|
||||
itemInfo.value.rows.push(...normalizeCreatedDocumentRows(linkedDocument.rows))
|
||||
}
|
||||
|
||||
for await (const doc of linkedDocuments.filter(i => quoteLikeDocumentTypes.includes(i.type))) {
|
||||
@@ -359,7 +394,7 @@ const setupPage = async () => {
|
||||
text: linkedDocument.title,
|
||||
})
|
||||
|
||||
itemInfo.value.rows.push(...linkedDocument.rows)
|
||||
itemInfo.value.rows.push(...normalizeCreatedDocumentRows(linkedDocument.rows))
|
||||
}
|
||||
|
||||
itemInfo.value.rows.push({
|
||||
@@ -428,7 +463,7 @@ const setupPage = async () => {
|
||||
if (optionsToImport.title) itemInfo.value.title = linkedDocument.title
|
||||
if (optionsToImport.description) itemInfo.value.description = linkedDocument.description
|
||||
if (optionsToImport.startText) itemInfo.value.startText = linkedDocument.startText
|
||||
if (optionsToImport.rows) itemInfo.value.rows = linkedDocument.rows
|
||||
if (optionsToImport.rows) itemInfo.value.rows = normalizeCreatedDocumentRows(linkedDocument.rows)
|
||||
if (optionsToImport.endText) itemInfo.value.endText = linkedDocument.endText
|
||||
|
||||
} else {
|
||||
@@ -454,7 +489,7 @@ const setupPage = async () => {
|
||||
itemInfo.value.title = linkedDocument.title
|
||||
itemInfo.value.description = linkedDocument.description
|
||||
itemInfo.value.startText = linkedDocument.startText
|
||||
itemInfo.value.rows = linkedDocument.rows
|
||||
itemInfo.value.rows = normalizeCreatedDocumentRows(linkedDocument.rows)
|
||||
itemInfo.value.endText = linkedDocument.endText
|
||||
}
|
||||
|
||||
@@ -1628,6 +1663,8 @@ const getTextTemplateByType = (type, pos) => {
|
||||
}
|
||||
|
||||
const checkCompatibilityWithInputPrice = () => {
|
||||
itemInfo.value.rows = normalizeCreatedDocumentRows(itemInfo.value.rows)
|
||||
|
||||
itemInfo.value.rows.forEach(row => {
|
||||
if (!row.inputPrice) {
|
||||
row.inputPrice = row.price
|
||||
|
||||
Reference in New Issue
Block a user