fix(mcp): Artikel- und Leistungsbeschreibung in Ausgangsbelegpositionen übernehmen

Wie im Belegeditor werden bei mode=normal/service fehlende Beschreibung, Name, Einheit, Preis, USt-Satz und Kostenstelle aus Artikel bzw. Leistung übernommen. descriptionText wird als description gespeichert, weil der Editor nur description liest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 08:23:33 +01:00
parent 9e003125c2
commit c10bfac23b
4 changed files with 99 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
import assert from "node:assert/strict"
import test from "node:test"
import { getTableName } from "drizzle-orm"
import { applyOutgoingRowCatalogDefaults } from "../src/mcp/outgoingRowDefaults"
const catalog: Record<string, any[]> = {
products: [{ id: 1, name: "Kabel", description: "NYM-J 3x1,5", unit: 2, selling_price: 1.25, tax_percentage: 19 }],
services: [{ id: 5, name: "Montage", description: "Montage vor Ort", unit: 3, sellingPrice: 50, sellingPriceComposed: { total: 55 }, taxPercentage: 7, costcentre: "cc" }],
}
const context: any = { tenantId: 7, server: { db: { select: () => ({ from: (table: any) => ({ where: async () => catalog[getTableName(table)] }) }) } } }
test("selected products and services bring their description and editor defaults", async () => {
const rows: any = await applyOutgoingRowCatalogDefaults(context, [
{ mode: "normal", product: 1, quantity: 3 },
JSON.stringify({ mode: "service", service: 5 }),
{ mode: "free", text: "Frei", descriptionText: "Alt" },
])
assert.deepEqual(rows[0], { mode: "normal", product: 1, quantity: 3, text: "Kabel", description: "NYM-J 3x1,5", unit: 2, inputPrice: 1.25, price: 1.25, taxPercent: 19 })
assert.equal(rows[1].description, "Montage vor Ort")
assert.equal(rows[1].price, 55)
assert.equal(rows[1].costCentre, "cc")
assert.equal(rows[2].description, "Alt")
})
test("caller values win and unknown catalog entries are rejected", async () => {
const [row]: any = await applyOutgoingRowCatalogDefaults(context, [{ mode: "normal", product: 1, description: "Eigene", price: 2, taxPercent: 7 }])
assert.equal(row.description, "Eigene")
assert.equal(row.price, 2)
assert.equal(row.taxPercent, 7)
await assert.rejects(applyOutgoingRowCatalogDefaults(context, [{ mode: "normal", product: 9 }]), /Artikel 9 nicht gefunden/)
})