Dokument-Steuertypen im FEDEO MCP ergänzen

Erweitert die Ausgangsbeleg-Tools um explizite Dokument-Steuertypen. Der MCP listet die unterstützten Steuertypen, validiert taxType als Dokumentfeld und setzt bei 13b UStG, 19 UStG und 12.3 UStG die Positions-USt analog zur Oberfläche auf 0 Prozent.
This commit is contained in:
2026-05-11 17:25:10 +02:00
parent ca4f1ba1c0
commit e60188f043

View File

@@ -41,6 +41,23 @@ const allowedOutgoingDocumentTypes = new Set([
"serialInvoices", "serialInvoices",
]) ])
const allowedOutgoingDocumentTaxTypes = new Set([
"Standard",
"13b UStG",
"19 UStG",
"12.3 UStG",
])
const outgoingDocumentTaxableTypes = new Set([
"invoices",
"cancellationInvoices",
"advanceInvoices",
"serialInvoices",
"confirmationOrders",
"quotes",
"costEstimates",
])
const documentTypeArg = (args: Record<string, unknown>, key = "type") => { const documentTypeArg = (args: Record<string, unknown>, key = "type") => {
const type = stringArg(args, key) || "invoices" const type = stringArg(args, key) || "invoices"
if (!allowedOutgoingDocumentTypes.has(type)) { if (!allowedOutgoingDocumentTypes.has(type)) {
@@ -49,6 +66,50 @@ const documentTypeArg = (args: Record<string, unknown>, key = "type") => {
return type return type
} }
const normalizeOutgoingDocumentTaxType = (value: unknown) => {
const taxType = typeof value === "string" && value.trim() ? value.trim() : "Standard"
if (!allowedOutgoingDocumentTaxTypes.has(taxType)) {
throw new Error(`Ungültiger Dokument-Steuertyp: ${taxType}`)
}
return taxType
}
const applyOutgoingDocumentTaxType = (
payload: Record<string, unknown>,
args: Record<string, unknown>,
documentType: string,
existingTaxType?: unknown,
existingRows?: unknown
) => {
if (!outgoingDocumentTaxableTypes.has(documentType)) {
payload.taxType = null
return
}
const taxType = args.taxType !== undefined
? normalizeOutgoingDocumentTaxType(args.taxType)
: existingTaxType
? normalizeOutgoingDocumentTaxType(existingTaxType)
: "Standard"
payload.taxType = taxType
if (["13b UStG", "19 UStG", "12.3 UStG"].includes(taxType)) {
const rows = Array.isArray(payload.rows)
? payload.rows
: Array.isArray(existingRows)
? existingRows
: null
if (!rows) return
payload.rows = rows.map((row: any) => ({
...row,
taxPercent: 0,
}))
}
}
const optionalObjectArg = (args: Record<string, unknown>, key: string) => { const optionalObjectArg = (args: Record<string, unknown>, key: string) => {
const value = args[key] const value = args[key]
return value && typeof value === "object" && !Array.isArray(value) ? value : null return value && typeof value === "object" && !Array.isArray(value) ? value : null
@@ -91,7 +152,6 @@ const buildOutgoingDocumentPayload = (
"description", "description",
"startText", "startText",
"endText", "endText",
"taxType",
] ]
for (const field of stringFields) { for (const field of stringFields) {
@@ -210,6 +270,26 @@ const validateIncomingInvoiceData = (invoice: Record<string, any>) => {
} }
export const accountingTools: McpTool[] = [ export const accountingTools: McpTool[] = [
{
name: "accounting.outgoing_documents.tax_types.list",
title: "Steuertypen für Ausgangsbelege auflisten",
description: "Listet die unterstützten Dokument-Steuertypen für Ausgangsbelege.",
requiredPermissions: ["accounting.outgoing_documents.read"],
inputSchema: {
type: "object",
properties: {},
},
async handler() {
return {
rows: [
{ key: "Standard", label: "Standard", forcesZeroTaxPercent: false },
{ key: "13b UStG", label: "13b UStG", forcesZeroTaxPercent: true },
{ key: "19 UStG", label: "19 UStG Kleinunternehmer", forcesZeroTaxPercent: true },
{ key: "12.3 UStG", label: "12.3 UStG", forcesZeroTaxPercent: true },
],
}
},
},
{ {
name: "accounting.outgoing_documents.list", name: "accounting.outgoing_documents.list",
title: "Ausgangsbelege auflisten", title: "Ausgangsbelege auflisten",
@@ -299,7 +379,11 @@ export const accountingTools: McpTool[] = [
deliveryDateType: { type: "string" }, deliveryDateType: { type: "string" },
paymentDays: { type: "number" }, paymentDays: { type: "number" },
payment_type: { type: "string" }, payment_type: { type: "string" },
taxType: { type: "string" }, taxType: {
type: "string",
enum: ["Standard", "13b UStG", "19 UStG", "12.3 UStG"],
description: "Steuertyp des gesamten Ausgangsdokuments, nicht der einzelne USt-Satz einer Position.",
},
title: { type: "string" }, title: { type: "string" },
description: { type: "string" }, description: { type: "string" },
startText: { type: "string" }, startText: { type: "string" },
@@ -316,6 +400,7 @@ export const accountingTools: McpTool[] = [
assertNoManualDocumentNumber(args) assertNoManualDocumentNumber(args)
const payload = buildOutgoingDocumentPayload(args, context.userId, context.tenantId, true) const payload = buildOutgoingDocumentPayload(args, context.userId, context.tenantId, true)
payload.state = "Entwurf" payload.state = "Entwurf"
applyOutgoingDocumentTaxType(payload, args, String(payload.type))
const [created] = await context.server.db const [created] = await context.server.db
.insert(createddocuments) .insert(createddocuments)
@@ -348,7 +433,11 @@ export const accountingTools: McpTool[] = [
deliveryDateType: { type: "string" }, deliveryDateType: { type: "string" },
paymentDays: { type: "number" }, paymentDays: { type: "number" },
payment_type: { type: "string" }, payment_type: { type: "string" },
taxType: { type: "string" }, taxType: {
type: "string",
enum: ["Standard", "13b UStG", "19 UStG", "12.3 UStG"],
description: "Steuertyp des gesamten Ausgangsdokuments, nicht der einzelne USt-Satz einer Position.",
},
title: { type: "string" }, title: { type: "string" },
description: { type: "string" }, description: { type: "string" },
startText: { type: "string" }, startText: { type: "string" },
@@ -377,6 +466,7 @@ export const accountingTools: McpTool[] = [
const payload = buildOutgoingDocumentPayload(args, context.userId, context.tenantId) const payload = buildOutgoingDocumentPayload(args, context.userId, context.tenantId)
payload.state = "Entwurf" payload.state = "Entwurf"
applyOutgoingDocumentTaxType(payload, args, String(payload.type || existing.type), existing.taxType, existing.rows)
const [updated] = await context.server.db const [updated] = await context.server.db
.update(createddocuments) .update(createddocuments)
@@ -402,7 +492,11 @@ export const accountingTools: McpTool[] = [
deliveryDateEnd: { type: "string" }, deliveryDateEnd: { type: "string" },
paymentDays: { type: "number" }, paymentDays: { type: "number" },
payment_type: { type: "string" }, payment_type: { type: "string" },
taxType: { type: "string" }, taxType: {
type: "string",
enum: ["Standard", "13b UStG", "19 UStG", "12.3 UStG"],
description: "Steuertyp des gesamten Ausgangsdokuments, nicht der einzelne USt-Satz einer Position.",
},
rows: { type: "array" }, rows: { type: "array" },
report: { type: "object" }, report: { type: "object" },
availableInPortal: { type: "boolean" }, availableInPortal: { type: "boolean" },
@@ -427,6 +521,7 @@ export const accountingTools: McpTool[] = [
payload.state = "Gebucht" payload.state = "Gebucht"
payload.documentNumber = result.usedNumber payload.documentNumber = result.usedNumber
applyOutgoingDocumentTaxType(payload, args, existing.type, existing.taxType, existing.rows)
const [updated] = await context.server.db const [updated] = await context.server.db
.update(createddocuments) .update(createddocuments)