- Updated GBultoService to use models.Package instead of models.GBulto. - Refactored Part model to use SQLAlchemy 2.0 style with Mapped and mapped_column. - Added timestamps (created_at, updated_at, deleted_at) to various pedimento models. - Improved relationships and foreign key constraints in pedimento models. - Updated PermissionRuleOct and Seal models to use Mapped and mapped_column. - Changed DTO configuration from orm_mode to from_attributes for better compatibility. - Removed obsolete models (models.py and models_ped.py) from the repository.
94 lines
3.4 KiB
Python
94 lines
3.4 KiB
Python
"""
|
|
Modelos ORM para gestión de licencias
|
|
"""
|
|
from datetime import datetime
|
|
from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey, Enum as SQLEnum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
from core.database import Base
|
|
import enum
|
|
|
|
|
|
class LicensePlan(enum.Enum):
|
|
"""Planes de licencia disponibles"""
|
|
FREE = "free"
|
|
BASIC = "basic"
|
|
PROFESSIONAL = "professional"
|
|
ENTERPRISE = "enterprise"
|
|
|
|
|
|
class LicenseStatus(enum.Enum):
|
|
"""Estados de licencia"""
|
|
ACTIVE = "active"
|
|
EXPIRED = "expired"
|
|
SUSPENDED = "suspended"
|
|
PENDING = "pending"
|
|
CANCELLED = "cancelled"
|
|
|
|
|
|
class License(Base):
|
|
"""
|
|
Modelo de Licencia - Control de planes y límites por tenant
|
|
"""
|
|
__tablename__ = "licenses"
|
|
__table_args__ = {"schema": "a76"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
tenant_id = Column(Integer, ForeignKey("a76.tenants.id"), nullable=False, unique=True, index=True)
|
|
|
|
# Plan y características
|
|
plan = Column(SQLEnum(LicensePlan), default=LicensePlan.FREE, nullable=False)
|
|
status = Column(SQLEnum(LicenseStatus), default=LicenseStatus.PENDING, nullable=False)
|
|
|
|
# Límites del plan
|
|
max_users = Column(Integer, default=5, nullable=False)
|
|
max_storage_gb = Column(Integer, default=10, nullable=False)
|
|
max_monthly_operations = Column(Integer, default=1000, nullable=False)
|
|
|
|
# Features habilitadas (booleans)
|
|
feature_api_access = Column(Boolean, default=True)
|
|
feature_advanced_reports = Column(Boolean, default=False)
|
|
feature_integrations = Column(Boolean, default=False)
|
|
feature_dedicated_support = Column(Boolean, default=False)
|
|
|
|
# Vigencia
|
|
starts_at = Column(DateTime(timezone=True), nullable=False)
|
|
expires_at = Column(DateTime(timezone=True), nullable=False)
|
|
|
|
# Timestamps
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=func.now(), onupdate=func.now())
|
|
deleted_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
|
|
def __repr__(self):
|
|
return f"<License(tenant_id={self.tenant_id}, plan={self.plan.value}, status={self.status.value})>"
|
|
|
|
|
|
class LicenseUsage(Base):
|
|
"""
|
|
Modelo para tracking de uso de licencia
|
|
"""
|
|
__tablename__ = "license_usage"
|
|
__table_args__ = {"schema": "a76"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
tenant_id = Column(Integer, ForeignKey("a76.tenants.id"), nullable=False, index=True)
|
|
|
|
# Métricas de uso
|
|
period_start = Column(DateTime(timezone=True), nullable=False)
|
|
period_end = Column(DateTime(timezone=True), nullable=False)
|
|
|
|
active_users = Column(Integer, default=0)
|
|
storage_used_gb = Column(Integer, default=0)
|
|
operations_count = Column(Integer, default=0)
|
|
api_calls_count = Column(Integer, default=0)
|
|
|
|
# Timestamps
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=func.now(), onupdate=func.now())
|
|
deleted_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
|
|
def __repr__(self):
|
|
return f"<LicenseUsage(tenant_id={self.tenant_id}, operations={self.operations_count})>"
|