77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, Float, Index, Boolean, Text, ForeignKey, Enum as SQLEnum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from database import Base
|
|
|
|
import enum
|
|
|
|
class Medio(str, enum.Enum):
|
|
MANUAL = "manual"
|
|
DIOT = "diot"
|
|
EXCEL = "excel"
|
|
FACTURA = "factura"
|
|
|
|
class Tercero(str, enum.Enum):
|
|
NACIONAL = "nacional"
|
|
EXTRANJERO = "extranjero"
|
|
GLOBAL = "global"
|
|
|
|
class Operacion(str, enum.Enum):
|
|
PRESTACIONSERVICIOSPROFECIONALES = "prestacion"
|
|
ARRENDAMIENTOSINMUENBLES = "arrendamientos"
|
|
OTROS = "otros"
|
|
|
|
|
|
|
|
class Client(Base):
|
|
__tablename__ = "clients"
|
|
|
|
#Identificacion
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
rfc = Column(String(60), nullable=False, unique=True)
|
|
email = Column(String(150), nullable=False, unique=True)
|
|
|
|
#Datos fiscales
|
|
short_name = Column(String(255), nullable=True)
|
|
razon_social = Column(String(255), nullable=False, index=True)
|
|
fiscal_number = Column(String(15), nullable=False, unique=True)
|
|
cellphone = Column(String(20), nullable=False)
|
|
|
|
|
|
#clasififcacion
|
|
medio = Column(SQLEnum(Medio, name="medio_enum", create_type=False), default=Medio.MANUAL, nullable=False)
|
|
third_type = Column(SQLEnum(Tercero, name="tercero_enum", create_type=False), default=Tercero.GLOBAL, nullable=False)
|
|
operation_type = Column(SQLEnum(Operacion, name="operacion_enum", create_type=False), default=Operacion.OTROS, nullable=False)
|
|
is_foreign = Column(Boolean, nullable=True, default=False)
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
location_id = Column(Integer, ForeignKey("location.id"), nullable=True)
|
|
|
|
#timestamps
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now(), nullable=True)
|
|
deleted_at = Column(DateTime(timezone=True), nullable=True)
|
|
|
|
#trazabilidad
|
|
created_by = Column(Integer, nullable=True)
|
|
updated_by = Column(Integer, nullable=True)
|
|
deleted_by = Column(Integer, nullable=True)
|
|
|
|
__table_args = (
|
|
Index('idx_clients_user', 'user_id'),
|
|
Index('idx_clients_location', 'location_id'),
|
|
)
|
|
|
|
#relationships
|
|
|
|
user = relationship("Users", foreign_keys=[user_id], back_populates="clients")
|
|
location = relationship("Locations", foreign_keys=[location_id])
|
|
license = relationship("License", back_populates="client")
|
|
branches = relationship("Branches", back_populates="client")
|
|
|
|
|
|
def __repr__(self):
|
|
return f"<Client(id={self.id}, rfc={self.rfc}, razon_social={self.razon_social})>"
|
|
|
|
|