✨ New Features: - Company module: Single company management with comprehensive business info - Client & Provider module: Manages clients/providers with address/program relationships - GParts module: Parts/components management for SCAII, SCAF, and WINSAAI systems - GClass module: Class classifications for SCAII and SCAF with tariff information 🔗 Database Relationships: - GPart ↔ GClass: Composite key relationship (client_key, part_class ↔ class_code) - GPart → Country: Foreign key to public.countries (country_of_origin) - GPart → CurrencyType: Foreign key to public.currency_types (currency_key) - GClass → MaterialType: Foreign key to public.material_types (material_key) 📊 API Endpoints Added: Company Module (/company): - POST / - Create company - GET / - Get single company Client & Provider Module (/clients-providers): - POST / - Create client/provider - GET / - List all with pagination - GET /clients - List only clients - GET /providers - List only providers - GET /search/rfc/{rfc} - Search by RFC - GET /{client_id} - Get by ID - PUT /{client_id} - Update client/provider - DELETE /{client_id} - Delete client/provider - PATCH /{client_id}/toggle-status - Toggle status - GET /{client_id}/address - Get address info - GET /{client_id}/programs - Get programs info - GET /{client_id}/basic - Get basic info GParts Module (/parts): - POST / - Create part - GET / - List all with pagination and filters - GET /client/{client_key} - Get parts by client - GET /search/fraction/{fraction} - Search by tariff fraction - GET /search/supplier/{supplier} - Search by supplier - GET /search/country/{country_code} - Search by country - GET /statistics - Get parts statistics - GET /{client_key}/{part_number} - Get specific part - PUT /{client_key}/{part_number} - Update part - DELETE /{client_key}/{part_number} - Delete part - PATCH /{client_key}/{part_number}/toggle-status - Toggle status - GET /{client_key}/{part_number}/basic - Get basic info - GET /{client_key}/{part_number}/regulatory - Get regulatory info GClass Module (/classes): - POST / - Create class - GET / - List all with pagination and filters - GET /client/{client_key} - Get classes by client - GET /search/fraction/{fraction} - Search by tariff fraction - GET /search/material/{material_key} - Search by material - GET /search/unit-measure/{unit_of_measure} - Search by unit of measure - GET /search/physical-review/{physical_review} - Search by physical review status - GET /statistics - Get class statistics - GET /{client_key}/{class_code} - Get specific class - PUT /{client_key}/{class_code} - Update class - DELETE /{client_key}/{class_code} - Delete class - GET /{client_key}/{class_code}/basic - Get basic info - GET /{client_key}/{class_code}/tariff - Get tariff information 🏗️ Architecture: - Modular design with models, DTOs, services, and routes for each entity - English field names with composite primary keys where applicable - Comprehensive CRUD operations with specialized search endpoints - SQLAlchemy relationships with proper foreign key constraints - Type-safe DTOs with Pydantic validation 📝 Documentation: - RELATIONSHIPS.md: Complete documentation of database relationships - Detailed type hints and comprehensive service methods - Consistent patterns across all modules for maintainability
61 lines
2.3 KiB
Python
61 lines
2.3 KiB
Python
"""
|
|
Modelos ORM para gestión de clases SCAII y SCAF
|
|
"""
|
|
from sqlalchemy import Column, Integer, String, DateTime, Boolean, Text, Numeric, SmallInteger, ForeignKey
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from core.database import Base
|
|
import enum
|
|
|
|
# Importar modelos relacionados para type hints y relationships
|
|
from typing import TYPE_CHECKING, List
|
|
|
|
if TYPE_CHECKING:
|
|
from api.v1.modules.a76.GParts.models import GPart
|
|
from api.v1.modules.public.reference_data.material_types.models import MaterialType
|
|
|
|
|
|
class GClass(Base):
|
|
"""
|
|
Modelo para la tabla GClases - Información de clases en sistemas SCAII y SCAF
|
|
"""
|
|
__tablename__ = "gclasses"
|
|
|
|
# Primary key compuesta
|
|
client_key = Column(Integer, primary_key=True, nullable=False)
|
|
class_code = Column(String(8), primary_key=True, nullable=False)
|
|
|
|
# Basic information
|
|
description_spanish = Column(String(500), nullable=True)
|
|
description_english = Column(String(500), nullable=True)
|
|
|
|
# Material and measurement
|
|
material_key = Column(String(10), ForeignKey('public.material_types.key'), nullable=True) # CLAVEMAT - homologated from TIPOMAT/TIPOMATEQUIPO
|
|
unit_of_measure = Column(String(5), nullable=True) # UNIMED - homologated from UNIMEDIDA
|
|
|
|
# Tariff fractions
|
|
fraction = Column(String(10), nullable=True) # Mexican tariff fraction
|
|
us_fraction = Column(String(16), nullable=True) # FRACCIONAME - US tariff fraction
|
|
|
|
# Additional classification
|
|
sub_key = Column(String(5), nullable=True) # CLAVESUB
|
|
physical_review = Column(SmallInteger, nullable=True) # REVFISICA
|
|
iva_exempt_fraction = Column(String(4), nullable=True) # FRACCIONEXENTAIVA
|
|
|
|
# Relationships
|
|
material_type: "MaterialType" = relationship("MaterialType", foreign_keys=[material_key])
|
|
|
|
# Inverse relationship with GParts that have this class
|
|
parts: List["GPart"] = relationship(
|
|
"GPart",
|
|
primaryjoin="and_(GClass.client_key == GPart.client_key, GClass.class_code == GPart.part_class)",
|
|
foreign_keys="[GPart.client_key, GPart.part_class]",
|
|
viewonly=True,
|
|
back_populates="part_class_info"
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<GClass(client_key={self.client_key}, class_code='{self.class_code}', description='{self.description_spanish}')>"
|
|
|
|
|