55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
from sqlalchemy import Column, Integer, String, Index, DateTime, Float, Boolean, Text, ForeignKey, Enum as SQLEnum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from database import Base
|
|
|
|
import enum
|
|
|
|
class SupplierType(str, enum.Enum):
|
|
NACIONAL = "nacional"
|
|
EXTRANJERO = "exttranjero"
|
|
GLOBAL = "global"
|
|
|
|
|
|
class Suppliers(Base):
|
|
__tablename__ = "suppliers"
|
|
id = Column(Integer, primary_key=True, nullable=False)
|
|
|
|
#Identificacion
|
|
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)
|
|
|
|
supplier_type = Column(SQLEnum(SupplierType, name="suppliertype", create_type=True),
|
|
nullable=False, default=SupplierType.NACIONAL)
|
|
|
|
location_id = Column(Integer, ForeignKey("location.id"), nullable=True)
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
|
|
client_id = Column(Integer, ForeignKey("clients.id"), nullable=False)
|
|
|
|
#timestamsp
|
|
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)
|
|
|
|
#trace
|
|
created_by = Column(Integer, nullable=True)
|
|
updated_by = Column(Integer, nullable=True)
|
|
deleted_by = Column(Integer, nullable=True)
|
|
|
|
#index
|
|
__table_args__ = (
|
|
Index('idx_suppliers_client', 'client_id'),
|
|
Index('idx_suppliers_location', 'location_id'),
|
|
Index('idx_suppliers_type', 'supplier_type'),
|
|
Index('idx_suppliers_active', 'is_active'),
|
|
)
|
|
|
|
client = relationship("Client", foreign_keys=[client_id])
|
|
location = relationship("Locations", foreign_keys=[location_id]) |