- Added service layer for handling client and provider operations including creation, retrieval, updating, and deletion. - Introduced DTOs for data transfer and validation. - Implemented filtering and pagination for client/provider listing. - Added logging for better traceability of operations. feat: Create parts management module - Developed a complete module for managing parts/components including creation, retrieval, updating, and deletion. - Introduced DTOs for parts with detailed attributes and validation. - Implemented search and filtering capabilities for parts based on various criteria. - Added endpoints for regulatory information retrieval and parts statistics. - Integrated logging for error handling and operational insights.
89 lines
3.6 KiB
Python
89 lines
3.6 KiB
Python
"""
|
|
Modelos ORM para gestión de partes/componentes
|
|
"""
|
|
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, Optional
|
|
|
|
if TYPE_CHECKING:
|
|
from api.v1.modules.public.reference_data.countries.models import Country
|
|
from api.v1.modules.public.reference_data.currency_types.models import CurrencyType
|
|
from api.v1.modules.a76.classes.models import Class
|
|
|
|
|
|
class Part(Base):
|
|
"""
|
|
Modelo para la tabla GPartes - Información de partes en los sistemas SCAII (N), SCAF (S) Y WINSAAI (W)
|
|
"""
|
|
__tablename__ = "parts"
|
|
__table_args__ = {"schema": "a76"}
|
|
|
|
# Primary key compuesta
|
|
client_key = Column(Integer, primary_key=True, nullable=False)
|
|
part_number = Column(String(49), primary_key=True, nullable=False)
|
|
|
|
# Basic information
|
|
fraction = Column(String(10), nullable=True)
|
|
description_spanish = Column(String(500), nullable=True)
|
|
description_english = Column(String(500), nullable=True)
|
|
part_class = Column(String(8), nullable=True)
|
|
unit_of_measure = Column(String(5), nullable=True)
|
|
commercial_part_number = Column(String(70), nullable=True)
|
|
country_of_origin = Column(String(3), ForeignKey('public.countries.m3_key'), nullable=True)
|
|
|
|
# Pricing and currency
|
|
unit_cost = Column(Numeric(23, 8), nullable=True)
|
|
currency_type = Column(String(2), nullable=True)
|
|
currency_key = Column(String(3), ForeignKey('public.currency_types.code'), nullable=True)
|
|
|
|
# Weight information
|
|
unit_weight = Column(Numeric(19, 8), nullable=True)
|
|
weight_type = Column(String(6), nullable=True)
|
|
|
|
# Classification and regulatory
|
|
us_fraction = Column(String(16), nullable=True) # FRACCIONAME
|
|
fda_key = Column(String(20), nullable=True)
|
|
fcc_key = Column(String(30), nullable=True)
|
|
license_code = Column(String(3), nullable=True)
|
|
eccn = Column(String(20), nullable=True) # Export Control Classification Number
|
|
export_code = Column(String(2), nullable=True)
|
|
exclusion_symbol = Column(String(19), nullable=True) # SIMBOLOEXCLIC
|
|
|
|
# Additional information
|
|
supplier = Column(String(14), nullable=True)
|
|
alternate_unit_measure = Column(String(14), nullable=True)
|
|
added_value = Column(Numeric(23, 8), nullable=True)
|
|
|
|
# Status and dates
|
|
enabled_disabled = Column(SmallInteger, nullable=True)
|
|
creation_date = Column(Integer, nullable=True) # FECHACREACIONPARTE
|
|
modification_date = Column(Integer, nullable=True) # FECHAMODIFICA
|
|
modification_date_iso = Column(DateTime(timezone=True), nullable=True) # FECHAMODIFICA_ISO
|
|
|
|
# Media
|
|
part_photo = Column(String(255), nullable=True)
|
|
|
|
# Relationships
|
|
country = relationship("Country", foreign_keys=[country_of_origin])
|
|
currency = relationship("CurrencyType", foreign_keys=[currency_key])
|
|
|
|
# Relationship with Class through composite foreign key
|
|
# Note: This requires both client_key and part_class to match client_key and class_code in Class
|
|
part_class_info = relationship(
|
|
"Class",
|
|
primaryjoin="and_(Part.client_key == Class.client_key, Part.part_class == Class.class_code)",
|
|
foreign_keys="[Part.client_key, Part.part_class]",
|
|
viewonly=True,
|
|
back_populates="parts"
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<Part(client_key={self.client_key}, part_number='{self.part_number}', description='{self.description_spanish}')>"
|
|
|
|
|