Files
plantillas-proyectos/backend/alembic/versions/03b786378f94_pedimentos.py
acazares 07dfe1edb1 Add service layers and models for Pedimento CRUD operations
- Implemented service classes for PedimentoConfigParameters, PedimentoConfigSurcharges, PedimentoConfigUpdateRectification, PedimentoConfigUpdates, PedimentoCustomsOffices, PedimentoDates, PedimentoDecrementables, PedimentoIncrementables, PedimentoIndexes, PedimentoPayments, PedimentoRectificationDestination, PedimentoRectificationOrigin, PedimentoTransportMeans, and PedimentoValidation.
- Each service class includes methods for CRUD operations: create, read, update, and delete.
- Added a main router for the API v1, integrating various modules including authentication, tenants, licenses, and pedimentos.
- Created models for PedimentoValidation with appropriate constraints and relationships.
2025-11-06 17:16:29 -06:00

425 lines
29 KiB
Python

"""Pedimentos
Revision ID: 03b786378f94
Revises: 7937209f9718
Create Date: 2025-11-06 17:07:16.536298
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '03b786378f94'
down_revision: Union[str, Sequence[str], None] = '7937209f9718'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('pedimentos',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('year', sa.String(length=2), nullable=True),
sa.Column('customs_office', sa.String(length=2), nullable=True),
sa.Column('license', sa.String(length=4), nullable=True),
sa.Column('pedimento_number', sa.String(length=7), nullable=True),
sa.Column('client_id', sa.Integer(), nullable=True),
sa.Column('operation_type', sa.Integer(), nullable=True),
sa.Column('pedimento_type', sa.Integer(), nullable=True),
sa.Column('pedimento_key', sa.String(length=2), nullable=True),
sa.Column('regime', sa.String(length=3), nullable=True),
sa.Column('status', sa.String(length=30), nullable=True),
sa.Column('usd_value', sa.Numeric(precision=17, scale=6), nullable=True),
sa.Column('paid_price', sa.Numeric(precision=17, scale=6), nullable=True),
sa.Column('gross_weight', sa.Numeric(precision=19, scale=3), nullable=True),
sa.Column('exchange_rate', sa.Numeric(precision=9, scale=5), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimentos_pkey'),
schema='a76'
)
op.create_index('idx_pedimentos_client_id', 'pedimentos', ['client_id'], unique=False, schema='a76')
op.create_index('idx_pedimentos_created_at', 'pedimentos', ['created_at'], unique=False, schema='a76')
op.create_index('idx_pedimentos_status', 'pedimentos', ['status'], unique=False, schema='a76')
op.create_index(op.f('ix_a76_pedimentos_tenant_id'), 'pedimentos', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_config_additional',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('add_po_identifier', sa.SmallInteger(), nullable=True),
sa.Column('do_not_exempt_norms_complement_x', sa.SmallInteger(), nullable=True),
sa.Column('manual_pedimento_year', sa.String(length=2), nullable=True),
sa.Column('enable_import_invoice_recipient', sa.SmallInteger(), nullable=True),
sa.Column('send_502_validation_file_for_consolidated', sa.SmallInteger(), nullable=True),
sa.Column('add_remove_norms', sa.SmallInteger(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_additional', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_config_additional_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_config_additional_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_config_additional_tenant_id'), 'pedimento_config_additional', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_config_calculations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('dta_type', sa.String(length=1), nullable=True),
sa.Column('dta_operation', sa.SmallInteger(), nullable=True),
sa.Column('dta_vehicle_count', sa.SmallInteger(), nullable=True),
sa.Column('dta_mixed_rate_8permil', sa.SmallInteger(), nullable=True),
sa.Column('pays_vat', sa.SmallInteger(), nullable=True),
sa.Column('pays_prevalidation', sa.SmallInteger(), nullable=True),
sa.Column('include_sagar_certificate_fee', sa.SmallInteger(), nullable=True),
sa.Column('fixed_vehicle_dta_fee', sa.SmallInteger(), nullable=True),
sa.Column('additional_fixed_fee', sa.SmallInteger(), nullable=True),
sa.Column('additional_fixed_fee_payment_method', sa.SmallInteger(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_calculations', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_config_calculations_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_config_calculations_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_config_calculations_tenant_id'), 'pedimento_config_calculations', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_config_parameters',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('is_embassy', sa.SmallInteger(), nullable=True),
sa.Column('embassy_dta', sa.Numeric(precision=11, scale=2), nullable=True),
sa.Column('rule_3121_section_ii', sa.SmallInteger(), nullable=True),
sa.Column('use_previous_tariff', sa.SmallInteger(), nullable=True),
sa.Column('use_payment_date_fi', sa.SmallInteger(), nullable=True),
sa.Column('add_state_supplier_record_505', sa.SmallInteger(), nullable=True),
sa.Column('customs_value_calculation', sa.SmallInteger(), nullable=True),
sa.Column('two_decimals_unit_value', sa.SmallInteger(), nullable=True),
sa.Column('customs_value_per_item', sa.SmallInteger(), nullable=True),
sa.Column('is_national_supplier', sa.SmallInteger(), nullable=True),
sa.Column('is_consolidated', sa.SmallInteger(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_parameters', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_config_parameters_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_config_parameters_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_config_parameters_tenant_id'), 'pedimento_config_parameters', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_config_surcharges',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('surcharge_igi', sa.SmallInteger(), nullable=True),
sa.Column('surcharge_dta', sa.SmallInteger(), nullable=True),
sa.Column('surcharge_vat', sa.SmallInteger(), nullable=True),
sa.Column('surcharge_isan', sa.SmallInteger(), nullable=True),
sa.Column('surcharge_ieps', sa.SmallInteger(), nullable=True),
sa.Column('surcharge_cc', sa.SmallInteger(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_surcharges', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_config_surcharges_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_config_surcharges_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_config_surcharges_tenant_id'), 'pedimento_config_surcharges', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_config_update_rectification',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('update_vat', sa.SmallInteger(), nullable=True),
sa.Column('update_advalorem', sa.SmallInteger(), nullable=True),
sa.Column('update_cc', sa.SmallInteger(), nullable=True),
sa.Column('update_ieps', sa.SmallInteger(), nullable=True),
sa.Column('calculate_surcharge', sa.SmallInteger(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_update_rectification', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_config_update_rectification_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_config_update_rectification_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_config_update_rectification_tenant_id'), 'pedimento_config_update_rectification', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_config_updates',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('update_vat', sa.SmallInteger(), nullable=True),
sa.Column('update_advalorem', sa.SmallInteger(), nullable=True),
sa.Column('update_cc', sa.SmallInteger(), nullable=True),
sa.Column('update_ieps', sa.SmallInteger(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_updates', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_config_updates_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_config_updates_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_config_updates_tenant_id'), 'pedimento_config_updates', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_customs_offices',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('dispatch_customs', sa.String(length=3), nullable=True),
sa.Column('entry_exit_customs', sa.String(length=3), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_customs_offices', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_customs_offices_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_customs_offices_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_customs_offices_tenant_id'), 'pedimento_customs_offices', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_dates',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('entry_date', sa.DateTime(), nullable=True),
sa.Column('pedimento_date', sa.DateTime(), nullable=True),
sa.Column('payment_date', sa.DateTime(), nullable=True),
sa.Column('rectification_payment_date', sa.DateTime(), nullable=True),
sa.Column('extraction_date', sa.DateTime(), nullable=True),
sa.Column('submission_date', sa.DateTime(), nullable=True),
sa.Column('eucan_date', sa.DateTime(), nullable=True),
sa.Column('original_date', sa.DateTime(), nullable=True),
sa.Column('start_date', sa.DateTime(), nullable=True),
sa.Column('end_date', sa.DateTime(), nullable=True),
sa.Column('capture_date', sa.DateTime(), nullable=True),
sa.Column('capture_time', sa.Time(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_dates', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_dates_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_dates_pedimento_id_key'),
schema='a76'
)
op.create_index('idx_pedimento_dates_pedimento_id', 'pedimento_dates', ['pedimento_id'], unique=False, schema='a76')
op.create_index(op.f('ix_a76_pedimento_dates_tenant_id'), 'pedimento_dates', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_decrementables',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('freight', sa.Numeric(precision=13, scale=2), nullable=True),
sa.Column('insurance', sa.Numeric(precision=13, scale=2), nullable=True),
sa.Column('loading', sa.Numeric(precision=13, scale=2), nullable=True),
sa.Column('unloading', sa.Numeric(precision=13, scale=2), nullable=True),
sa.Column('others', sa.Numeric(precision=13, scale=2), nullable=True),
sa.Column('currency', sa.String(length=3), nullable=True),
sa.Column('currency_factor', sa.Numeric(precision=15, scale=8), nullable=True),
sa.Column('not_affect_usd_value', sa.SmallInteger(), nullable=True),
sa.Column('not_affect_customs_value', sa.SmallInteger(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_decrementables', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_decrementables_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_decrementables_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_decrementables_tenant_id'), 'pedimento_decrementables', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_incrementables',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('insured_value', sa.Numeric(precision=13, scale=2), nullable=True),
sa.Column('freight', sa.Numeric(precision=13, scale=2), nullable=True),
sa.Column('insurance', sa.Numeric(precision=13, scale=2), nullable=True),
sa.Column('packaging', sa.Numeric(precision=13, scale=2), nullable=True),
sa.Column('others', sa.Numeric(precision=13, scale=3), nullable=True),
sa.Column('deductibles', sa.Numeric(precision=13, scale=3), nullable=True),
sa.Column('currency', sa.String(length=3), nullable=True),
sa.Column('currency_factor', sa.Numeric(precision=15, scale=8), nullable=True),
sa.Column('not_affect_usd_value', sa.SmallInteger(), nullable=True),
sa.Column('not_affect_customs_value', sa.SmallInteger(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_incrementables', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_incrementables_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_incrementables_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_incrementables_tenant_id'), 'pedimento_incrementables', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_indexes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('update_factor_type', sa.SmallInteger(), nullable=True),
sa.Column('update_factor', sa.Numeric(precision=7, scale=4), nullable=True),
sa.Column('manual_update_factor', sa.SmallInteger(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_indexes', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_indexes_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_indexes_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_indexes_tenant_id'), 'pedimento_indexes', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_payments',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('acknowledgment', sa.String(length=20), nullable=True),
sa.Column('operation_number', sa.String(length=14), nullable=True),
sa.Column('bank_code', sa.Integer(), nullable=True),
sa.Column('cashier', sa.String(length=2), nullable=True),
sa.Column('date', sa.Date(), nullable=True),
sa.Column('time', sa.Time(), nullable=True),
sa.Column('shift', sa.String(length=1), nullable=True),
sa.Column('total_cash_paid', sa.Integer(), nullable=True),
sa.Column('total_contributions', sa.Integer(), nullable=True),
sa.Column('counter_payment', sa.SmallInteger(), nullable=True),
sa.Column('pece_code', sa.String(length=5), nullable=True),
sa.Column('payment_id', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_payments', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_payments_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_payments_pedimento_id_key'),
schema='a76'
)
op.create_index('idx_pedimento_payments_pedimento_id', 'pedimento_payments', ['pedimento_id'], unique=False, schema='a76')
op.create_index(op.f('ix_a76_pedimento_payments_tenant_id'), 'pedimento_payments', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_rectification_destination',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('destination_pedimento_year', sa.String(length=2), nullable=True),
sa.Column('destination_customs_office', sa.String(length=3), nullable=True),
sa.Column('destination_license', sa.String(length=4), nullable=True),
sa.Column('destination_pedimento_number', sa.String(length=7), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_rectification_destination', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_rectification_destination_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_rectification_destination_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_rectification_destination_tenant_id'), 'pedimento_rectification_destination', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_rectification_origin',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('original_pedimento_year', sa.String(length=2), nullable=True),
sa.Column('original_customs_office', sa.String(length=3), nullable=True),
sa.Column('original_license', sa.String(length=4), nullable=True),
sa.Column('original_pedimento_number', sa.String(length=7), nullable=True),
sa.Column('original_pedimento_key', sa.String(length=2), nullable=True),
sa.Column('original_payment_date', sa.DateTime(), nullable=True),
sa.Column('total_cash', sa.Integer(), nullable=True),
sa.Column('total_others', sa.Integer(), nullable=True),
sa.Column('reason', sa.String(length=255), nullable=True),
sa.Column('charge_to_client', sa.SmallInteger(), nullable=True),
sa.Column('use_original_payment_date_for_interest_calc', sa.SmallInteger(), nullable=True),
sa.Column('manual_calculation', sa.SmallInteger(), nullable=True),
sa.Column('original_pedimento_norms', sa.SmallInteger(), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_rectification_origin', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_rectification_origin_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_rectification_origin_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_rectification_origin_tenant_id'), 'pedimento_rectification_origin', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_transport_means',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('destination', sa.SmallInteger(), nullable=True),
sa.Column('entry_exit', sa.String(length=2), nullable=True),
sa.Column('arrival', sa.String(length=2), nullable=True),
sa.Column('departure', sa.String(length=2), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_transport_means', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_transport_means_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_transport_means_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_transport_means_tenant_id'), 'pedimento_transport_means', ['tenant_id'], unique=False, schema='a76')
op.create_table('pedimento_validation',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('validator', sa.String(length=3), nullable=True),
sa.Column('validation_ack', sa.String(length=8), nullable=True),
sa.Column('pre_ack', sa.String(length=8), nullable=True),
sa.Column('line_signature', sa.String(length=50), nullable=True),
sa.Column('electronic_signature', sa.String(length=999), nullable=True),
sa.Column('certificate_number', sa.String(length=99), nullable=True),
sa.Column('validator_id', sa.Integer(), nullable=True),
sa.Column('responsible_id', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_validation', ondelete='CASCADE'),
sa.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id', name='pedimento_validation_pkey'),
sa.UniqueConstraint('pedimento_id', name='pedimento_validation_pedimento_id_key'),
schema='a76'
)
op.create_index(op.f('ix_a76_pedimento_validation_tenant_id'), 'pedimento_validation', ['tenant_id'], unique=False, schema='a76')
op.drop_constraint(op.f('fk_regimenped'), 'code_pedimento_regimens', type_='foreignkey')
op.drop_constraint(op.f('fk_codeped'), 'code_pedimento_regimens', type_='foreignkey')
op.create_foreign_key('fk_codeped', 'code_pedimento_regimens', 'pedimento_codes', ['pedimento_code'], ['code'], source_schema='public', referent_schema='public')
op.create_foreign_key('fk_regimenped', 'code_pedimento_regimens', 'pedimento_regimens', ['regimen_code'], ['code'], source_schema='public', referent_schema='public')
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint('fk_regimenped', 'code_pedimento_regimens', schema='public', type_='foreignkey')
op.drop_constraint('fk_codeped', 'code_pedimento_regimens', schema='public', type_='foreignkey')
op.create_foreign_key(op.f('fk_codeped'), 'code_pedimento_regimens', 'pedimento_codes', ['pedimento_code'], ['code'])
op.create_foreign_key(op.f('fk_regimenped'), 'code_pedimento_regimens', 'pedimento_regimens', ['regimen_code'], ['code'])
op.drop_index(op.f('ix_a76_pedimento_validation_tenant_id'), table_name='pedimento_validation', schema='a76')
op.drop_table('pedimento_validation', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_transport_means_tenant_id'), table_name='pedimento_transport_means', schema='a76')
op.drop_table('pedimento_transport_means', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_rectification_origin_tenant_id'), table_name='pedimento_rectification_origin', schema='a76')
op.drop_table('pedimento_rectification_origin', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_rectification_destination_tenant_id'), table_name='pedimento_rectification_destination', schema='a76')
op.drop_table('pedimento_rectification_destination', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_payments_tenant_id'), table_name='pedimento_payments', schema='a76')
op.drop_index('idx_pedimento_payments_pedimento_id', table_name='pedimento_payments', schema='a76')
op.drop_table('pedimento_payments', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_indexes_tenant_id'), table_name='pedimento_indexes', schema='a76')
op.drop_table('pedimento_indexes', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_incrementables_tenant_id'), table_name='pedimento_incrementables', schema='a76')
op.drop_table('pedimento_incrementables', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_decrementables_tenant_id'), table_name='pedimento_decrementables', schema='a76')
op.drop_table('pedimento_decrementables', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_dates_tenant_id'), table_name='pedimento_dates', schema='a76')
op.drop_index('idx_pedimento_dates_pedimento_id', table_name='pedimento_dates', schema='a76')
op.drop_table('pedimento_dates', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_customs_offices_tenant_id'), table_name='pedimento_customs_offices', schema='a76')
op.drop_table('pedimento_customs_offices', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_config_updates_tenant_id'), table_name='pedimento_config_updates', schema='a76')
op.drop_table('pedimento_config_updates', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_config_update_rectification_tenant_id'), table_name='pedimento_config_update_rectification', schema='a76')
op.drop_table('pedimento_config_update_rectification', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_config_surcharges_tenant_id'), table_name='pedimento_config_surcharges', schema='a76')
op.drop_table('pedimento_config_surcharges', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_config_parameters_tenant_id'), table_name='pedimento_config_parameters', schema='a76')
op.drop_table('pedimento_config_parameters', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_config_calculations_tenant_id'), table_name='pedimento_config_calculations', schema='a76')
op.drop_table('pedimento_config_calculations', schema='a76')
op.drop_index(op.f('ix_a76_pedimento_config_additional_tenant_id'), table_name='pedimento_config_additional', schema='a76')
op.drop_table('pedimento_config_additional', schema='a76')
op.drop_index(op.f('ix_a76_pedimentos_tenant_id'), table_name='pedimentos', schema='a76')
op.drop_index('idx_pedimentos_status', table_name='pedimentos', schema='a76')
op.drop_index('idx_pedimentos_created_at', table_name='pedimentos', schema='a76')
op.drop_index('idx_pedimentos_client_id', table_name='pedimentos', schema='a76')
op.drop_table('pedimentos', schema='a76')
op.drop_index(op.f('ix_a76_licenses_tenant_id'), table_name='licenses', schema='a76')
op.drop_index(op.f('ix_a76_licenses_id'), table_name='licenses', schema='a76')
op.drop_table('licenses', schema='a76')
op.drop_index(op.f('ix_a76_license_usage_tenant_id'), table_name='license_usage', schema='a76')
op.drop_index(op.f('ix_a76_license_usage_id'), table_name='license_usage', schema='a76')
op.drop_table('license_usage', schema='a76')
op.drop_index(op.f('ix_a76_tenants_slug'), table_name='tenants', schema='a76')
op.drop_index(op.f('ix_a76_tenants_name'), table_name='tenants', schema='a76')
op.drop_index(op.f('ix_a76_tenants_id'), table_name='tenants', schema='a76')
op.drop_table('tenants', schema='a76')
# ### end Alembic commands ###