feat(L4-L5): KI-Steuerung + XRechnung-Format-Layer (EN16931/CII)
Check Cross-Plugin Imports / check (push) Has been cancelled

L5 Format-Layer (User-Klaerung: Verkaufsmodul spaeter, Format JETZT):
- einvoice.py: EN16931/XRechnung CII-XML-Generator (ElementTree, XML-Escaping gratis), Pflichtfeld-Validierung mit BT/BG-Codes, Decimal-kommerzielles Rounding, Header-Tax-Breakdown pro VAT-Satz, Profile en16931|xrechnung (XRechnung 3.0)
- POST /einvoice/render (inline->XML), /einvoice/validate (422 mit BT-Fehlliste), /einvoice/render-for (Contract-Resolver einvoice_data() — Andockpunkt Verkaufsmodul, 404 no_data_source ohne Beitrag)

L4 KI-Steuerung:
- POST /documents/suggest: Natuerliche Sprache -> Block-Komposition via zentralem llm_complete (Cost-Tracking, Tenant-Budget), Registry-Sanitizing (ungueltige KI-Bloecke gefiltert, IDs serverseitig), Code-Fence-Stripping, 502 ai_unavailable/invalid_ai_response
- Frontend: KI-Vorschlag-Panel im PrintTemplateEditor (Sparkles-Icon, Prompt-Textarea, Bloecke werden angehaengt), i18n de/en

TDD: Rot 25 failed -> Gruen 25/25 (Validierung, XML-Struktur/Escaping/Summen, Contract-Mocks, API 200/422/403/404, Suggest Mock-LLM/Fence/502). tsc exit 0, Build OK, ruff clean. Doku: api-documentation.md, plugin-development-guide.md (einvoice_data-Contract), PROGRESS.md
This commit is contained in:
Agent Zero
2026-08-29 18:05:55 +02:00
parent b311ab7aa1
commit 559bba69a4
11 changed files with 1363 additions and 1 deletions
@@ -162,3 +162,78 @@ class DocumentAssetResponse(BaseModel):
size_bytes: int
data_url: str | None = None
created_at: datetime | None = None
# ─── E-Invoice (EN16931/XRechnung, Phase L5) ────────────────────────────────
class EInvoiceAddress(BaseModel):
"""Postal address (BT-50..53 seller, BT-65..68 buyer)."""
street: str | None = None
postal_code: str | None = None
city: str | None = None
country: str | None = None
class EInvoiceLineItem(BaseModel):
"""Invoice line (BG-25). ``line_net_amount`` wins over qty*price."""
name: str = ""
quantity: float = 1.0
unit: str = "HUR"
unit_net_price: float = 0.0
vat_rate: float = 0.0
line_net_amount: float | None = None
class EInvoiceRenderRequest(BaseModel):
"""Inline invoice data — field-level semantics validated by
``einvoice.validate_einvoice_data`` (BT/BG business terms, 422)."""
invoice_number: str = ""
issue_date: str = ""
type_code: str = "380"
currency: str = "EUR"
due_date: str | None = None
delivery_date: str | None = None
buyer_name: str = ""
buyer_reference: str | None = None
buyer_address: EInvoiceAddress | None = None
seller_name: str = ""
seller_vat_id: str | None = None
seller_tax_id: str | None = None
seller_address: EInvoiceAddress | None = None
payment_means_code: str | None = None
payment_terms_text: str | None = None
note: str | None = None
line_items: list[EInvoiceLineItem] = Field(default_factory=list)
profile: str = Field("en16931", pattern="^(en16931|xrechnung)$")
class EInvoiceRenderForRequest(BaseModel):
"""Render an e-invoice for an entity via the ``einvoice_data()``
contract hook (future sales module docking point)."""
entity_type: str = Field(..., min_length=1, max_length=100)
entity_id: str = Field(..., min_length=1)
class EInvoiceValidationResponse(BaseModel):
valid: bool
missing: list[str] = Field(default_factory=list)
# ─── AI block suggestion (Phase L4) ──────────────────────────────────────────
class DocumentSuggestRequest(BaseModel):
"""Natural-language block composition request for the template editor."""
prompt: str = Field(..., min_length=1, max_length=2000)
entity_type: str | None = Field(None, max_length=100)
class DocumentSuggestResponse(BaseModel):
blocks: list[dict]
notes: str = ""