Files
leocrm/app/models/address.py
T
Agent Zero 0eb6d7621e
Check Cross-Plugin Imports / check (push) Has been cancelled
fix(security): 16 mittlere Probleme behoben (P18-P33)
P18: require_permission zu forgejo_error_reporter und ai_ui_control routes hinzugefügt
P19: Cross-Tenant Permission-Cache-Invalidierung bei Rollenänderungen
P20: Session/Permission-Cache-Invalidierung bei Gruppen-Änderungen
P21: ENTITY_MODELS Registry um fehlende Plugin-Modelle erweitert
P22: Entity-Links prüfen verknüpfte Entity-Permissions
P23: authStore persist Middleware entfernt (kein localStorage mehr)
P24: 5xx Retry nur noch für GET-Requests
P25: KI-Kommentar in address.py (bekannte Inkonsistenz)
P26: DeletionLog in EntityHistory gemerged (action=delete)
P27: KI-Kommentar in entity_policy.py (ABAC nicht aktiv genutzt)
P28: db.commit() aus bulk_permission_service entfernt
P29: CSV-Export in export_service.py ausgelagert
P30: plugins.py Business-Logik in plugin_install_service.py ausgelagert
P31: KI-Kommentar in session.py (Dual-System dokumentiert)
P32: Migration 0115: crm_platform_admin Role droppen
P33: Cross-Plugin Imports über contracts.py behoben (10 Violations → 0)
2026-08-06 13:23:58 +02:00

58 lines
2.3 KiB
Python

"""Address model — polymorphic addresses for companies and contacts.
⚠️ Address-Tabelle wird für Bank-Accounts genutzt. Contacts nutzen inline Address-Felder.
Diese Inkonsistenz ist bekannt und wird bei Gelegenheit vereinheitlicht.
"""
from __future__ import annotations
import uuid
from sqlalchemy import Boolean, Index, String, UniqueConstraint
from sqlalchemy.dialects.postgresql import UUID as PGUUID
from sqlalchemy.orm import Mapped, mapped_column
from app.core.db import Base, TenantMixin
from app.models.owned_mixin import OwnedMixin
class Address(Base, TenantMixin, OwnedMixin):
"""Polymorphic address entity — multiple addresses per contact.
entity_type: 'contact'
entity_id: FK to companies.id or contacts.id
address_type: billing, shipping, headquarters, branch, private, other
is_default: one default address per (entity_type, entity_id, address_type)
"""
__tablename__ = "addresses"
__table_args__ = (
UniqueConstraint(
"tenant_id",
"entity_type",
"entity_id",
"address_type",
"is_default",
name="uq_address_default_per_type",
),
Index("ix_addresses_tenant_entity", "tenant_id", "entity_type", "entity_id"),
Index("ix_addresses_tenant_type", "tenant_id", "address_type"),
)
id: Mapped[uuid.UUID] = mapped_column(
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
)
entity_type: Mapped[str] = mapped_column(String(50), nullable=False)
entity_id: Mapped[uuid.UUID] = mapped_column(
PGUUID(as_uuid=True), nullable=False, index=True
)
label: Mapped[str] = mapped_column(String(100), nullable=False)
address_type: Mapped[str] = mapped_column(String(50), nullable=False)
street: Mapped[str | None] = mapped_column(String(255), nullable=True)
street_number: Mapped[str | None] = mapped_column(String(20), nullable=True)
city: Mapped[str | None] = mapped_column(String(100), nullable=True)
zip: Mapped[str | None] = mapped_column(String(20), nullable=True)
state: Mapped[str | None] = mapped_column(String(100), nullable=True)
country: Mapped[str | None] = mapped_column(String(2), nullable=True)
is_default: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)