- 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.
39 lines
1.9 KiB
Python
39 lines
1.9 KiB
Python
from typing import TYPE_CHECKING
|
|
from sqlalchemy import DateTime, ForeignKeyConstraint, Integer, Numeric, PrimaryKeyConstraint, SmallInteger, String, UniqueConstraint, func, text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.orm.base import Mapped
|
|
from datetime import datetime
|
|
from core.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from api.v1.modules.a76.pedmientos.models.pedimentos import Pedimentos
|
|
|
|
class PedimentoDecrementables(Base):
|
|
__tablename__ = 'pedimento_decrementables'
|
|
__table_args__ = (
|
|
ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id']),
|
|
ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], ondelete='CASCADE', name='fk_pedimento_decrementables'),
|
|
PrimaryKeyConstraint('id', name='pedimento_decrementables_pkey'),
|
|
UniqueConstraint('pedimento_id', name='pedimento_decrementables_pedimento_id_key'),
|
|
{'schema': 'a76'}
|
|
)
|
|
|
|
id = mapped_column(Integer)
|
|
pedimento_id = mapped_column(Integer, nullable=False)
|
|
tenant_id = mapped_column(Integer, nullable=False, index=True)
|
|
freight = mapped_column(Numeric(13, 2))
|
|
insurance = mapped_column(Numeric(13, 2))
|
|
loading = mapped_column(Numeric(13, 2))
|
|
unloading = mapped_column(Numeric(13, 2))
|
|
others = mapped_column(Numeric(13, 2))
|
|
currency = mapped_column(String(3))
|
|
currency_factor = mapped_column(Numeric(15, 8))
|
|
not_affect_usd_value = mapped_column(SmallInteger)
|
|
not_affect_customs_value = mapped_column(SmallInteger)
|
|
|
|
# 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)
|
|
|
|
pedimento: Mapped['Pedimentos'] = relationship('Pedimentos', back_populates='pedimento_decrementables') |