diff --git a/backend/alembic/versions/57472f4f3ca0_add_material_type_key_to_parts.py b/backend/alembic/versions/57472f4f3ca0_add_material_type_key_to_parts.py new file mode 100644 index 00000000..7e6c7705 --- /dev/null +++ b/backend/alembic/versions/57472f4f3ca0_add_material_type_key_to_parts.py @@ -0,0 +1,2658 @@ +"""add material_type_key to parts + +Revision ID: 57472f4f3ca0 +Revises: 7937209f9718 +Create Date: 2026-01-07 15:27:22.443152 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = '57472f4f3ca0' +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('tenants', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('slug', sa.String(length=100), nullable=False), + sa.Column('type', sa.Enum('SHARED', 'DEDICATED', name='tenanttype'), nullable=False), + sa.Column('keycloak_realm', sa.String(length=255), nullable=False), + sa.Column('db_config', sa.Text(), nullable=True), + sa.Column('contact_name', sa.String(length=255), nullable=True), + sa.Column('contact_email', sa.String(length=255), nullable=True), + sa.Column('contact_phone', sa.String(length=50), nullable=True), + sa.Column('is_active', sa.Boolean(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.PrimaryKeyConstraint('id'), + schema='core' + ) + op.create_index(op.f('ix_core_tenants_id'), 'tenants', ['id'], unique=False, schema='core') + op.create_index(op.f('ix_core_tenants_name'), 'tenants', ['name'], unique=False, schema='core') + op.create_index(op.f('ix_core_tenants_slug'), 'tenants', ['slug'], unique=True, schema='core') + op.create_table('company', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=255), nullable=True), + sa.Column('rfc', sa.String(length=30), nullable=True), + sa.Column('main_activity', sa.String(length=255), nullable=True), + sa.Column('program', sa.String(length=10), nullable=True), + sa.Column('program_number', sa.String(length=40), nullable=True), + sa.Column('prosec', sa.SmallInteger(), nullable=True), + sa.Column('prosec_authorization', sa.String(length=20), nullable=True), + sa.Column('manufacturer_id', sa.String(length=25), nullable=True), + sa.Column('broker_company', sa.String(length=10), nullable=True), + sa.Column('responsible', sa.String(length=80), nullable=True), + sa.Column('responsible_name', sa.String(length=20), nullable=True), + sa.Column('responsible_last_name', sa.String(length=20), nullable=True), + sa.Column('responsible_mother_last_name', sa.String(length=20), nullable=True), + sa.Column('responsible_rfc', sa.String(length=30), nullable=True), + sa.Column('position', sa.String(length=30), nullable=True), + sa.Column('logo', sa.String(length=255), nullable=True), + sa.Column('has_express_line', sa.Boolean(), nullable=True), + sa.Column('order_format_type', sa.String(length=19), nullable=True), + sa.Column('previous_code', sa.SmallInteger(), nullable=True), + sa.Column('is_service_company', sa.Boolean(), nullable=True), + sa.Column('client_name', sa.String(length=300), nullable=True), + sa.Column('subassembly_mode', sa.String(length=7), nullable=True), + sa.Column('curp', sa.String(length=19), nullable=True), + sa.Column('inter_db_name', sa.String(length=100), nullable=True), + sa.Column('ctpat_svi', sa.String(length=100), nullable=True), + sa.Column('trusted_exporter_number', sa.String(length=50), nullable=True), + sa.Column('prevalidator_key', sa.String(length=20), nullable=True), + sa.Column('seventh_amendment', sa.Boolean(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='company_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_company_tenant_id'), 'company', ['tenant_id'], unique=False, schema='a76') + op.create_table('customs_broker_concepts', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('broker_key', sa.String(length=5), nullable=False), + sa.Column('concept', sa.String(length=15), nullable=False), + sa.Column('amount', sa.Numeric(precision=11, scale=2), nullable=True), + sa.Column('priority', sa.Integer(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('broker_key', 'concept', 'company_id', name='uq_broker_concept'), + schema='a76' + ) + op.create_index(op.f('ix_a76_customs_broker_concepts_tenant_id'), 'customs_broker_concepts', ['tenant_id'], unique=False, schema='a76') + op.create_table('license_usage', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('period_start', sa.DateTime(timezone=True), nullable=False), + sa.Column('period_end', sa.DateTime(timezone=True), nullable=False), + sa.Column('active_users', sa.Integer(), nullable=True), + sa.Column('storage_used_gb', sa.Integer(), nullable=True), + sa.Column('operations_count', sa.Integer(), nullable=True), + sa.Column('api_calls_count', sa.Integer(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='core' + ) + op.create_index(op.f('ix_core_license_usage_id'), 'license_usage', ['id'], unique=False, schema='core') + op.create_index(op.f('ix_core_license_usage_tenant_id'), 'license_usage', ['tenant_id'], unique=False, schema='core') + op.create_table('licenses', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('plan', sa.Enum('FREE', 'BASIC', 'PROFESSIONAL', 'ENTERPRISE', name='licenseplan'), nullable=False), + sa.Column('status', sa.Enum('ACTIVE', 'EXPIRED', 'SUSPENDED', 'PENDING', 'CANCELLED', name='licensestatus'), nullable=False), + sa.Column('max_users', sa.Integer(), nullable=False), + sa.Column('max_storage_gb', sa.Integer(), nullable=False), + sa.Column('max_monthly_operations', sa.Integer(), nullable=False), + sa.Column('feature_api_access', sa.Boolean(), nullable=True), + sa.Column('feature_advanced_reports', sa.Boolean(), nullable=True), + sa.Column('feature_integrations', sa.Boolean(), nullable=True), + sa.Column('feature_dedicated_support', sa.Boolean(), nullable=True), + sa.Column('starts_at', sa.DateTime(timezone=True), nullable=False), + sa.Column('expires_at', sa.DateTime(timezone=True), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='core' + ) + op.create_index(op.f('ix_core_licenses_id'), 'licenses', ['id'], unique=False, schema='core') + op.create_index(op.f('ix_core_licenses_tenant_id'), 'licenses', ['tenant_id'], unique=True, schema='core') + op.create_table('location', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=5), nullable=False), + sa.Column('description', sa.String(length=200), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='location_pkey'), + sa.UniqueConstraint('code'), + sa.UniqueConstraint('code', name='location_code_unique'), + schema='a24' + ) + op.create_index(op.f('ix_a24_location_company_id'), 'location', ['company_id'], unique=False, schema='a24') + op.create_index(op.f('ix_a24_location_tenant_id'), 'location', ['tenant_id'], unique=False, schema='a24') + op.create_table('classification_concepts', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('classification', sa.String(length=30), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('classification', name='uq_classification_concept'), + schema='a76' + ) + op.create_index(op.f('ix_a76_classification_concepts_company_id'), 'classification_concepts', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_classification_concepts_tenant_id'), 'classification_concepts', ['tenant_id'], unique=False, schema='a76') + op.create_table('clients_and_providers', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('type_nat_foreign', sa.String(length=1), nullable=True), + sa.Column('name', sa.String(length=256), nullable=True), + sa.Column('short_name', sa.String(length=10), nullable=True), + sa.Column('rfc', sa.String(length=30), nullable=True), + sa.Column('curp', sa.String(length=19), nullable=True), + sa.Column('client_or_provider', sa.Enum('CLIENT', 'PROVIDER', 'BOTH', name='entity_client_or_provider'), nullable=False), + sa.Column('linking', sa.String(length=1), nullable=True), + sa.Column('transform_subassembly', sa.String(length=1), nullable=True), + sa.Column('extra_information', sa.String(length=399), nullable=True), + sa.Column('web_key', sa.String(length=40), nullable=True), + sa.Column('responsible', sa.String(length=80), nullable=True), + sa.Column('position', sa.String(length=30), nullable=True), + sa.Column('incoterm', sa.String(length=19), nullable=True), + sa.Column('is_national_provider', sa.Boolean(), nullable=True), + sa.Column('is_active', sa.Boolean(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='clients_and_providers_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_clients_and_providers_company_id'), 'clients_and_providers', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_clients_and_providers_tenant_id'), 'clients_and_providers', ['tenant_id'], unique=False, schema='a76') + op.create_table('customs_brokers', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('type', sa.String(length=9), nullable=True), + sa.Column('broker_key', sa.String(length=5), nullable=False), + sa.Column('name', sa.String(length=80), nullable=True), + sa.Column('address', sa.String(length=1500), nullable=True), + sa.Column('postal_code', sa.String(length=15), nullable=True), + sa.Column('city', sa.String(length=30), nullable=True), + sa.Column('state', sa.String(length=30), nullable=True), + sa.Column('phone', sa.String(length=30), nullable=True), + sa.Column('fax', sa.String(length=30), nullable=True), + sa.Column('email', sa.String(length=100), nullable=True), + sa.Column('country', sa.String(length=3), nullable=True), + sa.Column('tax_id', sa.String(length=30), nullable=True), + sa.Column('personal_id', sa.String(length=20), nullable=True), + sa.Column('position', sa.String(length=30), nullable=True), + sa.Column('license', sa.String(length=4), nullable=True), + sa.Column('company', sa.String(length=200), nullable=True), + sa.Column('contact', sa.String(length=80), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='customs_brokers_pkey'), + sa.UniqueConstraint('broker_key', 'tenant_id', 'company_id', name='uq_broker_key_tenant_company'), + schema='a76' + ) + op.create_index(op.f('ix_a76_customs_brokers_company_id'), 'customs_brokers', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_customs_brokers_tenant_id'), 'customs_brokers', ['tenant_id'], unique=False, schema='a76') + op.create_table('doda', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('integration_number', sa.String(length=30), nullable=True), + sa.Column('doda_date', sa.Integer(), nullable=True), + sa.Column('doda_time', sa.Integer(), nullable=True), + sa.Column('dispatch_customs', sa.String(length=3), nullable=True), + sa.Column('customs_sections', sa.String(length=3), nullable=True), + sa.Column('patent', sa.String(length=4), nullable=True), + sa.Column('pedimentos', sa.String(length=80), nullable=True), + sa.Column('caat', sa.String(length=10), nullable=True), + sa.Column('transport_identification', sa.String(length=20), nullable=True), + sa.Column('fast_id', sa.String(length=20), nullable=True), + sa.Column('operation_type', sa.String(length=1), nullable=True), + sa.Column('selected', sa.Boolean(), nullable=True), + sa.Column('user_selected', sa.String(length=30), nullable=True), + sa.Column('last_user', sa.String(length=30), nullable=True), + sa.Column('responsible', sa.String(length=14), nullable=True), + sa.Column('carrier', sa.String(length=8), nullable=True), + sa.Column('shipments', sa.String(length=80), nullable=True), + sa.Column('pedimento_type', sa.String(length=30), nullable=True), + sa.Column('original_chain', sa.String(length=5000), nullable=True), + sa.Column('serial_number', sa.String(length=21), nullable=True), + sa.Column('electronic_signature', sa.String(length=2000), nullable=True), + sa.Column('transaction_number', sa.String(length=30), nullable=True), + sa.Column('status', sa.String(length=30), nullable=True), + sa.Column('linq_sat_qr', sa.String(length=1000), nullable=True), + sa.Column('sat_certificate', sa.String(length=2001), nullable=True), + sa.Column('sat_digital_seal', sa.Text(), nullable=True), + sa.Column('xml_doda_sent_path', sa.String(length=1000), nullable=True), + sa.Column('xml_doda_response_path', sa.String(length=1000), nullable=True), + sa.Column('sat_original_chain', sa.Text(), nullable=True), + sa.Column('customs_clearance', sa.Integer(), nullable=True), + sa.Column('unique_badge_number', sa.String(length=250), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='doda_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_doda_company_id'), 'doda', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_doda_tenant_id'), 'doda', ['tenant_id'], unique=False, schema='a76') + op.create_table('electronic_notices', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('notice_number', sa.String(length=500), nullable=True), + sa.Column('year', sa.String(length=20), nullable=True), + sa.Column('patent', sa.String(length=4), nullable=True), + sa.Column('pedimento', sa.String(length=15), nullable=True), + sa.Column('file_sent', sa.String(length=1000), nullable=True), + sa.Column('file_response', sa.String(length=1000), nullable=True), + sa.Column('status', sa.String(length=100), nullable=True), + sa.Column('invoice', sa.String(length=50), nullable=True), + sa.Column('validation_acknowledgment', sa.String(length=20), nullable=True), + sa.Column('fea', sa.String(length=1000), nullable=True), + sa.Column('certificate_number', sa.String(length=50), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='electronic_notices_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_electronic_notices_company_id'), 'electronic_notices', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_electronic_notices_tenant_id'), 'electronic_notices', ['tenant_id'], unique=False, schema='a76') + op.create_table('equivalencies', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('identifier', sa.String(length=10), nullable=False), + sa.Column('description', sa.String(length=200), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('identifier', 'tenant_id', 'company_id', name='uq_equivalency_identifier'), + schema='a76' + ) + op.create_index(op.f('ix_a76_equivalencies_company_id'), 'equivalencies', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_equivalencies_tenant_id'), 'equivalencies', ['tenant_id'], unique=False, schema='a76') + op.create_table('error_classifications', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=100), nullable=False), + sa.Column('level', sa.String(length=3), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='error_classifications_pkey'), + sa.UniqueConstraint('code'), + sa.UniqueConstraint('code', name='error_classifications_code_unique'), + schema='a76' + ) + op.create_index(op.f('ix_a76_error_classifications_company_id'), 'error_classifications', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_error_classifications_tenant_id'), 'error_classifications', ['tenant_id'], unique=False, schema='a76') + op.create_table('exchange_rate', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('date', sa.DateTime(), nullable=False), + sa.Column('value', sa.DECIMAL(precision=13, scale=6), nullable=True), + sa.Column('local_currency', sa.String(length=7), nullable=True), + sa.Column('foreign_currency', sa.String(length=7), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='exchange_rate_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'date', name='uq_exchange_rate_date_tenant'), + schema='a76' + ) + op.create_index(op.f('ix_a76_exchange_rate_company_id'), 'exchange_rate', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_exchange_rate_tenant_id'), 'exchange_rate', ['tenant_id'], unique=False, schema='a76') + op.create_table('fraction_rule_octave', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('permission', sa.String(length=20), nullable=False), + sa.Column('line', sa.Integer(), nullable=False), + sa.Column('fraction', sa.String(length=10), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='fraction_rule_octave_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'permission', 'line', 'fraction', name='uq_fraction_rule_octave_permission_line_fraction'), + schema='a76' + ) + op.create_index(op.f('ix_a76_fraction_rule_octave_company_id'), 'fraction_rule_octave', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_fraction_rule_octave_tenant_id'), 'fraction_rule_octave', ['tenant_id'], unique=False, schema='a76') + op.create_table('identifiers', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=2), nullable=False), + sa.Column('description', sa.String(length=1000), nullable=True), + sa.Column('level', sa.String(length=1), nullable=True), + sa.Column('complement', sa.String(length=5000), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('code', name='uq_identifier_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_identifiers_company_id'), 'identifiers', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_identifiers_tenant_id'), 'identifiers', ['tenant_id'], unique=False, schema='a76') + op.create_table('inpc', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('year', sa.String(length=4), nullable=False), + sa.Column('month', sa.String(length=2), nullable=False), + sa.Column('value', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('year', 'month', 'tenant_id', 'company_id', name='uq_inpc_year_month'), + schema='a76' + ) + op.create_index(op.f('ix_a76_inpc_company_id'), 'inpc', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_inpc_tenant_id'), 'inpc', ['tenant_id'], unique=False, schema='a76') + op.create_table('invoice_header', + sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False), + sa.Column('system', sa.String(length=12), nullable=True), + sa.Column('operation_type', sa.String(length=10), nullable=False), + sa.Column('invoice_type', sa.String(length=5), nullable=True), + sa.Column('invoice_number', sa.String(length=20), nullable=True), + sa.Column('project_number', sa.String(length=14), nullable=True), + sa.Column('purchase_order', sa.String(length=50), nullable=True), + sa.Column('related_doc_id', sa.Integer(), nullable=True), + sa.Column('alternate_invoice', sa.String(length=99), nullable=True), + sa.Column('invoice_ref', sa.String(length=19), nullable=True), + sa.Column('proforma_number', sa.String(length=20), nullable=True), + sa.Column('invoice_date', sa.Date(), nullable=True), + sa.Column('capture_date', sa.TIMESTAMP(), nullable=False), + sa.Column('emission_date', sa.Date(), nullable=True), + sa.Column('is_updated', sa.Boolean(), nullable=True), + sa.Column('updated_date', sa.TIMESTAMP(), nullable=True), + sa.Column('who_updated', sa.String(length=20), nullable=True), + sa.Column('capture_user', sa.String(length=20), nullable=True), + sa.Column('traffic_light_status', sa.String(length=50), nullable=True), + sa.Column('process_log', sa.String(length=300), nullable=True), + sa.Column('status_rec', sa.Integer(), nullable=True), + sa.Column('status_rep', sa.String(length=2), nullable=True), + sa.Column('observation_es', sa.Text(), nullable=True), + sa.Column('observation_en', sa.Text(), nullable=True), + sa.Column('comments_status', sa.Text(), nullable=True), + sa.Column('vu_observations', sa.String(length=500), nullable=True), + sa.Column('cfdi_uuid', sa.String(length=100), nullable=True), + sa.Column('path_pdf', sa.String(length=500), nullable=True), + sa.Column('path_xml', sa.String(length=500), nullable=True), + sa.Column('subcompany', sa.String(length=5), nullable=True), + sa.Column('party_count', sa.Integer(), nullable=True), + sa.Column('generate_id', sa.String(length=1), nullable=True), + sa.Column('generate_desc_parties', sa.String(length=12), nullable=True), + sa.Column('apply_manual_discount', sa.String(length=1), nullable=True), + sa.Column('is_bulk', sa.Boolean(), nullable=True), + sa.Column('download_substance', sa.Boolean(), nullable=True), + sa.Column('download_class', sa.Boolean(), nullable=True), + sa.Column('download_def', sa.Boolean(), nullable=True), + sa.Column('payment_terms', sa.String(length=200), nullable=True), + sa.Column('handling_fees', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('option_iv18', sa.String(length=50), nullable=True), + sa.Column('enajenation_goods', sa.Boolean(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['invoice_type'], ['public.invoice_types.key'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_invoice_header_company_id'), 'invoice_header', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_invoice_header_tenant_id'), 'invoice_header', ['tenant_id'], unique=False, schema='a76') + op.create_table('legends', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.Integer(), nullable=False), + sa.Column('description', sa.String(length=2000), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_legend_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_legends_company_id'), 'legends', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_legends_tenant_id'), 'legends', ['tenant_id'], unique=False, schema='a76') + op.create_table('multi_currency_types', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('currency_type_code', sa.String(length=3), nullable=False), + sa.Column('country_key', sa.String(length=3), nullable=True), + sa.Column('conversion_factor', sa.Numeric(precision=13, scale=6), nullable=True), + sa.Column('publication_date', sa.Integer(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['country_key'], ['public.countries.m3_key'], ), + sa.ForeignKeyConstraint(['currency_type_code'], ['public.currency_types.code'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('currency_type_code', 'publication_date', 'tenant_id', 'company_id', name='uq_multi_currency_type_code_date'), + schema='a76' + ) + op.create_index(op.f('ix_a76_multi_currency_types_company_id'), 'multi_currency_types', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_multi_currency_types_tenant_id'), 'multi_currency_types', ['tenant_id'], unique=False, schema='a76') + op.create_table('packages', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('key', sa.String(length=5), nullable=False), + sa.Column('description_es', sa.String(length=40), nullable=True), + sa.Column('description_en', sa.String(length=40), nullable=True), + sa.Column('weight_unit', sa.DECIMAL(precision=19, scale=8), nullable=True), + sa.Column('plurals', sa.String(length=4), nullable=True), + sa.Column('plural_in', sa.String(length=4), nullable=True), + sa.Column('code_ace', sa.String(length=4), nullable=True), + sa.Column('code_aamex', sa.String(length=9), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='packages_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'key', name='packages_key_ukey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_packages_company_id'), 'packages', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_packages_tenant_id'), 'packages', ['tenant_id'], unique=False, schema='a76') + op.create_table('packing_lists', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('item_line_id', sa.Integer(), nullable=False), + sa.Column('packing_list_number', sa.String(length=100), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_packing_lists_company_id'), 'packing_lists', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_packing_lists_tenant_id'), 'packing_lists', ['tenant_id'], unique=False, schema='a76') + op.create_table('permission_rule_oct', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('permission', sa.String(length=20), nullable=False), + sa.Column('start_date', sa.Integer(), nullable=True), + sa.Column('end_date', sa.Integer(), nullable=True), + sa.Column('sector', sa.String(length=8), nullable=True), + sa.Column('system', sa.String(length=5), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='permission_rule_oct_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'permission', name='permission_rule_oct_permission_tenant_ukey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_permission_rule_oct_company_id'), 'permission_rule_oct', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_permission_rule_oct_tenant_id'), 'permission_rule_oct', ['tenant_id'], unique=False, schema='a76') + op.create_table('ports', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('port_code', sa.String(length=6), nullable=False), + sa.Column('description', sa.String(length=20), nullable=True), + sa.Column('location_code', sa.String(length=4), nullable=False), + sa.Column('location_description', sa.String(length=20), nullable=True), + sa.Column('port_type', sa.String(length=15), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('port_code', 'location_code', 'tenant_id', 'company_id', name='uq_port_location'), + schema='a76' + ) + op.create_index(op.f('ix_a76_ports_company_id'), 'ports', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_ports_tenant_id'), 'ports', ['tenant_id'], unique=False, schema='a76') + op.create_table('prevalidators', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('code', sa.String(length=20), nullable=False), + sa.Column('customs_prevalidator', sa.String(length=20), nullable=True), + sa.Column('patent_prevalidator', sa.String(length=20), nullable=True), + sa.Column('description', sa.String(length=50), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='prevalidators_pkey'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='prevalidators_code_unique'), + schema='a76' + ) + op.create_index(op.f('ix_a76_prevalidators_company_id'), 'prevalidators', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_prevalidators_tenant_id'), 'prevalidators', ['tenant_id'], unique=False, schema='a76') + op.create_table('seal', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('seal', sa.String(length=15), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='seal_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'seal', name='seal_ukey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_seal_company_id'), 'seal', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_seal_tenant_id'), 'seal', ['tenant_id'], unique=False, schema='a76') + op.create_table('signatures', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=10), nullable=False), + sa.Column('signature', sa.String(length=1000), nullable=True), + sa.Column('photo_path', sa.String(length=1000), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='signatures_pkey'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='signatures_code_unique'), + schema='a76' + ) + op.create_index(op.f('ix_a76_signatures_company_id'), 'signatures', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_signatures_tenant_id'), 'signatures', ['tenant_id'], unique=False, schema='a76') + op.create_table('subassembly_entries', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('remission_line', sa.Integer(), nullable=False), + sa.Column('exit_invoice', sa.String(length=15), nullable=True), + sa.Column('exit_line', sa.Integer(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_subassembly_entries_company_id'), 'subassembly_entries', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_subassembly_entries_tenant_id'), 'subassembly_entries', ['tenant_id'], unique=False, schema='a76') + op.create_table('trailer_type', + sa.Column('trailer_type_key', sa.String(length=2), nullable=False), + sa.Column('description', sa.String(length=100), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('trailer_type_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_trailer_type_company_id'), 'trailer_type', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_trailer_type_tenant_id'), 'trailer_type', ['tenant_id'], unique=False, schema='a76') + op.create_table('transporter', + sa.Column('transporter_key', sa.String(length=5), nullable=False), + sa.Column('name', sa.String(length=256), nullable=True), + sa.Column('short_name', sa.String(length=10), nullable=True), + sa.Column('responsible', sa.String(length=100), nullable=True), + sa.Column('rfc', sa.String(length=30), nullable=True), + sa.Column('streets', sa.String(length=100), nullable=True), + sa.Column('postal_code', sa.String(length=15), nullable=True), + sa.Column('city', sa.String(length=30), nullable=True), + sa.Column('state', sa.String(length=30), nullable=True), + sa.Column('country', sa.String(length=3), nullable=True), + sa.Column('loader_code', sa.String(length=9), nullable=True), + sa.Column('caat_code', sa.String(length=49), nullable=True), + sa.Column('transport_code', sa.String(length=8), nullable=True), + sa.Column('transport_interface_type', sa.String(length=20), nullable=True), + sa.Column('ftp_server', sa.String(length=200), nullable=True), + sa.Column('ftp_user', sa.String(length=200), nullable=True), + sa.Column('ftp_password', sa.String(length=100), nullable=True), + sa.Column('ftp_directory', sa.String(length=1000), nullable=True), + sa.Column('filler_code', sa.String(length=4), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('transporter_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_transporter_company_id'), 'transporter', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_transporter_tenant_id'), 'transporter', ['tenant_id'], unique=False, schema='a76') + op.create_table('unit_of_measure_ace', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=4), nullable=False), + sa.Column('description', sa.String(length=49), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_ace_code'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_ace_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_unit_of_measure_ace_company_id'), 'unit_of_measure_ace', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_unit_of_measure_ace_tenant_id'), 'unit_of_measure_ace', ['tenant_id'], unique=False, schema='a76') + op.create_table('unit_of_measure_american', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=3), nullable=False), + sa.Column('description', sa.String(length=40), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_american_code'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_american_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_unit_of_measure_american_company_id'), 'unit_of_measure_american', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_unit_of_measure_american_tenant_id'), 'unit_of_measure_american', ['tenant_id'], unique=False, schema='a76') + op.create_table('unit_of_measure_customs', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=2), nullable=False), + sa.Column('description', sa.String(length=20), nullable=True), + sa.Column('scaii_unit_code', sa.String(length=5), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_customs_code'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_customs_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_unit_of_measure_customs_company_id'), 'unit_of_measure_customs', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_unit_of_measure_customs_tenant_id'), 'unit_of_measure_customs', ['tenant_id'], unique=False, schema='a76') + op.create_table('unit_of_measure_oma', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=10), nullable=False), + sa.Column('description', sa.String(length=200), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_oma_code'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_oma_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_unit_of_measure_oma_company_id'), 'unit_of_measure_oma', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_unit_of_measure_oma_tenant_id'), 'unit_of_measure_oma', ['tenant_id'], unique=False, schema='a76') + op.create_table('units_of_measure', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=5), nullable=False), + sa.Column('description', sa.String(length=100), nullable=True), + sa.Column('description_en', sa.String(length=100), nullable=True), + sa.Column('customs_code', sa.String(length=2), nullable=True), + sa.Column('american_code', sa.String(length=3), nullable=True), + sa.Column('ace_code', sa.String(length=4), nullable=True), + sa.Column('oma_code', sa.String(length=10), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['ace_code', 'tenant_id', 'company_id'], ['a76.unit_of_measure_ace.code', 'a76.unit_of_measure_ace.tenant_id', 'a76.unit_of_measure_ace.company_id'], name='fk_uom_ace', use_alter=True), + sa.ForeignKeyConstraint(['american_code', 'tenant_id', 'company_id'], ['a76.unit_of_measure_american.code', 'a76.unit_of_measure_american.tenant_id', 'a76.unit_of_measure_american.company_id'], name='fk_uom_american', use_alter=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['customs_code', 'tenant_id', 'company_id'], ['a76.unit_of_measure_customs.code', 'a76.unit_of_measure_customs.tenant_id', 'a76.unit_of_measure_customs.company_id'], name='fk_uom_customs', use_alter=True), + sa.ForeignKeyConstraint(['oma_code', 'tenant_id', 'company_id'], ['a76.unit_of_measure_oma.code', 'a76.unit_of_measure_oma.tenant_id', 'a76.unit_of_measure_oma.company_id'], name='fk_uom_oma', use_alter=True), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_code'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_units_of_measure_company_id'), 'units_of_measure', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_units_of_measure_tenant_id'), 'units_of_measure', ['tenant_id'], unique=False, schema='a76') + op.create_table('units_of_measure_general', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=5), nullable=False), + sa.Column('description', sa.String(length=100), nullable=True), + sa.Column('conversion_factor', sa.Numeric(precision=13, scale=6), nullable=True), + sa.Column('mexico_unit', sa.String(length=5), nullable=True), + sa.Column('american_unit_code', sa.String(length=5), nullable=True), + sa.Column('customs_code', sa.String(length=2), nullable=True), + sa.Column('ace_code', sa.String(length=4), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['ace_code', 'tenant_id', 'company_id'], ['a76.unit_of_measure_ace.code', 'a76.unit_of_measure_ace.tenant_id', 'a76.unit_of_measure_ace.company_id'], name='fk_uom_general_ace', use_alter=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['customs_code', 'tenant_id', 'company_id'], ['a76.unit_of_measure_customs.code', 'a76.unit_of_measure_customs.tenant_id', 'a76.unit_of_measure_customs.company_id'], name='fk_uom_general_customs', use_alter=True), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_general_code'), + sa.UniqueConstraint('code', 'tenant_id', 'company_id', name='uq_uom_general_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_units_of_measure_general_company_id'), 'units_of_measure_general', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_units_of_measure_general_tenant_id'), 'units_of_measure_general', ['tenant_id'], unique=False, schema='a76') + op.create_table('vehicle', + sa.Column('vehicle_key', sa.String(length=14), nullable=False), + sa.Column('ace_vehicle_key', sa.String(length=10), nullable=True), + sa.Column('transporter_key', sa.String(length=23), nullable=True), + sa.Column('transport_identifier', sa.String(length=30), nullable=True), + sa.Column('transport_type', sa.String(length=2), nullable=True), + sa.Column('entity_code', sa.String(length=1), nullable=True), + sa.Column('transponder_number', sa.String(length=16), nullable=True), + sa.Column('dot_number', sa.String(length=8), nullable=True), + sa.Column('plate_number', sa.String(length=17), nullable=True), + sa.Column('city', sa.String(length=30), nullable=True), + sa.Column('state', sa.String(length=30), nullable=True), + sa.Column('country', sa.String(length=3), nullable=True), + sa.Column('seal', sa.String(length=49), nullable=True), + sa.Column('insurance_company_name', sa.String(length=30), nullable=True), + sa.Column('insurance_number', sa.String(length=20), nullable=True), + sa.Column('insurance_amount', sa.DECIMAL(precision=13, scale=2), nullable=True), + sa.Column('insurance_date', sa.Integer(), nullable=True), + sa.Column('box_number', sa.String(length=300), nullable=True), + sa.Column('brand', sa.String(length=20), nullable=True), + sa.Column('year', sa.String(length=4), nullable=True), + sa.Column('series', sa.String(length=30), nullable=True), + sa.Column('description', sa.String(length=100), nullable=True), + sa.Column('engine_number', sa.String(length=50), nullable=True), + sa.Column('sct_permission', sa.String(length=40), nullable=True), + sa.Column('color', sa.String(length=20), nullable=True), + sa.Column('container_key', sa.String(length=3), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('vehicle_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_vehicle_company_id'), 'vehicle', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_vehicle_tenant_id'), 'vehicle', ['tenant_id'], unique=False, schema='a76') + op.create_table('user_tenants', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('keycloak_user_id', sa.String(length=255), nullable=False), + sa.Column('is_active', sa.Boolean(), nullable=False), + sa.Column('role', sa.String(length=50), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('keycloak_user_id', 'tenant_id', 'company_id', name='uq_user_tenant'), + schema='core' + ) + op.create_index(op.f('ix_core_user_tenants_company_id'), 'user_tenants', ['company_id'], unique=False, schema='core') + op.create_index(op.f('ix_core_user_tenants_id'), 'user_tenants', ['id'], unique=False, schema='core') + op.create_index(op.f('ix_core_user_tenants_keycloak_user_id'), 'user_tenants', ['keycloak_user_id'], unique=False, schema='core') + op.create_index(op.f('ix_core_user_tenants_tenant_id'), 'user_tenants', ['tenant_id'], unique=False, schema='core') + op.create_table('classes', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('class_code', sa.String(length=8), nullable=False), + sa.Column('description_es', sa.String(length=500), nullable=True), + sa.Column('description_en', sa.String(length=500), nullable=True), + sa.Column('material_key', sa.String(length=10), nullable=True), + sa.Column('unit_of_measure', sa.String(length=5), nullable=True), + sa.Column('fraction', sa.String(length=10), nullable=True), + sa.Column('us_fraction', sa.String(length=16), nullable=True), + sa.Column('sub_key', sa.String(length=5), nullable=True), + sa.Column('physical_review', sa.SmallInteger(), nullable=True), + sa.Column('iva_exempt_fraction', sa.String(length=4), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['client_id'], ['a76.clients_and_providers.id'], name='fk_classes_client'), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['material_key'], ['public.material_types.key'], name='fk_classes_material_type'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.ForeignKeyConstraint(['unit_of_measure', 'tenant_id', 'company_id'], ['a76.units_of_measure.code', 'a76.units_of_measure.tenant_id', 'a76.units_of_measure.company_id'], ), + sa.PrimaryKeyConstraint('id', name='classes_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'client_id', 'class_code', name='ufa_classes_client_id_class_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_classes_company_id'), 'classes', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_classes_tenant_id'), 'classes', ['tenant_id'], unique=False, schema='a76') + op.create_table('clients_and_providers_address', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('municipality', sa.String(length=150), nullable=True), + sa.Column('streets', sa.String(length=100), nullable=True), + sa.Column('neighborhood', sa.String(length=40), nullable=True), + sa.Column('interior_number', sa.String(length=20), nullable=True), + sa.Column('exterior_number', sa.String(length=20), nullable=True), + sa.Column('postal_code', sa.String(length=15), nullable=True), + sa.Column('city', sa.String(length=30), nullable=True), + sa.Column('state', sa.String(length=30), nullable=True), + sa.Column('country', sa.String(length=3), nullable=True), + sa.Column('phone', sa.String(length=30), nullable=True), + sa.Column('fax_number', sa.String(length=30), nullable=True), + sa.Column('email', sa.String(length=100), nullable=True), + sa.Column('contact', sa.String(length=50), nullable=True), + sa.Column('reference', sa.String(length=250), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['client_id'], ['a76.clients_and_providers.id'], name='fk_clients_and_providers_address_client', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['client_id'], ['a76.clients_and_providers.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='clients_and_providers_address_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_clients_and_providers_address_company_id'), 'clients_and_providers_address', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_clients_and_providers_address_tenant_id'), 'clients_and_providers_address', ['tenant_id'], unique=False, schema='a76') + op.create_table('clients_and_providers_programs', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('program', sa.String(length=7), nullable=True), + sa.Column('program_number', sa.String(length=40), nullable=True), + sa.Column('prosec', sa.SmallInteger(), nullable=True), + sa.Column('prosec_authorization', sa.String(length=20), nullable=True), + sa.Column('secon_auth_date', sa.Integer(), nullable=True), + sa.Column('manufacturer_id', sa.String(length=25), nullable=True), + sa.Column('tax_id', sa.String(length=30), nullable=True), + sa.Column('broker', sa.String(length=6), nullable=True), + sa.Column('import_broker', sa.String(length=6), nullable=True), + sa.Column('transfer_key', sa.String(length=8), nullable=True), + sa.Column('secon_authorization', sa.String(length=20), nullable=True), + sa.Column('applied_proportion', sa.Numeric(precision=7, scale=2), nullable=True), + sa.Column('is_certified_company', sa.String(length=1), nullable=True), + sa.Column('certified_company_registry', sa.String(length=40), nullable=True), + sa.Column('donation_auth_number', sa.String(length=50), nullable=True), + sa.Column('ctpat_svi', sa.String(length=100), nullable=True), + sa.Column('tax_registry_number', sa.String(length=40), nullable=True), + sa.Column('subassembly_service', sa.SmallInteger(), nullable=True), + sa.Column('autse_dates', sa.Integer(), nullable=True), + sa.Column('autse_number', sa.String(length=300), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['client_id'], ['a76.clients_and_providers.id'], name='fk_clients_and_providers_programs_client', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['client_id'], ['a76.clients_and_providers.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='clients_and_providers_programs_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_clients_and_providers_programs_company_id'), 'clients_and_providers_programs', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_clients_and_providers_programs_tenant_id'), 'clients_and_providers_programs', ['tenant_id'], unique=False, schema='a76') + op.create_table('concepts', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('code', sa.String(length=15), nullable=False), + sa.Column('description', sa.String(length=120), nullable=True), + sa.Column('description_en', sa.String(length=120), nullable=True), + sa.Column('detailed_description', sa.String(length=1000), nullable=True), + sa.Column('priority', sa.Integer(), nullable=True), + sa.Column('priority_ame', sa.Integer(), nullable=True), + sa.Column('first_total', sa.Boolean(), nullable=True), + sa.Column('type', sa.String(length=9), nullable=True), + sa.Column('is_printed', sa.Boolean(), nullable=True), + sa.Column('section', sa.Integer(), nullable=True), + sa.Column('classification', sa.String(length=30), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['classification'], ['a76.classification_concepts.classification'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('code', name='uq_concept_code'), + schema='a76' + ) + op.create_index(op.f('ix_a76_concepts_tenant_id'), 'concepts', ['tenant_id'], unique=False, schema='a76') + op.create_table('country_rule_oct', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('permission', sa.String(length=20), nullable=False), + sa.Column('line', sa.Integer(), nullable=False), + sa.Column('fraction', sa.String(length=10), nullable=False), + sa.Column('country_code', sa.String(length=3), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id', 'company_id', 'permission', 'line', 'fraction'], ['a76.fraction_rule_octave.tenant_id', 'a76.fraction_rule_octave.company_id', 'a76.fraction_rule_octave.permission', 'a76.fraction_rule_octave.line', 'a76.fraction_rule_octave.fraction'], name='fk_country_rule_oct_frac_octava', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='country_rule_oct_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'permission', 'line', 'fraction', 'country_code', name='uq_country_rule_oct_permission_line_fraction_country'), + schema='a76' + ) + op.create_index(op.f('ix_a76_country_rule_oct_company_id'), 'country_rule_oct', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_country_rule_oct_tenant_id'), 'country_rule_oct', ['tenant_id'], unique=False, schema='a76') + op.create_table('customs_brokers_personnel', + sa.Column('customs_broker_id', sa.Integer(), nullable=False), + sa.Column('line', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=80), nullable=True), + sa.Column('tax_id', sa.String(length=30), nullable=True), + sa.Column('personal_id', sa.String(length=20), nullable=True), + sa.Column('position', sa.String(length=30), nullable=True), + sa.Column('license', sa.String(length=4), nullable=True), + sa.Column('first_name', sa.String(length=80), nullable=True), + sa.Column('last_name', sa.String(length=80), nullable=True), + sa.Column('middle_name', sa.String(length=80), nullable=True), + sa.Column('email', sa.String(length=100), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['customs_broker_id'], ['a76.customs_brokers.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('customs_broker_id', 'line'), + schema='a76' + ) + op.create_index(op.f('ix_a76_customs_brokers_personnel_company_id'), 'customs_brokers_personnel', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_customs_brokers_personnel_tenant_id'), 'customs_brokers_personnel', ['tenant_id'], unique=False, schema='a76') + op.create_table('customs_brokers_vu', + sa.Column('customs_broker_id', sa.Integer(), nullable=False), + sa.Column('certificate_path', sa.String(length=1499), nullable=True), + sa.Column('key_path', sa.String(length=1499), nullable=True), + sa.Column('access_key', sa.String(length=50), nullable=True), + sa.Column('fiel_format', sa.String(length=19), nullable=True), + sa.Column('signature_read_path', sa.String(length=1499), nullable=True), + sa.Column('archive_path', sa.String(length=1499), nullable=True), + sa.Column('fiel_access_key', sa.String(length=50), nullable=True), + sa.Column('web_service_user', sa.String(length=100), nullable=True), + sa.Column('web_service_access_key', sa.String(length=100), nullable=True), + sa.Column('vu_email', sa.String(length=800), nullable=True), + sa.Column('vu_figure_type', sa.String(length=29), nullable=True), + sa.Column('xml_files_path', sa.String(length=1499), nullable=True), + sa.Column('query_tax_id', sa.String(length=30), nullable=True), + sa.Column('doda_certificate_path', sa.String(length=1499), nullable=True), + sa.Column('doda_key_path', sa.String(length=1499), nullable=True), + sa.Column('doda_web_service_user', sa.String(length=100), nullable=True), + sa.Column('doda_web_service_access_key', sa.String(length=100), nullable=True), + sa.Column('doda_fiel_access_key', sa.String(length=50), nullable=True), + sa.Column('doda_xml_files_path', sa.String(length=1499), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['customs_broker_id'], ['a76.customs_brokers.id'], ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('customs_broker_id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_customs_brokers_vu_company_id'), 'customs_brokers_vu', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_customs_brokers_vu_tenant_id'), 'customs_brokers_vu', ['tenant_id'], unique=False, schema='a76') + op.create_table('doda_american_pedimentos', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('doda_id', sa.Integer(), nullable=False), + sa.Column('american_pedimento_line', sa.Integer(), nullable=False), + sa.Column('american_pedimento_type', sa.String(length=2), nullable=True), + sa.Column('american_pedimento_value', sa.String(length=20), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['doda_id'], ['a76.doda.id'], name='fk_doda_american_pedimentos_doda'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='doda_american_pedimentos_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_doda_american_pedimentos_company_id'), 'doda_american_pedimentos', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_doda_american_pedimentos_tenant_id'), 'doda_american_pedimentos', ['tenant_id'], unique=False, schema='a76') + op.create_table('doda_containers', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('doda_id', sa.Integer(), nullable=False), + sa.Column('container_line', sa.Integer(), nullable=False), + sa.Column('container_value', sa.String(length=20), nullable=True), + sa.Column('seals', sa.String(length=254), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['doda_id'], ['a76.doda.id'], name='fk_doda_containers_doda'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='doda_containers_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_doda_containers_company_id'), 'doda_containers', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_doda_containers_tenant_id'), 'doda_containers', ['tenant_id'], unique=False, schema='a76') + op.create_table('doda_pedimentos', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('doda_id', sa.Integer(), nullable=False), + sa.Column('pedimento_line', sa.Integer(), nullable=False), + sa.Column('authorization_patent', sa.String(length=10), nullable=True), + sa.Column('document', sa.String(length=50), nullable=True), + sa.Column('shipment', sa.String(length=11), nullable=True), + sa.Column('cove', sa.String(length=50), nullable=True), + sa.Column('umc', sa.String(length=20), nullable=True), + sa.Column('effective_amount_usd', sa.Numeric(precision=15, scale=2), nullable=True), + sa.Column('difference_amount_usd', sa.Numeric(precision=15, scale=2), nullable=True), + sa.Column('dta_niu', sa.String(length=20), nullable=True), + sa.Column('article_7', sa.Boolean(), nullable=True), + sa.Column('pedimento_id', sa.Integer(), nullable=True), + sa.Column('invoice_line', sa.Integer(), nullable=True), + sa.Column('part_ii_line', sa.Integer(), nullable=True), + sa.Column('pedimento_type', sa.String(length=20), nullable=True), + sa.Column('zero_packaging_validation', sa.Boolean(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['doda_id'], ['a76.doda.id'], name='fk_doda_pedimentos_doda'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='doda_pedimentos_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_doda_pedimentos_company_id'), 'doda_pedimentos', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_doda_pedimentos_tenant_id'), 'doda_pedimentos', ['tenant_id'], unique=False, schema='a76') + op.create_table('driver', + sa.Column('transporter_key', sa.String(length=5), nullable=False), + sa.Column('line', sa.Integer(), nullable=False), + sa.Column('driver_name', sa.String(length=80), nullable=True), + sa.Column('license_number', sa.String(length=29), nullable=True), + sa.Column('express_line_id', sa.String(length=17), nullable=True), + sa.Column('ace_id', sa.String(length=20), nullable=True), + sa.Column('birth_date', sa.Integer(), nullable=True), + sa.Column('gender', sa.String(length=1), nullable=True), + sa.Column('birth_country', sa.String(length=3), nullable=True), + sa.Column('hazardous_material_auth', sa.String(length=2), nullable=True), + sa.Column('hazardous_material_state', sa.String(length=30), nullable=True), + sa.Column('first_name', sa.String(length=20), nullable=True), + sa.Column('last_name', sa.String(length=20), nullable=True), + sa.Column('id_key1', sa.String(length=40), nullable=True), + sa.Column('id_number1', sa.String(length=20), nullable=True), + sa.Column('id_state1', sa.String(length=30), nullable=True), + sa.Column('id_country1', sa.String(length=3), nullable=True), + sa.Column('id_key2', sa.String(length=40), nullable=True), + sa.Column('id_number2', sa.String(length=20), nullable=True), + sa.Column('id_state2', sa.String(length=30), nullable=True), + sa.Column('id_country2', sa.String(length=3), nullable=True), + sa.Column('badge_number', sa.String(length=20), nullable=True), + sa.Column('class_type', sa.String(length=1), nullable=True), + sa.Column('unique_badge_number', sa.String(length=100), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.ForeignKeyConstraint(['transporter_key'], ['a76.transporter.transporter_key'], ondelete='CASCADE'), + sa.PrimaryKeyConstraint('transporter_key', 'line'), + schema='a76' + ) + op.create_index(op.f('ix_a76_driver_company_id'), 'driver', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_driver_tenant_id'), 'driver', ['tenant_id'], unique=False, schema='a76') + op.create_table('equivalency_items', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('equivalency_id', sa.Integer(), nullable=False), + sa.Column('original_field', sa.String(length=100), nullable=False), + sa.Column('external_field', sa.String(length=100), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['equivalency_id'], ['a76.equivalencies.id'], ), + sa.ForeignKeyConstraint(['original_field', 'tenant_id', 'company_id'], ['a76.units_of_measure.code', 'a76.units_of_measure.tenant_id', 'a76.units_of_measure.company_id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('equivalency_id', 'original_field', 'external_field', 'tenant_id', 'company_id', name='uq_equivalency_item_fields'), + schema='a76' + ) + op.create_index(op.f('ix_a76_equivalency_items_company_id'), 'equivalency_items', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_equivalency_items_tenant_id'), 'equivalency_items', ['tenant_id'], unique=False, schema='a76') + op.create_table('error_catalogs', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('code', sa.String(length=15), nullable=False), + sa.Column('description', sa.String(length=255), nullable=True), + sa.Column('classification_id', sa.Integer(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['classification_id'], ['a76.error_classifications.id'], name='fk_error_catalogs_classification'), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='error_catalogs_pkey'), + sa.UniqueConstraint('code'), + sa.UniqueConstraint('code', name='error_catalogs_code_unique'), + schema='a76' + ) + op.create_index(op.f('ix_a76_error_catalogs_company_id'), 'error_catalogs', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_error_catalogs_tenant_id'), 'error_catalogs', ['tenant_id'], unique=False, schema='a76') + op.create_table('identifier_details', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('invoice_consecutive', sa.Integer(), nullable=True), + sa.Column('part_line', sa.Integer(), nullable=True), + sa.Column('identifier_code', sa.String(length=2), nullable=True), + sa.Column('module', sa.String(length=20), nullable=True), + sa.Column('complement1', sa.String(length=50), nullable=True), + sa.Column('complement2', sa.String(length=51), nullable=True), + sa.Column('complement3', sa.String(length=50), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['identifier_code'], ['a76.identifiers.code'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_identifier_details_company_id'), 'identifier_details', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_identifier_details_tenant_id'), 'identifier_details', ['tenant_id'], unique=False, schema='a76') + op.create_table('invoice_collections', + sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False), + sa.Column('invoice_id', sa.BigInteger(), nullable=False), + sa.Column('line_number', sa.Integer(), nullable=False), + sa.Column('invoice_number', sa.String(length=15), nullable=True), + sa.Column('concept', sa.String(length=100), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['invoice_id'], ['a76.invoice_header.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_invoice_collections_company_id'), 'invoice_collections', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_invoice_collections_tenant_id'), 'invoice_collections', ['tenant_id'], unique=False, schema='a76') + op.create_table('invoice_compliance_mx', + sa.Column('invoice_id', sa.BigInteger(), nullable=False), + sa.Column('pedimento', sa.String(length=19), nullable=True), + sa.Column('pedimento_code', sa.String(length=5), nullable=True), + sa.Column('pedimento_k1', sa.String(length=15), nullable=True), + sa.Column('remesa', sa.Integer(), nullable=True), + sa.Column('aduana', sa.String(length=3), nullable=True), + sa.Column('port_of_entry', sa.String(length=6), nullable=True), + sa.Column('destination', sa.String(length=3), nullable=True), + sa.Column('manifest_number', sa.String(length=15), nullable=True), + sa.Column('provider_header', sa.String(length=20), nullable=True), + sa.Column('provider_id', sa.Integer(), nullable=True), + sa.Column('sold_to_header', sa.String(length=20), nullable=True), + sa.Column('sold_to_id', sa.Integer(), nullable=True), + sa.Column('shipped_to_header', sa.String(length=20), nullable=True), + sa.Column('shipped_to_id', sa.Integer(), nullable=True), + sa.Column('shipped_by_header', sa.String(length=20), nullable=True), + sa.Column('shipped_by_id', sa.Integer(), nullable=True), + sa.Column('customs_broker_id', sa.Integer(), nullable=True), + sa.Column('customs_broker_us_id', sa.Integer(), nullable=True), + sa.Column('broker_invoice_num', sa.String(length=20), nullable=True), + sa.Column('broker_invoice_date', sa.Date(), nullable=True), + sa.Column('is_mixed', sa.Boolean(), nullable=True), + sa.Column('waste_type', sa.String(length=1), nullable=True), + sa.Column('scrap_type', sa.String(length=1), nullable=True), + sa.Column('appendix_17', sa.Integer(), nullable=True), + sa.Column('is_regime_change', sa.String(length=1), nullable=True), + sa.Column('which_exchange_rate', sa.String(length=5), nullable=True), + sa.Column('value_method', sa.String(length=2), nullable=True), + sa.Column('act_value', sa.String(length=5), nullable=True), + sa.Column('is_pedimento_pending', sa.Boolean(), nullable=True), + sa.Column('is_owner_of_goods', sa.String(length=2), nullable=True), + sa.Column('generate_balances', sa.String(length=2), nullable=True), + sa.Column('was_reviewed_by_company', sa.Boolean(), nullable=True), + sa.Column('edocument', 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('niu_number', sa.String(length=19), nullable=True), + sa.Column('bill_of_lading_count', sa.String(length=12), nullable=True), + sa.Column('addendum_vu', sa.String(length=204), nullable=True), + sa.Column('origin_destination_cove', sa.String(length=19), nullable=True), + sa.Column('vucem_operation_num', sa.String(length=19), nullable=True), + sa.Column('customs_person_line', sa.Integer(), nullable=True), + sa.Column('contingency_mode', sa.Boolean(), nullable=True), + sa.Column('enclosure', sa.String(length=4), nullable=True), + sa.Column('guide_type_to_identify', sa.String(length=1), nullable=True), + sa.Column('location', sa.String(length=200), nullable=True), + sa.Column('dot_code', sa.String(length=20), nullable=True), + sa.Column('subdivision', sa.String(length=20), nullable=True), + sa.Column('acts_as', sa.String(length=20), nullable=True), + sa.Column('movement_type', sa.String(length=31), nullable=True), + sa.Column('office_document', sa.String(length=30), nullable=True), + sa.Column('reason_export', sa.String(length=1), nullable=True), + sa.Column('signature_key', sa.String(length=10), nullable=True), + sa.Column('sem_id', sa.Integer(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['aduana'], ['public.customs_sections.customs_code'], ), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['customs_broker_id'], ['a76.customs_brokers.id'], ), + sa.ForeignKeyConstraint(['customs_broker_us_id'], ['a76.customs_brokers.id'], ), + sa.ForeignKeyConstraint(['invoice_id'], ['a76.invoice_header.id'], ), + sa.ForeignKeyConstraint(['provider_id'], ['a76.clients_and_providers.id'], ), + sa.ForeignKeyConstraint(['shipped_by_id'], ['a76.clients_and_providers.id'], ), + sa.ForeignKeyConstraint(['shipped_to_id'], ['a76.clients_and_providers.id'], ), + sa.ForeignKeyConstraint(['sold_to_id'], ['a76.clients_and_providers.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('invoice_id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_invoice_compliance_mx_company_id'), 'invoice_compliance_mx', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_invoice_compliance_mx_tenant_id'), 'invoice_compliance_mx', ['tenant_id'], unique=False, schema='a76') + op.create_table('invoice_financials', + sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False), + sa.Column('invoice_id', sa.BigInteger(), nullable=False), + sa.Column('currency', sa.String(length=3), nullable=True), + sa.Column('currency_type', sa.String(length=3), nullable=True), + sa.Column('exchange_rate', sa.Numeric(precision=13, scale=6), nullable=True), + sa.Column('exchange_rate_mm', sa.Numeric(precision=13, scale=6), nullable=True), + sa.Column('value_mn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_me', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('customs_value_mn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('customs_value_me', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('raw_material_value_mn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('raw_material_value_me', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('aggregate_value_mn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('aggregate_value_me', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('aggregate_value_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('mexican_value_mn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('mexican_value_me', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('mexican_value_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('national_packaging_mn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('national_packaging_me', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('national_packaging_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('freight', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('insurance', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('insurance_value', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('packaging', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('other_increments', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('total_increments_mn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('total_increments_me', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('iva_mn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('iva_me', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('iva_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('iva_factor', sa.String(length=10), nullable=True), + sa.Column('tax_value_me', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('seal_value_2500', sa.Boolean(), nullable=True), + sa.Column('total_quantity', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('gross_weight', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('net_weight', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('bundle_count', sa.Integer(), nullable=True), + sa.Column('weight_factor', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['currency_type'], ['public.currency_types.code'], ), + sa.ForeignKeyConstraint(['invoice_id'], ['a76.invoice_header.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_invoice_financials_company_id'), 'invoice_financials', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_invoice_financials_tenant_id'), 'invoice_financials', ['tenant_id'], unique=False, schema='a76') + op.create_table('invoice_logistics', + sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False), + sa.Column('invoice_id', sa.BigInteger(), nullable=False), + sa.Column('carrier_id', sa.String(length=10), nullable=True), + sa.Column('transport_id', sa.String(length=10), nullable=True), + sa.Column('transport_us_id', sa.String(length=10), nullable=True), + sa.Column('transport_type', sa.String(length=15), nullable=False), + sa.Column('transport_num', sa.String(length=20), nullable=True), + sa.Column('transport_mode', sa.String(length=15), nullable=True), + sa.Column('driver_name', sa.String(length=80), nullable=True), + sa.Column('is_rail', sa.String(length=2), nullable=True), + sa.Column('rail_id', sa.String(length=31), nullable=True), + sa.Column('vehicle_num', sa.String(length=20), nullable=True), + sa.Column('license_plate', sa.String(length=20), nullable=True), + sa.Column('license_plate_complete', sa.String(length=40), nullable=True), + sa.Column('trailer_num', sa.String(length=20), nullable=True), + sa.Column('seal_number', sa.String(length=15), nullable=True), + sa.Column('guide_number', sa.String(length=20), nullable=True), + sa.Column('bill_number', sa.String(length=15), nullable=True), + sa.Column('reference_number', sa.String(length=14), nullable=True), + sa.Column('shipment_number', sa.String(length=19), nullable=True), + sa.Column('incoterm', sa.String(length=5), nullable=True), + sa.Column('identifier_1', sa.String(length=2), nullable=True), + sa.Column('complement_1', sa.String(length=30), nullable=True), + sa.Column('identifier_2', sa.String(length=2), nullable=True), + sa.Column('complement_2', sa.String(length=30), nullable=True), + sa.Column('weight_type', sa.String(length=6), nullable=True), + sa.Column('container_types', sa.String(length=500), nullable=True), + sa.Column('vehicle_data', sa.String(length=500), nullable=True), + sa.Column('origin_location', sa.String(length=200), nullable=True), + sa.Column('destination_location', sa.String(length=200), nullable=True), + sa.Column('transport_itinerary', sa.String(length=1000), nullable=True), + sa.Column('destination_goods', sa.String(length=50), nullable=True), + sa.Column('entry_exit_date', sa.Date(), nullable=True), + sa.Column('delivery_date', sa.Date(), nullable=True), + sa.Column('delivered_status', sa.String(length=2), nullable=True), + sa.Column('received_by', sa.String(length=50), nullable=True), + sa.Column('payment_date', sa.Date(), nullable=True), + sa.Column('payment_receipt_num', sa.String(length=20), nullable=True), + sa.Column('is_ctm_process', sa.String(length=2), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['invoice_id'], ['a76.invoice_header.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_invoice_logistics_company_id'), 'invoice_logistics', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_invoice_logistics_tenant_id'), 'invoice_logistics', ['tenant_id'], unique=False, schema='a76') + op.create_table('invoice_sales_details', + sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False), + sa.Column('invoice_id', sa.BigInteger(), nullable=False), + sa.Column('line_number', sa.Integer(), nullable=False), + sa.Column('sales_order', sa.String(length=20), nullable=True), + sa.Column('colors_description', sa.String(length=49), nullable=True), + sa.Column('square_color_code', sa.String(length=1), nullable=True), + sa.Column('line_bundles', sa.Integer(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['invoice_id'], ['a76.invoice_header.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_invoice_sales_details_company_id'), 'invoice_sales_details', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_invoice_sales_details_tenant_id'), 'invoice_sales_details', ['tenant_id'], unique=False, schema='a76') + op.create_table('items', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('invoice_id', sa.BigInteger(), nullable=False), + sa.Column('reference_number', sa.String(length=20), nullable=True), + sa.Column('order', sa.String(length=50), nullable=True), + sa.Column('guide_number', sa.String(length=50), nullable=True), + sa.Column('depreciation_date', sa.Integer(), nullable=True), + sa.Column('rectification', sa.Boolean(), nullable=True), + sa.Column('warehouse', sa.String(length=30), nullable=True), + sa.Column('location', sa.String(length=200), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['invoice_id'], ['a76.invoice_header.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_items_company_id'), 'items', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_items_tenant_id'), 'items', ['tenant_id'], unique=False, schema='a76') + op.create_table('parts', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('part_number', sa.String(length=50), nullable=False), + sa.Column('fraction', sa.String(length=10), nullable=True), + sa.Column('description_spanish', sa.String(length=500), nullable=True), + sa.Column('description_english', sa.String(length=500), nullable=True), + sa.Column('part_class', sa.String(length=8), nullable=True), + sa.Column('material_type', sa.String(length=10), nullable=True), + sa.Column('unit_of_measure', sa.String(length=5), nullable=True), + sa.Column('commercial_part_number', sa.String(length=70), nullable=True), + sa.Column('country_of_origin', sa.String(length=3), nullable=True), + sa.Column('unit_cost', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('currency_type', sa.String(length=2), nullable=True), + sa.Column('currency_key', sa.String(length=3), nullable=True), + sa.Column('unit_weight', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('weight_type', sa.String(length=6), nullable=True), + sa.Column('us_fraction', sa.String(length=16), nullable=True), + sa.Column('fda_key', sa.String(length=20), nullable=True), + sa.Column('fcc_key', sa.String(length=30), nullable=True), + sa.Column('license_code', sa.String(length=3), nullable=True), + sa.Column('eccn', sa.String(length=20), nullable=True), + sa.Column('export_code', sa.String(length=2), nullable=True), + sa.Column('exclusion_symbol', sa.String(length=19), nullable=True), + sa.Column('supplier', sa.String(length=14), nullable=True), + sa.Column('alternate_unit_measure', sa.String(length=14), nullable=True), + sa.Column('added_value', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('is_active', sa.Boolean(), nullable=True), + sa.Column('creation_date', sa.Integer(), nullable=True), + sa.Column('modification_date', sa.Integer(), nullable=True), + sa.Column('modification_date_iso', sa.DateTime(), nullable=True), + sa.Column('part_photo', sa.String(length=255), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['country_of_origin'], ['public.countries.m3_key'], name='fk_parts_country'), + sa.ForeignKeyConstraint(['currency_key'], ['public.currency_types.code'], name='fk_parts_currency'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.ForeignKeyConstraint(['unit_of_measure', 'tenant_id', 'company_id'], ['a76.units_of_measure.code', 'a76.units_of_measure.tenant_id', 'a76.units_of_measure.company_id'], ), + sa.PrimaryKeyConstraint('id', name='parts_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'part_number', name='client_part_ukey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_parts_company_id'), 'parts', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_parts_tenant_id'), 'parts', ['tenant_id'], unique=False, schema='a76') + op.create_table('pedimentos', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('year', sa.String(length=2), nullable=False), + sa.Column('customs_office', sa.String(length=3), nullable=False), + sa.Column('license', sa.String(length=4), nullable=False), + sa.Column('pedimento_number', sa.String(length=7), nullable=False), + sa.Column('client_id', sa.Integer(), nullable=False), + sa.Column('operation_type', sa.Integer(), nullable=False), + sa.Column('pedimento_type', sa.String(length=20), nullable=False), + sa.Column('pedimento_code', sa.String(length=2), nullable=False), + sa.Column('regime', sa.String(length=3), nullable=False), + 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('observations', sa.Text(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['client_id'], ['a76.clients_and_providers.id'], name='fk_pedimentos_client'), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_code'], ['public.pedimento_codes.code'], name='fk_pedimentos_code'), + sa.ForeignKeyConstraint(['regime'], ['public.pedimento_regimens.code'], name='fk_pedimentos_regime'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimentos_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'year', 'customs_office', 'license', 'pedimento_number', name='pedimentos_unique_key'), + 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_company_id'), 'pedimentos', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_pedimentos_tenant_id'), 'pedimentos', ['tenant_id'], unique=False, schema='a76') + op.create_table('trailer', + sa.Column('trailer_number', sa.String(length=20), nullable=False), + sa.Column('ace_trailer_number', sa.String(length=10), nullable=True), + sa.Column('trailer_type_key', sa.String(length=2), nullable=True), + sa.Column('seal', sa.String(length=15), nullable=True), + sa.Column('entity_code', sa.String(length=1), nullable=True), + sa.Column('plate_number', sa.String(length=17), nullable=True), + sa.Column('state', sa.String(length=30), nullable=True), + sa.Column('country', sa.String(length=3), nullable=True), + sa.Column('container_key', sa.String(length=3), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.ForeignKeyConstraint(['trailer_type_key'], ['a76.trailer_type.trailer_type_key'], ), + sa.PrimaryKeyConstraint('trailer_number'), + schema='a76' + ) + op.create_index(op.f('ix_a76_trailer_company_id'), 'trailer', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_trailer_tenant_id'), 'trailer', ['tenant_id'], unique=False, schema='a76') + op.create_table('unit_conversions', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('from_unit_code', sa.String(length=5), nullable=False), + sa.Column('to_unit_code', sa.String(length=5), nullable=False), + sa.Column('conversion_factor', sa.Numeric(precision=13, scale=6), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['from_unit_code', 'tenant_id', 'company_id'], ['a76.units_of_measure.code', 'a76.units_of_measure.tenant_id', 'a76.units_of_measure.company_id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.ForeignKeyConstraint(['to_unit_code', 'tenant_id', 'company_id'], ['a76.units_of_measure.code', 'a76.units_of_measure.tenant_id', 'a76.units_of_measure.company_id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('from_unit_code', 'to_unit_code', 'tenant_id', 'company_id', name='uq_unit_conversion_pair'), + schema='a76' + ) + op.create_index(op.f('ix_a76_unit_conversions_company_id'), 'unit_conversions', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_unit_conversions_tenant_id'), 'unit_conversions', ['tenant_id'], unique=False, schema='a76') + op.create_table('fa_classes', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('class_id', sa.Integer(), nullable=False), + sa.Column('import_tariff_code', sa.String(length=10), nullable=False), + sa.Column('import_tariff_type', sa.String(length=6), nullable=False), + sa.Column('export_tariff_code', sa.String(length=10), nullable=False), + sa.Column('export_tariff_type', sa.String(length=6), nullable=False), + sa.Column('depreciation_rate', sa.Numeric(precision=5, scale=2), nullable=False), + sa.Column('fda_code', sa.String(length=20), nullable=False), + sa.Column('eccn_code', sa.String(length=20), nullable=False), + sa.Column('class_enabled', sa.Boolean(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['class_id'], ['a76.classes.id'], name='fk_qclasses_classes'), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='qclases_pk'), + schema='a24' + ) + op.create_index(op.f('ix_a24_fa_classes_company_id'), 'fa_classes', ['company_id'], unique=False, schema='a24') + op.create_index(op.f('ix_a24_fa_classes_tenant_id'), 'fa_classes', ['tenant_id'], unique=False, schema='a24') + op.create_table('inv_classes', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('class_id', sa.Integer(), nullable=False), + sa.Column('stock_um', sa.String(length=5), nullable=False), + sa.Column('us_tariff_code', sa.String(length=19), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['class_id'], ['a76.classes.id'], name='fk_sclasses_classes'), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='sclases_pk'), + schema='a24' + ) + op.create_index(op.f('ix_a24_inv_classes_company_id'), 'inv_classes', ['company_id'], unique=False, schema='a24') + op.create_index(op.f('ix_a24_inv_classes_tenant_id'), 'inv_classes', ['tenant_id'], unique=False, schema='a24') + op.create_table('line_items', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('item_id', sa.Integer(), nullable=False), + sa.Column('asset_number', sa.String(length=25), nullable=True), + sa.Column('asset_photo', sa.String(length=255), nullable=True), + sa.Column('equipment_message', sa.String(length=40), nullable=True), + sa.Column('invoice_type_asset', sa.String(length=6), nullable=True), + sa.Column('return_import_invoice', sa.String(length=15), nullable=True), + sa.Column('return_import_date', sa.Integer(), nullable=True), + sa.Column('movement_type_import', sa.String(length=3), nullable=True), + sa.Column('search_invoice', sa.String(length=15), nullable=True), + sa.Column('search_line', sa.Integer(), nullable=True), + sa.Column('search_type', sa.String(length=10), nullable=True), + sa.Column('download', sa.Boolean(), nullable=True), + sa.Column('own_equipment', sa.Boolean(), nullable=True), + sa.Column('omit_annex31', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['item_id'], ['a76.items.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a24' + ) + op.create_table('doda_container_seals', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('container_id', sa.Integer(), nullable=False), + sa.Column('doda_id', sa.Integer(), nullable=False), + sa.Column('seal_line', sa.Integer(), nullable=False), + sa.Column('seal_value', sa.String(length=21), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['container_id'], ['a76.doda_containers.id'], name='fk_doda_container_seals_container'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='doda_container_seals_pkey'), + schema='a76' + ) + op.create_index(op.f('ix_a76_doda_container_seals_company_id'), 'doda_container_seals', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_doda_container_seals_tenant_id'), 'doda_container_seals', ['tenant_id'], unique=False, schema='a76') + op.create_table('item_lines', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('item_id', sa.Integer(), nullable=False), + sa.Column('line_number', sa.Integer(), nullable=False), + sa.Column('part_number', sa.Integer(), nullable=True), + sa.Column('component_part_number', sa.Integer(), nullable=True), + sa.Column('class_code', sa.Integer(), nullable=True), + sa.Column('unit_of_measure', sa.Integer(), nullable=True), + sa.Column('alternate_unit', sa.Integer(), nullable=True), + sa.Column('uma_key', sa.String(length=2), nullable=True), + sa.Column('auxiliary_unit', sa.String(length=5), nullable=True), + sa.Column('permit_number', sa.String(length=20), nullable=True), + sa.Column('page_line', sa.String(length=10), nullable=True), + sa.Column('has_certificate', sa.Boolean(), nullable=True), + sa.Column('certificate_number', sa.String(length=10), nullable=True), + sa.Column('octave_permit', sa.String(length=20), nullable=True), + sa.Column('permits_ped', sa.String(length=500), nullable=True), + sa.Column('has_fda_code', sa.Boolean(), nullable=True), + sa.Column('fda_key', sa.String(length=10), nullable=True), + sa.Column('is_subitem', sa.Boolean(), nullable=True), + sa.Column('contains_subitems', sa.Boolean(), nullable=True), + sa.Column('includes_subitems', sa.Boolean(), nullable=True), + sa.Column('subitem_number', sa.Boolean(), nullable=True), + sa.Column('is_military_mcia', sa.Boolean(), nullable=True), + sa.Column('iv32_type_key', sa.String(length=5), nullable=True), + sa.Column('iv32_number', sa.String(length=35), nullable=True), + sa.Column('scrap_invoice', sa.String(length=15), nullable=True), + sa.Column('consecutive_destination', sa.Integer(), nullable=True), + sa.Column('ctm_section', sa.String(length=3), nullable=True), + sa.Column('tax_payment', sa.Boolean(), nullable=True), + sa.Column('payment_method', sa.String(length=9), nullable=True), + sa.Column('igi_amount', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('igi_payment_method', sa.String(length=9), nullable=True), + sa.Column('fcc_key', sa.String(length=30), nullable=True), + sa.Column('valuation_method', sa.String(length=2), nullable=True), + sa.Column('valuation_determined_value', sa.Numeric(precision=29, scale=8), nullable=True), + sa.Column('valuation_reason', sa.String(length=500), nullable=True), + sa.Column('container_rule', sa.String(length=50), nullable=True), + sa.Column('container_parts_ii', sa.String(length=50), nullable=True), + sa.Column('consecutive_aphis', sa.Integer(), nullable=True), + sa.Column('bom_version', sa.Integer(), nullable=True), + sa.Column('bill_version', sa.Integer(), nullable=True), + sa.Column('tlcan_value', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('identifier', sa.String(length=2), nullable=True), + sa.Column('validation_zero', sa.Integer(), nullable=True), + sa.Column('validation_one', sa.Integer(), nullable=True), + sa.Column('material_type', sa.String(length=50), nullable=True), + sa.Column('order_type', sa.String(length=50), nullable=True), + sa.Column('line_concept', sa.String(length=50), nullable=True), + sa.Column('review_dispatch', sa.String(length=10), nullable=True), + sa.Column('take_component_pt', sa.Integer(), nullable=True), + sa.Column('pallet2', sa.SmallInteger(), nullable=True), + sa.Column('wildcard_field', sa.String(length=100), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['alternate_unit'], ['a76.units_of_measure_general.id'], ), + sa.ForeignKeyConstraint(['class_code'], ['a76.classes.id'], ), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['component_part_number'], ['a76.parts.id'], ), + sa.ForeignKeyConstraint(['item_id'], ['a76.items.id'], ), + sa.ForeignKeyConstraint(['part_number'], ['a76.parts.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.ForeignKeyConstraint(['unit_of_measure'], ['a76.units_of_measure_general.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_item_lines_company_id'), 'item_lines', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_item_lines_tenant_id'), 'item_lines', ['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('add_po_identifier', sa.SmallInteger(), nullable=False), + sa.Column('do_not_exempt_norms_complement_x', sa.SmallInteger(), nullable=False), + sa.Column('manual_pedimento_year', sa.String(length=2), nullable=False), + sa.Column('enable_import_invoice_recipient', sa.SmallInteger(), nullable=False), + sa.Column('send_502_validation_file_for_consolidated', sa.SmallInteger(), nullable=False), + sa.Column('add_remove_norms', sa.SmallInteger(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_additional', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_config_additional_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_config_additional_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_config_additional_company_id'), 'pedimento_config_additional', ['company_id'], unique=False, 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('dta_type', sa.String(length=1), nullable=True), + sa.Column('dta_operation', sa.Boolean(), server_default='false', nullable=False), + sa.Column('dta_vehicle_count', sa.SmallInteger(), server_default='0', nullable=False), + sa.Column('dta_mixed_rate_8permil', sa.Boolean(), server_default='false', nullable=False), + sa.Column('pays_vat', sa.Boolean(), server_default='false', nullable=False), + sa.Column('pays_prevalidation', sa.Boolean(), server_default='false', nullable=False), + sa.Column('include_sagar_certificate_fee', sa.Boolean(), server_default='false', nullable=False), + sa.Column('fixed_vehicle_dta_fee', sa.Boolean(), server_default='false', nullable=False), + sa.Column('additional_fixed_fee', sa.SmallInteger(), server_default='0', nullable=False), + sa.Column('additional_fixed_fee_payment_method', sa.SmallInteger(), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_calculations', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_config_calculations_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_config_calculations_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_config_calculations_company_id'), 'pedimento_config_calculations', ['company_id'], unique=False, 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('is_embassy', sa.Boolean(), server_default='false', nullable=False), + sa.Column('embassy_dta', sa.Numeric(precision=11, scale=2), server_default='0.00', nullable=False), + sa.Column('rule_3121_section_ii', sa.Boolean(), server_default='false', nullable=False), + sa.Column('use_previous_tariff', sa.Boolean(), server_default='false', nullable=False), + sa.Column('use_payment_date_fi', sa.Boolean(), server_default='false', nullable=False), + sa.Column('add_state_supplier_record_505', sa.Boolean(), server_default='false', nullable=False), + sa.Column('customs_value_calculation', sa.Boolean(), server_default='false', nullable=False), + sa.Column('two_decimals_unit_value', sa.Boolean(), server_default='false', nullable=False), + sa.Column('customs_value_per_item', sa.Boolean(), server_default='false', nullable=False), + sa.Column('is_national_supplier', sa.Boolean(), server_default='false', nullable=False), + sa.Column('is_consolidated', sa.Boolean(), server_default='false', nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_parameters', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_config_parameters_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_config_parameters_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_config_parameters_company_id'), 'pedimento_config_parameters', ['company_id'], unique=False, 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('surcharge_igi', sa.SmallInteger(), nullable=False), + sa.Column('surcharge_dta', sa.SmallInteger(), nullable=False), + sa.Column('surcharge_vat', sa.SmallInteger(), nullable=False), + sa.Column('surcharge_isan', sa.SmallInteger(), nullable=False), + sa.Column('surcharge_ieps', sa.SmallInteger(), nullable=False), + sa.Column('surcharge_cc', sa.SmallInteger(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_surcharges', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_config_surcharges_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_config_surcharges_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_config_surcharges_company_id'), 'pedimento_config_surcharges', ['company_id'], unique=False, 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('update_vat', sa.Boolean(), server_default='false', nullable=False), + sa.Column('update_advalorem', sa.Boolean(), server_default='false', nullable=False), + sa.Column('update_dta', sa.Boolean(), server_default='false', nullable=False), + sa.Column('update_cc', sa.Boolean(), server_default='false', nullable=False), + sa.Column('update_ieps', sa.Boolean(), server_default='false', nullable=False), + sa.Column('calculate_surcharge', sa.Boolean(), server_default='false', nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_update_rectification', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_config_update_rectification_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_config_update_rectification_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_config_update_rectification_company_id'), 'pedimento_config_update_rectification', ['company_id'], unique=False, 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('update_vat', sa.Boolean(), server_default='false', nullable=False), + sa.Column('update_advalorem', sa.Boolean(), server_default='false', nullable=False), + sa.Column('update_dta', sa.Boolean(), server_default='false', nullable=False), + sa.Column('update_cc', sa.Boolean(), server_default='false', nullable=False), + sa.Column('update_ieps', sa.Boolean(), server_default='false', nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_config_updates', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_config_updates_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_config_updates_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_config_updates_company_id'), 'pedimento_config_updates', ['company_id'], unique=False, 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('dispatch_customs', sa.String(length=3), nullable=False), + sa.Column('entry_exit_customs', sa.String(length=3), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_customs_offices', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_customs_offices_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_customs_offices_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_customs_offices_company_id'), 'pedimento_customs_offices', ['company_id'], unique=False, 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('entry_date', sa.DateTime(), nullable=True), + sa.Column('pedimento_date', sa.DateTime(), nullable=True), + sa.Column('payment_date', sa.DateTime(), nullable=False), + 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_time', sa.Time(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_dates', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_dates_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', '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_company_id'), 'pedimento_dates', ['company_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('freight', sa.Numeric(precision=13, scale=2), nullable=False), + sa.Column('insurance', sa.Numeric(precision=13, scale=2), nullable=False), + sa.Column('loading', sa.Numeric(precision=13, scale=2), nullable=False), + sa.Column('unloading', sa.Numeric(precision=13, scale=2), nullable=False), + sa.Column('others', sa.Numeric(precision=13, scale=2), nullable=False), + sa.Column('currency', sa.String(length=3), nullable=False), + sa.Column('currency_factor', sa.Numeric(precision=15, scale=8), nullable=False), + sa.Column('not_affect_usd_value', sa.SmallInteger(), nullable=False), + sa.Column('not_affect_customs_value', sa.SmallInteger(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_decrementables', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_decrementables_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_decrementables_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_decrementables_company_id'), 'pedimento_decrementables', ['company_id'], unique=False, 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('insured_value', sa.Numeric(precision=13, scale=2), nullable=False), + sa.Column('freight', sa.Numeric(precision=13, scale=2), nullable=False), + sa.Column('insurance', sa.Numeric(precision=13, scale=2), nullable=False), + sa.Column('packaging', sa.Numeric(precision=13, scale=2), nullable=False), + sa.Column('others', sa.Numeric(precision=13, scale=3), nullable=False), + sa.Column('deductibles', sa.Numeric(precision=13, scale=3), nullable=False), + sa.Column('currency', sa.String(length=3), nullable=False), + sa.Column('currency_factor', sa.Numeric(precision=15, scale=8), nullable=False), + sa.Column('not_affect_usd_value', sa.SmallInteger(), nullable=False), + sa.Column('not_affect_customs_value', sa.SmallInteger(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_incrementables', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_incrementables_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_incrementables_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_incrementables_company_id'), 'pedimento_incrementables', ['company_id'], unique=False, 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('update_factor_type', sa.SmallInteger(), nullable=False), + sa.Column('update_factor', sa.Numeric(precision=7, scale=4), nullable=False), + sa.Column('manual_update_factor', sa.SmallInteger(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_indexes', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_indexes_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_indexes_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_indexes_company_id'), 'pedimento_indexes', ['company_id'], unique=False, 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('acknowledgment', sa.String(length=20), nullable=False), + sa.Column('operation_number', sa.String(length=14), nullable=False), + sa.Column('bank_code', sa.Integer(), nullable=False), + sa.Column('cashier', sa.String(length=2), nullable=False), + sa.Column('date', sa.Date(), nullable=False), + sa.Column('time', sa.Time(), nullable=False), + sa.Column('shift', sa.String(length=1), nullable=False), + sa.Column('total_cash_paid', sa.Integer(), nullable=False), + sa.Column('total_contributions', sa.Integer(), nullable=False), + sa.Column('counter_payment', sa.SmallInteger(), nullable=False), + sa.Column('pece_code', sa.String(length=5), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_payments', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_payments_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', '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_company_id'), 'pedimento_payments', ['company_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('destination_pedimento_year', sa.String(length=2), nullable=False), + sa.Column('destination_customs_office', sa.String(length=3), nullable=False), + sa.Column('destination_license', sa.String(length=4), nullable=False), + sa.Column('destination_pedimento_number', sa.String(length=7), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_rectification_destination', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_rectification_destination_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_rectification_destination_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_rectification_destination_company_id'), 'pedimento_rectification_destination', ['company_id'], unique=False, 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('original_pedimento_year', sa.String(length=2), nullable=False), + sa.Column('original_customs_office', sa.String(length=3), nullable=False), + sa.Column('original_license', sa.String(length=4), nullable=False), + sa.Column('original_pedimento_number', sa.String(length=7), nullable=False), + sa.Column('original_pedimento_code', sa.String(length=2), nullable=False), + sa.Column('original_payment_date', sa.DateTime(), nullable=False), + sa.Column('total_cash', sa.Integer(), nullable=False), + sa.Column('total_others', sa.Integer(), nullable=False), + sa.Column('reason', sa.String(length=255), nullable=False), + sa.Column('charge_to_client', sa.SmallInteger(), nullable=False), + sa.Column('use_original_payment_date_for_interest_calc', sa.SmallInteger(), nullable=False), + sa.Column('manual_calculation', sa.SmallInteger(), nullable=False), + sa.Column('original_pedimento_norms', sa.SmallInteger(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_rectification_origin', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_rectification_origin_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_rectification_origin_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_rectification_origin_company_id'), 'pedimento_rectification_origin', ['company_id'], unique=False, 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('destination', sa.SmallInteger(), nullable=False), + sa.Column('entry_exit', sa.String(length=2), nullable=False), + sa.Column('arrival', sa.String(length=2), nullable=False), + sa.Column('departure', sa.String(length=2), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_transport_means', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_transport_means_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_transport_means_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_transport_means_company_id'), 'pedimento_transport_means', ['company_id'], unique=False, 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('validator', sa.String(length=3), nullable=False), + sa.Column('validation_ack', sa.String(length=8), nullable=False), + sa.Column('pre_ack', sa.String(length=8), nullable=False), + sa.Column('line_signature', sa.String(length=50), nullable=False), + sa.Column('electronic_signature', sa.String(length=999), nullable=False), + sa.Column('certificate_number', sa.String(length=99), nullable=False), + sa.Column('validator_id', sa.Integer(), nullable=False), + sa.Column('responsible_id', sa.Integer(), nullable=False), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['pedimento_id'], ['a76.pedimentos.id'], name='fk_pedimento_validation', ondelete='CASCADE'), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id', name='pedimento_validation_pkey'), + sa.UniqueConstraint('tenant_id', 'company_id', 'pedimento_id', name='pedimento_validation_pedimento_id_key'), + schema='a76' + ) + op.create_index(op.f('ix_a76_pedimento_validation_company_id'), 'pedimento_validation', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_pedimento_validation_tenant_id'), 'pedimento_validation', ['tenant_id'], unique=False, schema='a76') + op.create_table('ctm_receipts', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('receipt_line', sa.Integer(), nullable=False), + sa.Column('option', sa.String(length=3), nullable=True), + sa.Column('exit_invoice', sa.String(length=19), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['receipt_line'], ['a76.item_lines.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_ctm_receipts_company_id'), 'ctm_receipts', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_ctm_receipts_tenant_id'), 'ctm_receipts', ['tenant_id'], unique=False, schema='a76') + op.create_table('item_line_series', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('line_item_id', sa.Integer(), nullable=False), + sa.Column('row', sa.Integer(), nullable=False), + sa.Column('serial_numbers', sa.String(length=50), nullable=True), + sa.Column('model', sa.String(length=50), nullable=True), + sa.Column('sub_model', sa.String(length=50), nullable=True), + sa.Column('brand', sa.String(length=50), nullable=True), + sa.Column('expo_brad', sa.String(length=50), nullable=True), + sa.Column('number_id', sa.String(length=25), nullable=True), + sa.Column('tenant_id', sa.Integer(), nullable=False), + sa.Column('company_id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['company_id'], ['a76.company.id'], ), + sa.ForeignKeyConstraint(['line_item_id'], ['a76.item_lines.id'], ), + sa.ForeignKeyConstraint(['tenant_id'], ['core.tenants.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_index(op.f('ix_a76_item_line_series_company_id'), 'item_line_series', ['company_id'], unique=False, schema='a76') + op.create_index(op.f('ix_a76_item_line_series_tenant_id'), 'item_line_series', ['tenant_id'], unique=False, schema='a76') + op.create_table('line_customs', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('item_line_id', sa.Integer(), nullable=False), + sa.Column('fraction', sa.String(length=10), nullable=True), + sa.Column('fraction_type', sa.String(length=7), nullable=True), + sa.Column('american_fraction', sa.String(length=16), nullable=True), + sa.Column('alternate_fraction', sa.String(length=10), nullable=True), + sa.Column('reference_fraction', sa.String(length=10), nullable=True), + sa.Column('octave_fraction', sa.String(length=10), nullable=True), + sa.Column('tlcan_fraction', sa.String(length=13), nullable=True), + sa.Column('extra_american_fraction', sa.String(length=16), nullable=True), + sa.Column('garment_fraction', sa.String(length=19), nullable=True), + sa.Column('advalorem', sa.String(length=10), nullable=True), + sa.Column('advalorem_numeric', sa.Numeric(precision=7, scale=2), nullable=True), + sa.Column('advalorem_american', sa.Numeric(precision=5, scale=2), nullable=True), + sa.Column('advalorem_tlcan', sa.Numeric(precision=5, scale=2), nullable=True), + sa.Column('rate', sa.String(length=10), nullable=True), + sa.Column('depreciation_rate', sa.Numeric(precision=5, scale=2), nullable=True), + sa.Column('origin_country', sa.String(length=3), nullable=True), + sa.Column('destination_country', sa.String(length=3), nullable=True), + sa.Column('optional_country', sa.String(length=3), nullable=True), + sa.Column('origin_procedure', sa.String(length=3), nullable=True), + sa.Column('scrap_procedure', sa.String(length=3), nullable=True), + sa.Column('sector', sa.String(length=8), nullable=True), + sa.ForeignKeyConstraint(['item_line_id'], ['a76.item_lines.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_table('line_descriptions', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('item_line_id', sa.Integer(), nullable=False), + sa.Column('description_spanish', sa.String(length=4999), nullable=True), + sa.Column('description_english', sa.String(length=4999), nullable=True), + sa.Column('extra_description', sa.Text(), nullable=True), + sa.Column('part_description', sa.String(length=500), nullable=True), + sa.Column('class_description', sa.String(length=500), nullable=True), + sa.Column('brand', sa.String(length=50), nullable=True), + sa.Column('model', sa.String(length=50), nullable=True), + sa.Column('has_serial', sa.Boolean(), nullable=True), + sa.Column('additional_info_spanish', sa.String(length=1000), nullable=True), + sa.Column('additional_info_english', sa.String(length=1000), nullable=True), + sa.Column('lot', sa.String(length=254), nullable=True), + sa.Column('entry_number', sa.String(length=50), nullable=True), + sa.ForeignKeyConstraint(['item_line_id'], ['a76.item_lines.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_table('line_financials', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('item_line_id', sa.Integer(), nullable=False), + sa.Column('unit_cost_capture', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_commercial_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_current_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_depreciated_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_subitem_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_auxiliary_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('sales_cost_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('commercial_unit_cost', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_commercial_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_current_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_depreciated_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_subitem_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('sales_cost_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('unit_cost_mc', sa.Numeric(precision=29, scale=8), nullable=True), + sa.Column('value_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_commercial_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_updated_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_subitem_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('sub_import_value_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_returned_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_depreciated_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('customs_value_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_total_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_temp_material_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_def_material_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_added_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_national_packing_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('vat_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('vat_used_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('advalorem_line_mxn', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_usd', sa.Numeric(precision=29, scale=8), nullable=True), + sa.Column('value_commercial_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_updated_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_subitem_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('sub_import_value_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_returned_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_depreciated_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('customs_value_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_auxiliary_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_total_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_temp_material_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_def_material_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_added_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_national_packing_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_us_packing_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('vat_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('vat_used_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_non_originating_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_originating_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('igi_amount_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('exempt_amount_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('total_commercial_value', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('advalorem_line_usd', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_mc', sa.Numeric(precision=29, scale=8), nullable=True), + sa.Column('sub_import_value_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('vat_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_added_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_national_packing_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_total_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_temp_material_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.Column('value_def_material_mc', sa.Numeric(precision=23, scale=8), nullable=True), + sa.ForeignKeyConstraint(['item_line_id'], ['a76.item_lines.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_table('line_quantities', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('item_line_id', sa.Integer(), nullable=False), + sa.Column('quantity', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('alternate_quantity', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('quantity_uma', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('auxiliary_quantity', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('quantity_temp_export', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('quantity_existence', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('quantity_returned', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('quantity_returned_temp', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('serial_count', sa.Integer(), nullable=True), + sa.Column('weight_unit', sa.String(length=3), nullable=True), + sa.Column('net_weight', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('gross_weight', sa.Numeric(precision=19, scale=8), nullable=True), + sa.Column('package_key', sa.String(length=5), nullable=True), + sa.Column('package_quantity', sa.Integer(), nullable=True), + sa.Column('package_description', sa.String(length=40), nullable=True), + sa.Column('container_quantity', sa.SmallInteger(), nullable=True), + sa.Column('container_description', sa.String(length=40), nullable=True), + sa.Column('box_count', sa.String(length=30), nullable=True), + sa.ForeignKeyConstraint(['item_line_id'], ['a76.item_lines.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.create_table('line_references', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('item_line_id', sa.Integer(), nullable=False), + sa.Column('serie_id', sa.Integer(), nullable=True), + sa.Column('customer_invoice', sa.Integer(), nullable=True), + sa.Column('assigned_client', sa.Integer(), nullable=True), + sa.Column('supplier', sa.Integer(), nullable=True), + sa.Column('requisitioner', sa.Integer(), nullable=True), + sa.Column('sent_to', sa.Integer(), nullable=True), + sa.Column('ped_line', sa.Integer(), nullable=True), + sa.Column('ro_line', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['assigned_client'], ['a76.clients_and_providers.id'], ), + sa.ForeignKeyConstraint(['customer_invoice'], ['a76.clients_and_providers.id'], ), + sa.ForeignKeyConstraint(['item_line_id'], ['a76.item_lines.id'], ), + sa.ForeignKeyConstraint(['requisitioner'], ['a76.clients_and_providers.id'], ), + sa.ForeignKeyConstraint(['sent_to'], ['a76.clients_and_providers.id'], ), + sa.ForeignKeyConstraint(['serie_id'], ['a76.item_line_series.id'], ), + sa.ForeignKeyConstraint(['supplier'], ['a76.clients_and_providers.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='a76' + ) + op.drop_constraint(op.f('fk_codeped'), 'code_pedimento_regimens', type_='foreignkey') + op.drop_constraint(op.f('fk_regimenped'), '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_regimenped'), 'code_pedimento_regimens', 'pedimento_regimens', ['regimen_code'], ['code']) + op.create_foreign_key(op.f('fk_codeped'), 'code_pedimento_regimens', 'pedimento_codes', ['pedimento_code'], ['code']) + op.drop_table('line_references', schema='a76') + op.drop_table('line_quantities', schema='a76') + op.drop_table('line_financials', schema='a76') + op.drop_table('line_descriptions', schema='a76') + op.drop_table('line_customs', schema='a76') + op.drop_index(op.f('ix_a76_item_line_series_tenant_id'), table_name='item_line_series', schema='a76') + op.drop_index(op.f('ix_a76_item_line_series_company_id'), table_name='item_line_series', schema='a76') + op.drop_table('item_line_series', schema='a76') + op.drop_index(op.f('ix_a76_ctm_receipts_tenant_id'), table_name='ctm_receipts', schema='a76') + op.drop_index(op.f('ix_a76_ctm_receipts_company_id'), table_name='ctm_receipts', schema='a76') + op.drop_table('ctm_receipts', schema='a76') + op.drop_index(op.f('ix_a76_pedimento_validation_tenant_id'), table_name='pedimento_validation', schema='a76') + op.drop_index(op.f('ix_a76_pedimento_validation_company_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_index(op.f('ix_a76_pedimento_transport_means_company_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_index(op.f('ix_a76_pedimento_rectification_origin_company_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_index(op.f('ix_a76_pedimento_rectification_destination_company_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(op.f('ix_a76_pedimento_payments_company_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_index(op.f('ix_a76_pedimento_indexes_company_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_index(op.f('ix_a76_pedimento_incrementables_company_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_index(op.f('ix_a76_pedimento_decrementables_company_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(op.f('ix_a76_pedimento_dates_company_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_index(op.f('ix_a76_pedimento_customs_offices_company_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_index(op.f('ix_a76_pedimento_config_updates_company_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_index(op.f('ix_a76_pedimento_config_update_rectification_company_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_index(op.f('ix_a76_pedimento_config_surcharges_company_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_index(op.f('ix_a76_pedimento_config_parameters_company_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_index(op.f('ix_a76_pedimento_config_calculations_company_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_index(op.f('ix_a76_pedimento_config_additional_company_id'), table_name='pedimento_config_additional', schema='a76') + op.drop_table('pedimento_config_additional', schema='a76') + op.drop_index(op.f('ix_a76_item_lines_tenant_id'), table_name='item_lines', schema='a76') + op.drop_index(op.f('ix_a76_item_lines_company_id'), table_name='item_lines', schema='a76') + op.drop_table('item_lines', schema='a76') + op.drop_index(op.f('ix_a76_doda_container_seals_tenant_id'), table_name='doda_container_seals', schema='a76') + op.drop_index(op.f('ix_a76_doda_container_seals_company_id'), table_name='doda_container_seals', schema='a76') + op.drop_table('doda_container_seals', schema='a76') + op.drop_table('line_items', schema='a24') + op.drop_index(op.f('ix_a24_inv_classes_tenant_id'), table_name='inv_classes', schema='a24') + op.drop_index(op.f('ix_a24_inv_classes_company_id'), table_name='inv_classes', schema='a24') + op.drop_table('inv_classes', schema='a24') + op.drop_index(op.f('ix_a24_fa_classes_tenant_id'), table_name='fa_classes', schema='a24') + op.drop_index(op.f('ix_a24_fa_classes_company_id'), table_name='fa_classes', schema='a24') + op.drop_table('fa_classes', schema='a24') + op.drop_index(op.f('ix_a76_unit_conversions_tenant_id'), table_name='unit_conversions', schema='a76') + op.drop_index(op.f('ix_a76_unit_conversions_company_id'), table_name='unit_conversions', schema='a76') + op.drop_table('unit_conversions', schema='a76') + op.drop_index(op.f('ix_a76_trailer_tenant_id'), table_name='trailer', schema='a76') + op.drop_index(op.f('ix_a76_trailer_company_id'), table_name='trailer', schema='a76') + op.drop_table('trailer', schema='a76') + op.drop_index(op.f('ix_a76_pedimentos_tenant_id'), table_name='pedimentos', schema='a76') + op.drop_index(op.f('ix_a76_pedimentos_company_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_parts_tenant_id'), table_name='parts', schema='a76') + op.drop_index(op.f('ix_a76_parts_company_id'), table_name='parts', schema='a76') + op.drop_table('parts', schema='a76') + op.drop_index(op.f('ix_a76_items_tenant_id'), table_name='items', schema='a76') + op.drop_index(op.f('ix_a76_items_company_id'), table_name='items', schema='a76') + op.drop_table('items', schema='a76') + op.drop_index(op.f('ix_a76_invoice_sales_details_tenant_id'), table_name='invoice_sales_details', schema='a76') + op.drop_index(op.f('ix_a76_invoice_sales_details_company_id'), table_name='invoice_sales_details', schema='a76') + op.drop_table('invoice_sales_details', schema='a76') + op.drop_index(op.f('ix_a76_invoice_logistics_tenant_id'), table_name='invoice_logistics', schema='a76') + op.drop_index(op.f('ix_a76_invoice_logistics_company_id'), table_name='invoice_logistics', schema='a76') + op.drop_table('invoice_logistics', schema='a76') + op.drop_index(op.f('ix_a76_invoice_financials_tenant_id'), table_name='invoice_financials', schema='a76') + op.drop_index(op.f('ix_a76_invoice_financials_company_id'), table_name='invoice_financials', schema='a76') + op.drop_table('invoice_financials', schema='a76') + op.drop_index(op.f('ix_a76_invoice_compliance_mx_tenant_id'), table_name='invoice_compliance_mx', schema='a76') + op.drop_index(op.f('ix_a76_invoice_compliance_mx_company_id'), table_name='invoice_compliance_mx', schema='a76') + op.drop_table('invoice_compliance_mx', schema='a76') + op.drop_index(op.f('ix_a76_invoice_collections_tenant_id'), table_name='invoice_collections', schema='a76') + op.drop_index(op.f('ix_a76_invoice_collections_company_id'), table_name='invoice_collections', schema='a76') + op.drop_table('invoice_collections', schema='a76') + op.drop_index(op.f('ix_a76_identifier_details_tenant_id'), table_name='identifier_details', schema='a76') + op.drop_index(op.f('ix_a76_identifier_details_company_id'), table_name='identifier_details', schema='a76') + op.drop_table('identifier_details', schema='a76') + op.drop_index(op.f('ix_a76_error_catalogs_tenant_id'), table_name='error_catalogs', schema='a76') + op.drop_index(op.f('ix_a76_error_catalogs_company_id'), table_name='error_catalogs', schema='a76') + op.drop_table('error_catalogs', schema='a76') + op.drop_index(op.f('ix_a76_equivalency_items_tenant_id'), table_name='equivalency_items', schema='a76') + op.drop_index(op.f('ix_a76_equivalency_items_company_id'), table_name='equivalency_items', schema='a76') + op.drop_table('equivalency_items', schema='a76') + op.drop_index(op.f('ix_a76_driver_tenant_id'), table_name='driver', schema='a76') + op.drop_index(op.f('ix_a76_driver_company_id'), table_name='driver', schema='a76') + op.drop_table('driver', schema='a76') + op.drop_index(op.f('ix_a76_doda_pedimentos_tenant_id'), table_name='doda_pedimentos', schema='a76') + op.drop_index(op.f('ix_a76_doda_pedimentos_company_id'), table_name='doda_pedimentos', schema='a76') + op.drop_table('doda_pedimentos', schema='a76') + op.drop_index(op.f('ix_a76_doda_containers_tenant_id'), table_name='doda_containers', schema='a76') + op.drop_index(op.f('ix_a76_doda_containers_company_id'), table_name='doda_containers', schema='a76') + op.drop_table('doda_containers', schema='a76') + op.drop_index(op.f('ix_a76_doda_american_pedimentos_tenant_id'), table_name='doda_american_pedimentos', schema='a76') + op.drop_index(op.f('ix_a76_doda_american_pedimentos_company_id'), table_name='doda_american_pedimentos', schema='a76') + op.drop_table('doda_american_pedimentos', schema='a76') + op.drop_index(op.f('ix_a76_customs_brokers_vu_tenant_id'), table_name='customs_brokers_vu', schema='a76') + op.drop_index(op.f('ix_a76_customs_brokers_vu_company_id'), table_name='customs_brokers_vu', schema='a76') + op.drop_table('customs_brokers_vu', schema='a76') + op.drop_index(op.f('ix_a76_customs_brokers_personnel_tenant_id'), table_name='customs_brokers_personnel', schema='a76') + op.drop_index(op.f('ix_a76_customs_brokers_personnel_company_id'), table_name='customs_brokers_personnel', schema='a76') + op.drop_table('customs_brokers_personnel', schema='a76') + op.drop_index(op.f('ix_a76_country_rule_oct_tenant_id'), table_name='country_rule_oct', schema='a76') + op.drop_index(op.f('ix_a76_country_rule_oct_company_id'), table_name='country_rule_oct', schema='a76') + op.drop_table('country_rule_oct', schema='a76') + op.drop_index(op.f('ix_a76_concepts_tenant_id'), table_name='concepts', schema='a76') + op.drop_table('concepts', schema='a76') + op.drop_index(op.f('ix_a76_clients_and_providers_programs_tenant_id'), table_name='clients_and_providers_programs', schema='a76') + op.drop_index(op.f('ix_a76_clients_and_providers_programs_company_id'), table_name='clients_and_providers_programs', schema='a76') + op.drop_table('clients_and_providers_programs', schema='a76') + op.drop_index(op.f('ix_a76_clients_and_providers_address_tenant_id'), table_name='clients_and_providers_address', schema='a76') + op.drop_index(op.f('ix_a76_clients_and_providers_address_company_id'), table_name='clients_and_providers_address', schema='a76') + op.drop_table('clients_and_providers_address', schema='a76') + op.drop_index(op.f('ix_a76_classes_tenant_id'), table_name='classes', schema='a76') + op.drop_index(op.f('ix_a76_classes_company_id'), table_name='classes', schema='a76') + op.drop_table('classes', schema='a76') + op.drop_index(op.f('ix_core_user_tenants_tenant_id'), table_name='user_tenants', schema='core') + op.drop_index(op.f('ix_core_user_tenants_keycloak_user_id'), table_name='user_tenants', schema='core') + op.drop_index(op.f('ix_core_user_tenants_id'), table_name='user_tenants', schema='core') + op.drop_index(op.f('ix_core_user_tenants_company_id'), table_name='user_tenants', schema='core') + op.drop_table('user_tenants', schema='core') + op.drop_index(op.f('ix_a76_vehicle_tenant_id'), table_name='vehicle', schema='a76') + op.drop_index(op.f('ix_a76_vehicle_company_id'), table_name='vehicle', schema='a76') + op.drop_table('vehicle', schema='a76') + op.drop_index(op.f('ix_a76_units_of_measure_general_tenant_id'), table_name='units_of_measure_general', schema='a76') + op.drop_index(op.f('ix_a76_units_of_measure_general_company_id'), table_name='units_of_measure_general', schema='a76') + op.drop_table('units_of_measure_general', schema='a76') + op.drop_index(op.f('ix_a76_units_of_measure_tenant_id'), table_name='units_of_measure', schema='a76') + op.drop_index(op.f('ix_a76_units_of_measure_company_id'), table_name='units_of_measure', schema='a76') + op.drop_table('units_of_measure', schema='a76') + op.drop_index(op.f('ix_a76_unit_of_measure_oma_tenant_id'), table_name='unit_of_measure_oma', schema='a76') + op.drop_index(op.f('ix_a76_unit_of_measure_oma_company_id'), table_name='unit_of_measure_oma', schema='a76') + op.drop_table('unit_of_measure_oma', schema='a76') + op.drop_index(op.f('ix_a76_unit_of_measure_customs_tenant_id'), table_name='unit_of_measure_customs', schema='a76') + op.drop_index(op.f('ix_a76_unit_of_measure_customs_company_id'), table_name='unit_of_measure_customs', schema='a76') + op.drop_table('unit_of_measure_customs', schema='a76') + op.drop_index(op.f('ix_a76_unit_of_measure_american_tenant_id'), table_name='unit_of_measure_american', schema='a76') + op.drop_index(op.f('ix_a76_unit_of_measure_american_company_id'), table_name='unit_of_measure_american', schema='a76') + op.drop_table('unit_of_measure_american', schema='a76') + op.drop_index(op.f('ix_a76_unit_of_measure_ace_tenant_id'), table_name='unit_of_measure_ace', schema='a76') + op.drop_index(op.f('ix_a76_unit_of_measure_ace_company_id'), table_name='unit_of_measure_ace', schema='a76') + op.drop_table('unit_of_measure_ace', schema='a76') + op.drop_index(op.f('ix_a76_transporter_tenant_id'), table_name='transporter', schema='a76') + op.drop_index(op.f('ix_a76_transporter_company_id'), table_name='transporter', schema='a76') + op.drop_table('transporter', schema='a76') + op.drop_index(op.f('ix_a76_trailer_type_tenant_id'), table_name='trailer_type', schema='a76') + op.drop_index(op.f('ix_a76_trailer_type_company_id'), table_name='trailer_type', schema='a76') + op.drop_table('trailer_type', schema='a76') + op.drop_index(op.f('ix_a76_subassembly_entries_tenant_id'), table_name='subassembly_entries', schema='a76') + op.drop_index(op.f('ix_a76_subassembly_entries_company_id'), table_name='subassembly_entries', schema='a76') + op.drop_table('subassembly_entries', schema='a76') + op.drop_index(op.f('ix_a76_signatures_tenant_id'), table_name='signatures', schema='a76') + op.drop_index(op.f('ix_a76_signatures_company_id'), table_name='signatures', schema='a76') + op.drop_table('signatures', schema='a76') + op.drop_index(op.f('ix_a76_seal_tenant_id'), table_name='seal', schema='a76') + op.drop_index(op.f('ix_a76_seal_company_id'), table_name='seal', schema='a76') + op.drop_table('seal', schema='a76') + op.drop_index(op.f('ix_a76_prevalidators_tenant_id'), table_name='prevalidators', schema='a76') + op.drop_index(op.f('ix_a76_prevalidators_company_id'), table_name='prevalidators', schema='a76') + op.drop_table('prevalidators', schema='a76') + op.drop_index(op.f('ix_a76_ports_tenant_id'), table_name='ports', schema='a76') + op.drop_index(op.f('ix_a76_ports_company_id'), table_name='ports', schema='a76') + op.drop_table('ports', schema='a76') + op.drop_index(op.f('ix_a76_permission_rule_oct_tenant_id'), table_name='permission_rule_oct', schema='a76') + op.drop_index(op.f('ix_a76_permission_rule_oct_company_id'), table_name='permission_rule_oct', schema='a76') + op.drop_table('permission_rule_oct', schema='a76') + op.drop_index(op.f('ix_a76_packing_lists_tenant_id'), table_name='packing_lists', schema='a76') + op.drop_index(op.f('ix_a76_packing_lists_company_id'), table_name='packing_lists', schema='a76') + op.drop_table('packing_lists', schema='a76') + op.drop_index(op.f('ix_a76_packages_tenant_id'), table_name='packages', schema='a76') + op.drop_index(op.f('ix_a76_packages_company_id'), table_name='packages', schema='a76') + op.drop_table('packages', schema='a76') + op.drop_index(op.f('ix_a76_multi_currency_types_tenant_id'), table_name='multi_currency_types', schema='a76') + op.drop_index(op.f('ix_a76_multi_currency_types_company_id'), table_name='multi_currency_types', schema='a76') + op.drop_table('multi_currency_types', schema='a76') + op.drop_index(op.f('ix_a76_legends_tenant_id'), table_name='legends', schema='a76') + op.drop_index(op.f('ix_a76_legends_company_id'), table_name='legends', schema='a76') + op.drop_table('legends', schema='a76') + op.drop_index(op.f('ix_a76_invoice_header_tenant_id'), table_name='invoice_header', schema='a76') + op.drop_index(op.f('ix_a76_invoice_header_company_id'), table_name='invoice_header', schema='a76') + op.drop_table('invoice_header', schema='a76') + op.drop_index(op.f('ix_a76_inpc_tenant_id'), table_name='inpc', schema='a76') + op.drop_index(op.f('ix_a76_inpc_company_id'), table_name='inpc', schema='a76') + op.drop_table('inpc', schema='a76') + op.drop_index(op.f('ix_a76_identifiers_tenant_id'), table_name='identifiers', schema='a76') + op.drop_index(op.f('ix_a76_identifiers_company_id'), table_name='identifiers', schema='a76') + op.drop_table('identifiers', schema='a76') + op.drop_index(op.f('ix_a76_fraction_rule_octave_tenant_id'), table_name='fraction_rule_octave', schema='a76') + op.drop_index(op.f('ix_a76_fraction_rule_octave_company_id'), table_name='fraction_rule_octave', schema='a76') + op.drop_table('fraction_rule_octave', schema='a76') + op.drop_index(op.f('ix_a76_exchange_rate_tenant_id'), table_name='exchange_rate', schema='a76') + op.drop_index(op.f('ix_a76_exchange_rate_company_id'), table_name='exchange_rate', schema='a76') + op.drop_table('exchange_rate', schema='a76') + op.drop_index(op.f('ix_a76_error_classifications_tenant_id'), table_name='error_classifications', schema='a76') + op.drop_index(op.f('ix_a76_error_classifications_company_id'), table_name='error_classifications', schema='a76') + op.drop_table('error_classifications', schema='a76') + op.drop_index(op.f('ix_a76_equivalencies_tenant_id'), table_name='equivalencies', schema='a76') + op.drop_index(op.f('ix_a76_equivalencies_company_id'), table_name='equivalencies', schema='a76') + op.drop_table('equivalencies', schema='a76') + op.drop_index(op.f('ix_a76_electronic_notices_tenant_id'), table_name='electronic_notices', schema='a76') + op.drop_index(op.f('ix_a76_electronic_notices_company_id'), table_name='electronic_notices', schema='a76') + op.drop_table('electronic_notices', schema='a76') + op.drop_index(op.f('ix_a76_doda_tenant_id'), table_name='doda', schema='a76') + op.drop_index(op.f('ix_a76_doda_company_id'), table_name='doda', schema='a76') + op.drop_table('doda', schema='a76') + op.drop_index(op.f('ix_a76_customs_brokers_tenant_id'), table_name='customs_brokers', schema='a76') + op.drop_index(op.f('ix_a76_customs_brokers_company_id'), table_name='customs_brokers', schema='a76') + op.drop_table('customs_brokers', schema='a76') + op.drop_index(op.f('ix_a76_clients_and_providers_tenant_id'), table_name='clients_and_providers', schema='a76') + op.drop_index(op.f('ix_a76_clients_and_providers_company_id'), table_name='clients_and_providers', schema='a76') + op.drop_table('clients_and_providers', schema='a76') + op.drop_index(op.f('ix_a76_classification_concepts_tenant_id'), table_name='classification_concepts', schema='a76') + op.drop_index(op.f('ix_a76_classification_concepts_company_id'), table_name='classification_concepts', schema='a76') + op.drop_table('classification_concepts', schema='a76') + op.drop_index(op.f('ix_a24_location_tenant_id'), table_name='location', schema='a24') + op.drop_index(op.f('ix_a24_location_company_id'), table_name='location', schema='a24') + op.drop_table('location', schema='a24') + op.drop_index(op.f('ix_core_licenses_tenant_id'), table_name='licenses', schema='core') + op.drop_index(op.f('ix_core_licenses_id'), table_name='licenses', schema='core') + op.drop_table('licenses', schema='core') + op.drop_index(op.f('ix_core_license_usage_tenant_id'), table_name='license_usage', schema='core') + op.drop_index(op.f('ix_core_license_usage_id'), table_name='license_usage', schema='core') + op.drop_table('license_usage', schema='core') + op.drop_index(op.f('ix_a76_customs_broker_concepts_tenant_id'), table_name='customs_broker_concepts', schema='a76') + op.drop_table('customs_broker_concepts', schema='a76') + op.drop_index(op.f('ix_a76_company_tenant_id'), table_name='company', schema='a76') + op.drop_table('company', schema='a76') + op.drop_index(op.f('ix_core_tenants_slug'), table_name='tenants', schema='core') + op.drop_index(op.f('ix_core_tenants_name'), table_name='tenants', schema='core') + op.drop_index(op.f('ix_core_tenants_id'), table_name='tenants', schema='core') + op.drop_table('tenants', schema='core') + # ### end Alembic commands ### diff --git a/backend/api/v1/modules/a24/fa/fa_parts/models.py b/backend/api/v1/modules/a24/fa/fa_parts/models.py new file mode 100644 index 00000000..ba5bbe75 --- /dev/null +++ b/backend/api/v1/modules/a24/fa/fa_parts/models.py @@ -0,0 +1,48 @@ +""" +Modelo ORM para datos específicos de Activos Fijos (Q-Partes) - Anexo 24 +""" + +from typing import TYPE_CHECKING, Optional +from api.v1.common.base_models import TenantScopedMixin, TimestampMixin +from core.database import Base +from sqlalchemy import ( + Integer, + PrimaryKeyConstraint, + String, + ForeignKeyConstraint +) +from sqlalchemy.orm import Mapped, mapped_column, relationship + +if TYPE_CHECKING: + + from api.v1.modules.a76.parts.models import Part + + +class FaPart(Base, TenantScopedMixin, TimestampMixin): + """ + Tabla fa_partes: Extensión de Anexo 24 para Activos Fijos. + """ + + __tablename__ = "fa_partes" + __table_args__ = ( + PrimaryKeyConstraint("id", name="fa_partes_pkey"), + ForeignKeyConstraint( + ["id"], ["a76.parts.id"], name="fk_fa_partes_master" + ), + {"schema": "a24"}, + ) + + # El ID hereda el valor de la tabla parts + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=False) + + # --- CAMPOS ESPECÍFICOS FISCALES (Q-PARTES) --- + origin_country: Mapped[Optional[str]] = mapped_column(String(3)) # PAIS + sector: Mapped[Optional[str]] = mapped_column(String(8)) # SECTOR + fraction_type: Mapped[Optional[str]] = mapped_column(String(7)) # TIPOFRACCION + + # --- RELACIÓN --- + # Usamos string "Part" para evitar que truene al inicializar los mappers + master_info: Mapped["Part"] = relationship("Part", back_populates="fa_data") + + def __repr__(self) -> str: + return f"" \ No newline at end of file diff --git a/backend/api/v1/modules/a24/inv/inv_classes/models.py b/backend/api/v1/modules/a24/inv/inv_classes/models.py index 229e5502..47fc679f 100644 --- a/backend/api/v1/modules/a24/inv/inv_classes/models.py +++ b/backend/api/v1/modules/a24/inv/inv_classes/models.py @@ -8,7 +8,7 @@ class SClasses(Base, TenantScopedMixin, TimestampMixin): __tablename__ = "inv_classes" # SClases __table_args__ = ( ForeignKeyConstraint( - ["class_id"], ["a76.clases.class_id"], name="fk_sclasses_classes" + ["class_id"], ["a76.classes.id"], name="fk_sclasses_classes" ), PrimaryKeyConstraint("id", name="sclases_pk"), {"schema": "a24"}, diff --git a/backend/api/v1/modules/a24/inv/inv_parts/models.py b/backend/api/v1/modules/a24/inv/inv_parts/models.py new file mode 100644 index 00000000..467bbc2c --- /dev/null +++ b/backend/api/v1/modules/a24/inv/inv_parts/models.py @@ -0,0 +1,108 @@ +""" +Modelo ORM para datos específicos de Inventario y Manufactura (S-Partes) - Anexo 24 +""" + +from typing import TYPE_CHECKING, Optional +from decimal import Decimal +from api.v1.common.base_models import TenantScopedMixin, TimestampMixin +from core.database import Base +from sqlalchemy import ( + Integer, + Numeric, + PrimaryKeyConstraint, + String, + Boolean, + ForeignKeyConstraint +) +from sqlalchemy.orm import Mapped, mapped_column, relationship + +if TYPE_CHECKING: + + from api.v1.modules.a76.parts.models import Part + + +class InvPart(Base, TenantScopedMixin, TimestampMixin): + """ + Tabla inv_partes: Extensión de Anexo 24 para Inventarios (SPartes). + """ + + __tablename__ = "inv_partes" + __table_args__ = ( + PrimaryKeyConstraint("id", name="inv_partes_pkey"), + ForeignKeyConstraint( + ["id"], ["a76.parts.id"], name="fk_inv_partes_master" + ), + {"schema": "a24"}, + ) + + # Relación 1:1 - El ID es el mismo de la tabla maestra + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=False) + + # --- 1. ATRIBUTOS PRINCIPALES DE INVENTARIO --- + part_type: Mapped[Optional[str]] = mapped_column(String(10)) # TIPOPARTE + material_type: Mapped[Optional[str]] = mapped_column(String(10)) # TIPOMAT + + reference_number: Mapped[Optional[str]] = mapped_column(String(70)) # NUMPARTEREF + flex_reference_number: Mapped[Optional[str]] = mapped_column(String(120)) # NUMPARTEREFFLEX + + # Conversiones + equivalent_uom: Mapped[Optional[str]] = mapped_column(String(5)) # UNIMEDEQUIV + conversion_factor: Mapped[Optional[Decimal]] = mapped_column(Numeric(19, 8)) # FACTORCONV + + stock_uom: Mapped[Optional[str]] = mapped_column(String(5)) # UMEXISTENCIA + alternate_uom: Mapped[Optional[str]] = mapped_column(String(5)) # UNIMEDALTERNA + conversion_uom: Mapped[Optional[str]] = mapped_column(String(9)) # UMCONVERSION + + # Valor Agregado + added_value: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) # VALORAGREGADO + added_value_type: Mapped[Optional[str]] = mapped_column(String(2)) # TIPOVA + + assigned_client: Mapped[Optional[str]] = mapped_column(String(50)) # CLIENTEASIGNADO + supplier_code: Mapped[Optional[str]] = mapped_column(String(8)) # PROVEEDOR + is_textile: Mapped[Optional[str]] = mapped_column(String(2)) # ESTEXTIL + + # --- 2. MANUFACTURA Y PELIGROSIDAD --- + bom_version: Mapped[Optional[int]] = mapped_column(Integer) # VERSIONBOM / VERSIONBILL + is_repair: Mapped[Optional[str]] = mapped_column(String(3)) # ESREPARACION + is_hazardous: Mapped[Optional[str]] = mapped_column(String(1)) # ESMATPELIGROSO + + emergency_number: Mapped[Optional[str]] = mapped_column(String(30)) # NUMEMERGENCIA + danger_class: Mapped[Optional[str]] = mapped_column(String(4)) # CLASEDEPELIGRO + packaging_group: Mapped[Optional[str]] = mapped_column(String(3)) # GRUPOEMBALAJE + + # Dimensiones + width: Mapped[Optional[str]] = mapped_column(String(50)) # ANCHURA + thickness: Mapped[Optional[str]] = mapped_column(String(50)) # ESPESOR + specification: Mapped[Optional[str]] = mapped_column(String(50)) # SPEC + + # --- 3. COSTOS DETALLADOS Y ADUANA US --- + total_value: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) # VALORTOTAL + direct_labor: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) # TRABAJODIREC + general_expenses: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) # GASTOGRALES + total_expenses: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) # TOTALGASTOS + + depreciation: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) # DEPRECIACION + tooling: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) # TOOLING + material_consumed: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) # MATCONSUMED + profit: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) # GANANCIA + + # Fracciones Internacionales + us_fraction_alt: Mapped[Optional[str]] = mapped_column(String(13)) # FRACEUA + ca_fraction: Mapped[Optional[str]] = mapped_column(String(13)) # FRACCANADA + ad_valorem_us: Mapped[Optional[Decimal]] = mapped_column(Numeric(5, 2)) # ADVALOREMAME + + # Nafta / USMCA + nafta_result: Mapped[Optional[str]] = mapped_column(String(19)) # RESULTADOCALCULONAFTA + nafta_percentage: Mapped[Optional[Decimal]] = mapped_column(Numeric(5, 2)) # PORCENTAJECALCULONAFTA + + # Impuestos Específicos (Derechos de Trámite Admon) + dta: Mapped[Optional[str]] = mapped_column(String(19)) # DTA + dtb: Mapped[Optional[str]] = mapped_column(String(19)) # DTB + dtg: Mapped[Optional[str]] = mapped_column(String(19)) # DTG + + # --- RELACIÓN --- + # Usamos string "Part" para evitar problemas de carga + master_info: Mapped["Part"] = relationship("Part", back_populates="inv_data") + + def __repr__(self) -> str: + return f"" \ No newline at end of file diff --git a/backend/api/v1/modules/a24/router.py b/backend/api/v1/modules/a24/router.py new file mode 100644 index 00000000..c0da4ed5 --- /dev/null +++ b/backend/api/v1/modules/a24/router.py @@ -0,0 +1,10 @@ +from fastapi import APIRouter +from .fa.fa_parts.models import FaPart as fa_model +from .inv.inv_parts.models import InvPart as inv_model + +router = APIRouter(prefix="/a24", tags=["Anexo 24"]) + +@router.get("/check") +def check(): + return {"status": "Anexo 24 module is operational."} + diff --git a/backend/api/v1/modules/a76/clients_and_providers/dto.py b/backend/api/v1/modules/a76/clients_and_providers/dto.py index f77df843..624c99f1 100644 --- a/backend/api/v1/modules/a76/clients_and_providers/dto.py +++ b/backend/api/v1/modules/a76/clients_and_providers/dto.py @@ -116,9 +116,7 @@ class ClientProviderCreateDTO(BaseModel): ) position: Optional[str] = Field(None, max_length=30, description="Position") incoterm: Optional[str] = Field(None, max_length=19, description="Incoterm") - is_national_provider: Optional[str] = Field( - None, max_length=2, description="Is national provider" - ) + is_national_provider: Optional[bool] = None is_active: Optional[bool] = Field(None, description="Enabled/Disabled status") # Nested DTOs @@ -159,9 +157,7 @@ class ClientProviderUpdateDTO(BaseModel): ) position: Optional[str] = Field(None, max_length=30, description="Position") incoterm: Optional[str] = Field(None, max_length=19, description="Incoterm") - is_national_provider: Optional[str] = Field( - None, max_length=2, description="Is national provider" - ) + is_national_provider: Optional[bool] = None is_active: Optional[bool] = Field(None, description="Enabled/Disabled status") # Nested DTOs @@ -193,7 +189,7 @@ class ClientProviderResponseDTO(BaseModel): responsible: Optional[str] = None position: Optional[str] = None incoterm: Optional[str] = None - is_national_provider: Optional[str] = None + is_national_provider: Optional[bool] = None is_active: Optional[bool] = None tenant_id: int company_id: int diff --git a/backend/api/v1/modules/a76/parts/dto.py b/backend/api/v1/modules/a76/parts/dto.py index e21e7772..0273bd68 100644 --- a/backend/api/v1/modules/a76/parts/dto.py +++ b/backend/api/v1/modules/a76/parts/dto.py @@ -1,232 +1,137 @@ -""" -DTOs (Data Transfer Objects) para módulo de partes/componentes -Reemplaza schemas.py siguiendo enfoque DDD y estilo NestJS -""" - from datetime import datetime from decimal import Decimal -from typing import Optional +from typing import List, Optional +from pydantic import BaseModel, Field, ConfigDict -from pydantic import BaseModel, Field +# --- SUB-DTO: DATOS ADUANALES (FaData) --- +class FaDataDTO(BaseModel): + origin_country: Optional[str] = None + sector: Optional[str] = None + fraction_type: Optional[str] = None + + model_config = ConfigDict(from_attributes=True) + +# --- SUB-DTO: DATOS DE INVENTARIO Y COSTEO (InvData) --- +class InvDataDTO(BaseModel): + part_type: Optional[str] = None + material_type: Optional[str] = None + reference_number: Optional[str] = None + flex_reference_number: Optional[str] = None + equivalent_uom: Optional[str] = None + conversion_factor: Optional[Decimal] = None + stock_uom: Optional[str] = None + alternate_uom: Optional[str] = None + conversion_uom: Optional[str] = None + added_value: Optional[Decimal] = None + added_value_type: Optional[str] = None + assigned_client: Optional[str] = None + supplier_code: Optional[str] = None + is_textile: Optional[str] = None + bom_version: Optional[int] = None + is_repair: Optional[str] = None + is_hazardous: Optional[str] = None + emergency_number: Optional[str] = None + danger_class: Optional[str] = None + packaging_group: Optional[str] = None + width: Optional[str] = None + thickness: Optional[str] = None + specification: Optional[str] = None + + # Desglose de Costos (Anexo 24 - Valor Agregado) + total_value: Optional[Decimal] = None + direct_labor: Optional[Decimal] = None + general_expenses: Optional[Decimal] = None + total_expenses: Optional[Decimal] = None + depreciation: Optional[Decimal] = None + tooling: Optional[Decimal] = None + material_consumed: Optional[Decimal] = None + profit: Optional[Decimal] = None + + # Fracciones adicionales y TLCAN/T-MEC + us_fraction_alt: Optional[str] = None + ca_fraction: Optional[str] = None + ad_valorem_us: Optional[Decimal] = None + nafta_result: Optional[str] = None + nafta_percentage: Optional[Decimal] = None + dta: Optional[str] = None + dtb: Optional[str] = None + dtg: Optional[str] = None + + model_config = ConfigDict(from_attributes=True) -class PartCreateDTO(BaseModel): - """DTO para crear una parte""" - - client_id: int = Field(..., description="Client key") - part_number: str = Field(..., max_length=49, description="Part number") - fraction: Optional[str] = Field(None, max_length=10, description="Tariff fraction") - description_spanish: Optional[str] = Field( - None, max_length=500, description="Description in Spanish" - ) - description_english: Optional[str] = Field( - None, max_length=500, description="Description in English" - ) - part_class: Optional[str] = Field(None, max_length=8, description="Part class") - unit_of_measure: Optional[str] = Field( - None, max_length=5, description="Unit of measure" - ) - commercial_part_number: Optional[str] = Field( - None, max_length=70, description="Commercial part number" - ) - country_of_origin: Optional[str] = Field( - None, max_length=3, description="Country of origin code" - ) - - # Pricing and currency - unit_cost: Optional[Decimal] = Field(None, description="Unit cost") - currency_type: Optional[str] = Field( - None, max_length=2, description="Currency type" - ) - currency_key: Optional[str] = Field(None, max_length=3, description="Currency key") - - # Weight information - unit_weight: Optional[Decimal] = Field(None, description="Unit weight") - weight_type: Optional[str] = Field(None, max_length=6, description="Weight type") - - # Classification and regulatory - us_fraction: Optional[str] = Field( - None, max_length=16, description="US tariff fraction" - ) - fda_key: Optional[str] = Field(None, max_length=20, description="FDA key") - fcc_key: Optional[str] = Field(None, max_length=30, description="FCC key") - license_code: Optional[str] = Field(None, max_length=3, description="License code") - eccn: Optional[str] = Field( - None, max_length=20, description="Export Control Classification Number" - ) - export_code: Optional[str] = Field(None, max_length=2, description="Export code") - exclusion_symbol: Optional[str] = Field( - None, max_length=19, description="Exclusion symbol" - ) - - # Additional information - supplier: Optional[str] = Field(None, max_length=14, description="Supplier") - alternate_unit_measure: Optional[str] = Field( - None, max_length=14, description="Alternate unit of measure" - ) - added_value: Optional[Decimal] = Field(None, description="Added value") - - # Status and media - is_active: Optional[bool] = Field(None, description="Enabled/Disabled status") - creation_date: Optional[int] = Field(None, description="Creation date") - part_photo: Optional[str] = Field( - None, max_length=255, description="Part photo URL" - ) - - class Config: - from_attributes = True - - -class PartUpdateDTO(BaseModel): - """DTO para actualizar una parte""" - - fraction: Optional[str] = Field(None, max_length=10, description="Tariff fraction") - description_spanish: Optional[str] = Field( - None, max_length=500, description="Description in Spanish" - ) - description_english: Optional[str] = Field( - None, max_length=500, description="Description in English" - ) - part_class: Optional[str] = Field(None, max_length=8, description="Part class") - unit_of_measure: Optional[str] = Field( - None, max_length=5, description="Unit of measure" - ) - commercial_part_number: Optional[str] = Field( - None, max_length=70, description="Commercial part number" - ) - country_of_origin: Optional[str] = Field( - None, max_length=3, description="Country of origin code" - ) - - # Pricing and currency - unit_cost: Optional[Decimal] = Field(None, description="Unit cost") - currency_type: Optional[str] = Field( - None, max_length=2, description="Currency type" - ) - currency_key: Optional[str] = Field(None, max_length=3, description="Currency key") - - # Weight information - unit_weight: Optional[Decimal] = Field(None, description="Unit weight") - weight_type: Optional[str] = Field(None, max_length=6, description="Weight type") - - # Classification and regulatory - us_fraction: Optional[str] = Field( - None, max_length=16, description="US tariff fraction" - ) - fda_key: Optional[str] = Field(None, max_length=20, description="FDA key") - fcc_key: Optional[str] = Field(None, max_length=30, description="FCC key") - license_code: Optional[str] = Field(None, max_length=3, description="License code") - eccn: Optional[str] = Field( - None, max_length=20, description="Export Control Classification Number" - ) - export_code: Optional[str] = Field(None, max_length=2, description="Export code") - exclusion_symbol: Optional[str] = Field( - None, max_length=19, description="Exclusion symbol" - ) - - # Additional information - supplier: Optional[str] = Field(None, max_length=14, description="Supplier") - alternate_unit_measure: Optional[str] = Field( - None, max_length=14, description="Alternate unit of measure" - ) - added_value: Optional[Decimal] = Field(None, description="Added value") - - # Status and media - is_active: Optional[bool] = Field(None, description="Enabled/Disabled status") - part_photo: Optional[str] = Field( - None, max_length=255, description="Part photo URL" - ) - - class Config: - from_attributes = True - - -class PartResponseDTO(BaseModel): - """DTO para respuesta de parte""" - +class PartBase(BaseModel): client_id: int - part_number: str - fraction: Optional[str] = None + part_number: str = Field(..., max_length=70) + commercial_part_number: Optional[str] = None + description_spanish: Optional[str] = None description_english: Optional[str] = None part_class: Optional[str] = None - unit_of_measure: Optional[str] = None - commercial_part_number: Optional[str] = None - country_of_origin: Optional[str] = None - - # Pricing and currency + unit_of_measure: Optional[str] = "PZ" + unit_cost: Optional[Decimal] = None - currency_type: Optional[str] = None currency_key: Optional[str] = None - - # Weight information + currency_type: Optional[str] = None + unit_weight: Optional[Decimal] = None weight_type: Optional[str] = None - - # Classification and regulatory + + fraction: Optional[str] = None us_fraction: Optional[str] = None + + # Regulatorios fda_key: Optional[str] = None fcc_key: Optional[str] = None license_code: Optional[str] = None eccn: Optional[str] = None export_code: Optional[str] = None exclusion_symbol: Optional[str] = None - - # Additional information - supplier: Optional[str] = None - alternate_unit_measure: Optional[str] = None - added_value: Optional[Decimal] = None - - # Status and dates - is_active: Optional[bool] = None - creation_date: Optional[int] = None - modification_date: Optional[int] = None - modification_date_iso: Optional[datetime] = None - - # Media + + is_active: bool = True part_photo: Optional[str] = None - class Config: - from_attributes = True + # Anidados + fa_data: Optional[FaDataDTO] = None + inv_data: Optional[InvDataDTO] = None +# --- CREACIÓN --- +class PartCreateDTO(PartBase): + # Opcional para que lo tome de la URL si no viene en el body + company_id: Optional[int] = None +# --- ACTUALIZACIÓN --- +class PartUpdateDTO(PartBase): + client_id: Optional[int] = None + part_number: Optional[str] = None + # Todo opcional para PATCH + pass + +# --- RESPUESTA --- +class PartResponseDTO(PartBase): + id: int + tenant_id: int + company_id: int + creation_date: Optional[int] = None + modification_date_iso: Optional[datetime] = None + + model_config = ConfigDict(from_attributes=True) + +# --- BÁSICO (Para listados ligeros) --- class PartBasicDTO(BaseModel): - """DTO para información básica de parte""" - - client_id: int + id: int part_number: str description_spanish: Optional[str] = None - description_english: Optional[str] = None - part_class: Optional[str] = None - unit_cost: Optional[Decimal] = None - currency_key: Optional[str] = None - is_active: Optional[bool] = None + fraction: Optional[str] = None + is_active: bool + + model_config = ConfigDict(from_attributes=True) - class Config: - from_attributes = True - - -class PartListDTO(BaseModel): - """DTO para lista de partes""" - - parts: list[PartBasicDTO] +# --- LISTADO PAGINADO --- +class PartListResponseDTO(BaseModel): + items: List[PartResponseDTO] total: int page: int - size: int + page_size: int + pages: int - class Config: - from_attributes = True - - -class PartSearchDTO(BaseModel): - """DTO para búsqueda de partes""" - - client_id: Optional[int] = Field(None, description="Filter by client key") - part_number: Optional[str] = Field(None, description="Search by part number") - description: Optional[str] = Field(None, description="Search in descriptions") - fraction: Optional[str] = Field(None, description="Filter by tariff fraction") - supplier: Optional[str] = Field(None, description="Filter by supplier") - enabled_only: bool = Field(False, description="Show only enabled parts") - - class Config: - from_attributes = True diff --git a/backend/api/v1/modules/a76/parts/models.py b/backend/api/v1/modules/a76/parts/models.py index 12750dca..a5da21c2 100644 --- a/backend/api/v1/modules/a76/parts/models.py +++ b/backend/api/v1/modules/a76/parts/models.py @@ -1,7 +1,6 @@ """ -Modelos ORM para gestión de partes/componentes +Modelos ORM para gestión de partes/componentes - Anexo 76 (Master Data) """ - from datetime import datetime from decimal import Decimal from typing import TYPE_CHECKING, Optional @@ -9,34 +8,23 @@ from typing import TYPE_CHECKING, Optional from api.v1.common.base_models import TenantScopedMixin, TimestampMixin from core.database import Base from sqlalchemy import ( - ForeignKeyConstraint, - Integer, - Numeric, - PrimaryKeyConstraint, - String, - UniqueConstraint, - Boolean, + ForeignKeyConstraint, Integer, Numeric, PrimaryKeyConstraint, + String, UniqueConstraint, Boolean, DateTime ) +# Importante usar relationship y Mapped from sqlalchemy.orm import Mapped, mapped_column, relationship if TYPE_CHECKING: from api.v1.modules.a76.classes.models import Class - 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.general_catalogs.units_of_measure.models import UnitOfMeasure - + from api.v1.modules.a24.fa.fa_parts.models import FaPart + from api.v1.modules.a24.inv.inv_parts.models import InvPart class Part(Base, TenantScopedMixin, TimestampMixin): - """ - Modelo para la tabla GPartes - Información de partes en los sistemas SCAII (N), SCAF (S) Y WINSAAI (W) - """ - __tablename__ = "parts" __table_args__ = ( PrimaryKeyConstraint("id", name="parts_pkey"), - ForeignKeyConstraint( - ["country_of_origin"], ["public.countries.m3_key"], name="fk_parts_country" - ), ForeignKeyConstraint( ["currency_key"], ["public.currency_types.code"], name="fk_parts_currency" ), @@ -45,6 +33,12 @@ class Part(Base, TenantScopedMixin, TimestampMixin): ["a76.units_of_measure.code", "a76.units_of_measure.tenant_id", "a76.units_of_measure.company_id"], ), + # Puente hacia la tabla de clases + ForeignKeyConstraint( + ["part_class", "tenant_id", "company_id"], + ["a76.classes.class_code", "a76.classes.tenant_id", "a76.classes.company_id"], + name="fk_parts_class" + ), UniqueConstraint( "tenant_id", "company_id", "part_number", name="client_part_ukey" ), @@ -52,80 +46,58 @@ class Part(Base, TenantScopedMixin, TimestampMixin): ) id: Mapped[int] = mapped_column(Integer, primary_key=True) - - # Unique constraint compuesta client_id: Mapped[int] = mapped_column(Integer) - part_number: Mapped[str] = mapped_column(String(50)) + part_number: Mapped[str] = mapped_column(String(70)) + commercial_part_number: Mapped[Optional[str]] = mapped_column(String(70)) - # Basic information - fraction: Mapped[Optional[str]] = mapped_column(String(10)) description_spanish: Mapped[Optional[str]] = mapped_column(String(500)) description_english: Mapped[Optional[str]] = mapped_column(String(500)) part_class: Mapped[Optional[str]] = mapped_column(String(8)) - unit_of_measure: Mapped[Optional[str]] = mapped_column( - String(5) - ) - commercial_part_number: Mapped[Optional[str]] = mapped_column(String(70)) - country_of_origin: Mapped[Optional[str]] = mapped_column(String(3)) - - # Pricing and currency + unit_of_measure: Mapped[Optional[str]] = mapped_column(String(5)) + unit_cost: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) currency_type: Mapped[Optional[str]] = mapped_column(String(2)) currency_key: Mapped[Optional[str]] = mapped_column(String(3)) - # Weight information unit_weight: Mapped[Optional[Decimal]] = mapped_column(Numeric(19, 8)) weight_type: Mapped[Optional[str]] = mapped_column(String(6)) - # Classification and regulatory - us_fraction: Mapped[Optional[str]] = mapped_column( - String(16)) # FRACCIONAME + fraction: Mapped[Optional[str]] = mapped_column(String(10)) + us_fraction: Mapped[Optional[str]] = mapped_column(String(16)) fda_key: Mapped[Optional[str]] = mapped_column(String(20)) fcc_key: Mapped[Optional[str]] = mapped_column(String(30)) license_code: Mapped[Optional[str]] = mapped_column(String(3)) - eccn: Mapped[Optional[str]] = mapped_column( - String(20) - ) # Export Control Classification Number + eccn: Mapped[Optional[str]] = mapped_column(String(20)) export_code: Mapped[Optional[str]] = mapped_column(String(2)) - exclusion_symbol: Mapped[Optional[str]] = mapped_column( - String(19)) # SIMBOLOEXCLIC + exclusion_symbol: Mapped[Optional[str]] = mapped_column(String(19)) - # Additional information - supplier: Mapped[Optional[str]] = mapped_column(String(14)) - alternate_unit_measure: Mapped[Optional[str]] = mapped_column(String(14)) - added_value: Mapped[Optional[Decimal]] = mapped_column(Numeric(23, 8)) - - # Status and dates - is_active: Mapped[Optional[bool]] = mapped_column(Boolean) - creation_date: Mapped[Optional[int] - ] = mapped_column() # FECHACREACIONPARTE - modification_date: Mapped[Optional[int]] = mapped_column() # FECHAMODIFICA - modification_date_iso: Mapped[Optional[datetime]] = ( - mapped_column() - ) # FECHAMODIFICA_ISO - - # Media + is_active: Mapped[Optional[bool]] = mapped_column(Boolean, default=True) part_photo: Mapped[Optional[str]] = mapped_column(String(255)) + + creation_date: Mapped[Optional[int]] = mapped_column() + modification_date: Mapped[Optional[int]] = mapped_column() + modification_date_iso: Mapped[Optional[datetime]] = mapped_column(DateTime) - # Relationships - country: Mapped[Optional["Country"]] = relationship( - foreign_keys=[country_of_origin] - ) + # --- RELACIONES CORREGIDAS --- currency: Mapped[Optional["CurrencyType"]] = relationship( - foreign_keys=[currency_key] + foreign_keys="[Part.currency_key]" ) unit_of_measure_info: Mapped[Optional["UnitOfMeasure"]] = relationship( - foreign_keys=[unit_of_measure] + foreign_keys="[Part.unit_of_measure, Part.tenant_id, Part.company_id]" + ) + part_class_info: Mapped[Optional["Class"]] = relationship( + "Class", + back_populates="parts", + foreign_keys="[Part.part_class, Part.tenant_id, Part.company_id]" ) - # Relationship with Class through composite foreign key - # Note: This requires both client_id and part_class to match client_id and class_code in Class - part_class_info: Mapped[Optional["Class"]] = relationship( - primaryjoin="and_(Part.client_id == Class.client_id, Part.part_class == Class.class_code)", - foreign_keys="[Part.client_id, Part.part_class]", - viewonly=True, - back_populates="parts", + # Extensiones Anexo 24 + fa_data: Mapped[Optional["FaPart"]] = relationship( + "FaPart", back_populates="master_info", uselist=False, cascade="all, delete-orphan" + ) + inv_data: Mapped[Optional["InvPart"]] = relationship( + "InvPart", back_populates="master_info", uselist=False, cascade="all, delete-orphan" ) def __repr__(self) -> str: - return f"" + return f"" \ No newline at end of file diff --git a/backend/api/v1/modules/a76/parts/routes.py b/backend/api/v1/modules/a76/parts/routes.py index 0f5996b6..033ad472 100644 --- a/backend/api/v1/modules/a76/parts/routes.py +++ b/backend/api/v1/modules/a76/parts/routes.py @@ -1,393 +1,22 @@ """ -Endpoints API para gestión de partes/componentes +Endpoints API para gestión de partes (SCAII) """ -from typing import List, Optional +from api.v1.common.tenant_crud_routes import TenantCRUDRoutes -from core.database import get_core_db -from core.security import get_current_user -from fastapi import APIRouter, Depends, HTTPException, Query, status -from sqlalchemy.orm import Session - -from .dto import ( - PartBasicDTO, - PartCreateDTO, - PartListDTO, - PartResponseDTO, - PartSearchDTO, - PartUpdateDTO, -) +from .dto import PartCreateDTO, PartResponseDTO, PartUpdateDTO from .service import PartService -router = APIRouter(prefix="/parts") - -@router.post("/", response_model=PartResponseDTO, status_code=status.HTTP_201_CREATED) -async def create_part( - part_data: PartCreateDTO, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Create a new part in the system - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - return service.create_part(part_data) - - -@router.get("/", response_model=PartListDTO) -async def list_parts( - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query( - 100, ge=1, le=1000, description="Maximum number of records to return" - ), - client_id: Optional[int] = Query(None, description="Filter by client key"), - part_number: Optional[str] = Query(None, description="Search by part number"), - description: Optional[str] = Query(None, description="Search in descriptions"), - fraction: Optional[str] = Query(None, description="Filter by tariff fraction"), - supplier: Optional[str] = Query(None, description="Filter by supplier"), - enabled_only: bool = Query(False, description="Show only enabled parts"), - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - List parts with optional filters and pagination - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - search_params = PartSearchDTO( - client_id=client_id, - part_number=part_number, - description=description, - fraction=fraction, - supplier=supplier, - enabled_only=enabled_only, - ) - return service.list_parts(skip, limit, search_params) - - -@router.get("/client/{client_id}", response_model=List[PartBasicDTO]) -async def get_parts_by_client( - client_id: int, - skip: int = Query(0, ge=0), - limit: int = Query(100, ge=1, le=1000), - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Get all parts for a specific client - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - return service.search_by_client(client_id, skip, limit) - - -@router.get("/search/fraction/{fraction}", response_model=List[PartBasicDTO]) -async def search_by_fraction( - fraction: str, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Search parts by tariff fraction - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - return service.search_by_fraction(fraction) - - -@router.get("/search/supplier/{supplier}", response_model=List[PartBasicDTO]) -async def search_by_supplier( - supplier: str, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Search parts by supplier - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - return service.search_by_supplier(supplier) - - -@router.get("/search/country/{country_code}", response_model=List[PartBasicDTO]) -async def get_parts_by_country( - country_code: str, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Get parts by country of origin - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - return service.get_parts_by_country(country_code) - - -@router.get("/statistics", response_model=dict) -async def get_parts_statistics( - db: Session = Depends(get_core_db), current_user: dict = Depends(get_current_user) -): - """ - Get basic parts statistics - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - return service.get_parts_statistics() - - -@router.get("/{client_id}/{part_number}", response_model=PartResponseDTO) -async def get_part( - client_id: int, - part_number: str, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Get part by composite key (client_id + part_number) - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - part = service.get_part(client_id, part_number) - if not part: - raise HTTPException( - status_code=404, - detail=f"Part with client_id '{client_id}' and part_number '{part_number}' not found", - ) - return part - - -@router.put("/{client_id}/{part_number}", response_model=PartResponseDTO) -async def update_part( - client_id: int, - part_number: str, - part_data: PartUpdateDTO, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Update part information - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - part = service.update_part(client_id, part_number, part_data) - if not part: - raise HTTPException( - status_code=404, - detail=f"Part with client_id '{client_id}' and part_number '{part_number}' not found", - ) - return part - - -@router.delete("/{client_id}/{part_number}", status_code=status.HTTP_204_NO_CONTENT) -async def delete_part( - client_id: int, - part_number: str, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Delete part from the system - - Note: This will completely remove the part from the system. - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - if not service.delete_part(client_id, part_number): - raise HTTPException( - status_code=404, - detail=f"Part with client_id '{client_id}' and part_number '{part_number}' not found", - ) - - -@router.patch( - "/{client_id}/{part_number}/toggle-status", response_model=PartResponseDTO -) -async def toggle_part_status( - client_id: int, - part_number: str, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Toggle part enabled/disabled status - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - part = service.toggle_status(client_id, part_number) - if not part: - raise HTTPException( - status_code=404, - detail=f"Part with client_id '{client_id}' and part_number '{part_number}' not found", - ) - return part - - -# Endpoints específicos para información detallada -@router.get("/{client_id}/{part_number}/basic", response_model=PartBasicDTO) -async def get_part_basic_info( - client_id: int, - part_number: str, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Get basic information for a part - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - part = service.get_part(client_id, part_number) - if not part: - raise HTTPException( - status_code=404, - detail=f"Part with client_id '{client_id}' and part_number '{part_number}' not found", - ) - - return PartBasicDTO( - client_id=part.client_id, - part_number=part.part_number, - description_spanish=part.description_spanish, - description_english=part.description_english, - part_class=part.part_class, - unit_cost=part.unit_cost, - currency_key=part.currency_key, - is_active=part.is_active, - ) - - -@router.get("/{client_id}/{part_number}/regulatory", response_model=dict) -async def get_part_regulatory_info( - client_id: int, - part_number: str, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """ - Get regulatory information for a part (FDA, FCC, ECCN, etc.) - """ - # Validate access to the tenant and company - tenant_id = current_user.get("tenant_id") - company_id = current_user.get("company_id") - - if not tenant_id or not company_id: - raise HTTPException( - status_code=403, detail="Access denied: Tenant or Company not found" - ) - - service = PartService(db) - part = service.get_part(client_id, part_number) - if not part: - raise HTTPException( - status_code=404, - detail=f"Part with client_id '{client_id}' and part_number '{part_number}' not found", - ) - - return { - "client_id": part.client_id, - "part_number": part.part_number, - "fraction": part.fraction, - "us_fraction": part.us_fraction, - "fda_key": part.fda_key, - "fcc_key": part.fcc_key, - "license_code": part.license_code, - "eccn": part.eccn, - "export_code": part.export_code, - "exclusion_symbol": part.exclusion_symbol, - } +router = TenantCRUDRoutes( + service=PartService, + create_schema=PartCreateDTO, + update_schema=PartUpdateDTO, + response_schema=PartResponseDTO, + prefix="/parts", + tags=["a76 / parts"], + resource_name="Part", + id_name="part_id", + enable_list=True, + enable_filters=True, +).router \ No newline at end of file diff --git a/backend/api/v1/modules/a76/parts/service.py b/backend/api/v1/modules/a76/parts/service.py index 48c2eab9..5db4bb5f 100644 --- a/backend/api/v1/modules/a76/parts/service.py +++ b/backend/api/v1/modules/a76/parts/service.py @@ -1,309 +1,179 @@ -""" -Capa de servicio para lógica de negocio de partes/componentes -""" - import logging -from typing import List, Optional +from typing import Any, Dict, List, Optional from fastapi import HTTPException -from sqlalchemy import and_, func, or_ +from sqlalchemy import or_ from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import Session -from .dto import PartCreateDTO, PartUpdateDTO +# Importamos el modelo PRINCIPAL from .models import Part +# Importamos TODOS los DTOs necesarios +from .dto import ( + PartCreateDTO, + PartUpdateDTO, + PartResponseDTO, + PartBasicDTO # ¡Importante tener este! +) + logger = logging.getLogger(__name__) - class PartService: - """ - Servicio para gestión de partes/componentes - """ + """Servicio para gestión de Partes (Anexo 76 + Anexo 24)""" @staticmethod - def create_part(db: Session, part_data: PartCreateDTO) -> Part: - """ - Crear una nueva parte - """ + def get_all( + db: Session, + tenant_id: int, + company_id: int, + skip: int = 0, + limit: int = 100, + filters: Optional[Dict[str, Any]] = None, + ) -> tuple[List[Part], int]: + + query = db.query(Part).filter( + Part.tenant_id == tenant_id, + Part.company_id == company_id + ) + + if filters: + if filters.get("q"): + search = f"%{filters['q']}%" + query = query.filter( + or_( + Part.part_number.ilike(search), + Part.description_spanish.ilike(search), + Part.commercial_part_number.ilike(search) + ) + ) + # Otros filtros... + + total = query.count() + items = query.offset(skip).limit(limit).all() + return items, total + + @staticmethod + def get_by_id(db: Session, part_id: int, tenant_id: int, company_id: int) -> Optional[Part]: + return db.query(Part).filter( + Part.id == part_id, + Part.tenant_id == tenant_id, + Part.company_id == company_id + ).first() + + @staticmethod + def create(db: Session, part_data: PartCreateDTO, tenant_id: int, company_id: int) -> Part: + # 1. Preparar datos + data = part_data.model_dump() + + # Separar datos anidados + fa_dict = data.pop('fa_data', None) + inv_dict = data.pop('inv_data', None) + + # Inyectar IDs de contexto (Seguridad Multi-tenant) + data['company_id'] = company_id + data['tenant_id'] = tenant_id + + # 2. Verificar duplicados (Usando la UniqueConstraint del modelo) + existing = db.query(Part).filter( + Part.tenant_id == tenant_id, + Part.company_id == company_id, + Part.part_number == data['part_number'] + ).first() + + if existing: + raise HTTPException( + status_code=400, + detail=f"El número de parte '{data['part_number']}' ya existe." + ) + + # 3. Crear objeto Part + db_part = Part(**data) + + # 4. Crear relaciones (Anexo 24) + # Importamos aquí para evitar ciclos, usando las rutas de tu modelo + if fa_dict: + from api.v1.modules.a24.fa.fa_parts.models import FaPart + # Importante: Pasar tenant/company también al hijo + db_part.fa_data = FaPart(**fa_dict, tenant_id=tenant_id, company_id=company_id) + + if inv_dict: + from api.v1.modules.a24.inv.inv_parts.models import InvPart + db_part.inv_data = InvPart(**inv_dict, tenant_id=tenant_id, company_id=company_id) + try: - db_part = Part(**part_data.model_dump()) db.add(db_part) db.commit() db.refresh(db_part) return db_part + + except IntegrityError as e: + db.rollback() + err_msg = str(e.orig) + logger.error(f"Error DB creando parte: {err_msg}") + + if "foreign key" in err_msg: + if "unit_of_measure" in err_msg: + raise HTTPException(400, "La Unidad de Medida no existe en el catálogo.") + if "currency_key" in err_msg: + raise HTTPException(400, "La Moneda no existe en el catálogo.") + if "part_class" in err_msg: + raise HTTPException(400, "La Clase no existe para este cliente.") + + # El error genérico si falla Company/Client + raise HTTPException(400, "Error de referencia: Verifique Cliente, Compañía o Catálogos.") + + raise HTTPException(400, "Error al guardar la parte.") + + @staticmethod + def update(db: Session, part_id: int, tenant_id: int, part_data: PartUpdateDTO, company_id: int) -> Optional[Part]: + db_part = PartService.get_by_id(db, part_id, tenant_id, company_id) + if not db_part: + return None + + data = part_data.model_dump(exclude_unset=True) + fa_dict = data.pop('fa_data', None) + inv_dict = data.pop('inv_data', None) + + # Actualizar campos directos + for key, value in data.items(): + setattr(db_part, key, value) + + # Actualizar FA Data + if fa_dict is not None: + if db_part.fa_data: + for k, v in fa_dict.items(): + setattr(db_part.fa_data, k, v) + else: + from api.v1.modules.a24.fa.fa_parts.models import FaPart + db_part.fa_data = FaPart(**fa_dict, tenant_id=tenant_id, company_id=company_id) + + # Actualizar INV Data + if inv_dict is not None: + if db_part.inv_data: + for k, v in inv_dict.items(): + setattr(db_part.inv_data, k, v) + else: + from api.v1.modules.a24.inv.inv_parts.models import InvPart + db_part.inv_data = InvPart(**inv_dict, tenant_id=tenant_id, company_id=company_id) + + try: + db.commit() + db.refresh(db_part) + return db_part except IntegrityError as e: db.rollback() - logger.error(f"Error creating part: {e}") - raise HTTPException( - status_code=400, - detail="Part with this client_id and part_number already exists", - ) - except Exception as e: - db.rollback() - logger.error(f"Unexpected error creating part: {e}") - raise HTTPException(status_code=500, detail="Error creating part") + raise HTTPException(400, f"Error actualizando: {str(e.orig)}") @staticmethod - def get_part(db: Session, client_id: int, part_number: str) -> Optional[Part]: - """ - Obtener una parte por clave de cliente y número de parte - """ + def delete(db: Session, part_id: int, tenant_id: int, company_id: int) -> bool: + db_part = PartService.get_by_id(db, part_id, tenant_id, company_id) + if not db_part: return False + try: - return ( - db.query(Part) - .filter( - and_(Part.client_id == client_id, Part.part_number == part_number) - ) - .first() - ) - except Exception as e: - logger.error(f"Error getting part: {e}") - raise HTTPException(status_code=500, detail="Error retrieving part") - - @staticmethod - def get_parts_paginated( - db: Session, - skip: int = 0, - limit: int = 100, - search: Optional[str] = None, - client_id: Optional[int] = None, - fraction: Optional[str] = None, - country_of_origin: Optional[str] = None, - ) -> tuple[List[Part], int]: - """ - Obtener partes con paginación y filtros - """ - try: - query = db.query(Part) - - # Aplicar filtros - if search: - query = query.filter( - or_( - Part.description_spanish.ilike(f"%{search}%"), - Part.description_english.ilike(f"%{search}%"), - Part.part_number.ilike(f"%{search}%"), - ) - ) - - if client_id is not None: - query = query.filter(Part.client_id == client_id) - - if fraction: - query = query.filter(Part.fraction == fraction) - - if country_of_origin: - query = query.filter(Part.country_of_origin == country_of_origin) - - # Contar total - total = query.count() - - # Aplicar paginación - parts = query.offset(skip).limit(limit).all() - - return parts, total - except Exception as e: - logger.error(f"Error getting paginated parts: {e}") - raise HTTPException(status_code=500, detail="Error retrieving parts") - - @staticmethod - def get_parts_by_client(db: Session, client_id: int) -> List[Part]: - """ - Obtener todas las partes de un cliente específico - """ - try: - return db.query(Part).filter(Part.client_id == client_id).all() - except Exception as e: - logger.error(f"Error getting parts by client: {e}") - raise HTTPException(status_code=500, detail="Error retrieving client parts") - - @staticmethod - def search_parts_by_fraction(db: Session, fraction: str) -> List[Part]: - """ - Buscar partes por fracción arancelaria - """ - try: - return ( - db.query(Part) - .filter( - or_( - Part.fraction.ilike(f"%{fraction}%"), - Part.us_fraction.ilike(f"%{fraction}%"), - ) - ) - .all() - ) - except Exception as e: - logger.error(f"Error searching parts by fraction: {e}") - raise HTTPException( - status_code=500, detail="Error searching parts by fraction" - ) - - @staticmethod - def search_parts_by_supplier(db: Session, supplier: str) -> List[Part]: - """ - Buscar partes por proveedor - """ - try: - return db.query(Part).filter(Part.supplier.ilike(f"%{supplier}%")).all() - except Exception as e: - logger.error(f"Error searching parts by supplier: {e}") - raise HTTPException( - status_code=500, detail="Error searching parts by supplier" - ) - - @staticmethod - def search_parts_by_country(db: Session, country_code: str) -> List[Part]: - """ - Buscar partes por país de origen - """ - try: - return db.query(Part).filter(Part.country_of_origin == country_code).all() - except Exception as e: - logger.error(f"Error searching parts by country: {e}") - raise HTTPException( - status_code=500, detail="Error searching parts by country" - ) - - @staticmethod - def update_part( - db: Session, client_id: int, part_number: str, part_data: PartUpdateDTO - ) -> Optional[Part]: - """ - Actualizar una parte existente - """ - try: - db_part = PartService.get_part(db, client_id, part_number) - if not db_part: - return None - - # Actualizar campos - for field, value in part_data.model_dump(exclude_unset=True).items(): - setattr(db_part, field, value) - - db.commit() - db.refresh(db_part) - return db_part - except Exception as e: - db.rollback() - logger.error(f"Error updating part: {e}") - raise HTTPException(status_code=500, detail="Error updating part") - - @staticmethod - def delete_part(db: Session, client_id: int, part_number: str) -> bool: - """ - Eliminar una parte - """ - try: - db_part = PartService.get_part(db, client_id, part_number) - if not db_part: - return False - db.delete(db_part) db.commit() return True - except Exception as e: + except Exception: db.rollback() - logger.error(f"Error deleting part: {e}") - raise HTTPException(status_code=500, detail="Error deleting part") - - @staticmethod - def toggle_part_status( - db: Session, client_id: int, part_number: str - ) -> Optional[Part]: - """ - Cambiar el estado habilitado/deshabilitado de una parte - """ - try: - db_part = PartService.get_part(db, client_id, part_number) - if not db_part: - return None - - # Toggle status (assuming 1 = enabled, 0 = disabled) - db_part.is_active = 1 if db_part.is_active == 0 else 0 - - db.commit() - db.refresh(db_part) - return db_part - except Exception as e: - db.rollback() - logger.error(f"Error toggling part status: {e}") - raise HTTPException(status_code=500, detail="Error toggling part status") - - @staticmethod - def get_parts_statistics(db: Session) -> dict: - """ - Obtener estadísticas de partes - """ - try: - total_parts = db.query(Part).count() - - # Partes por cliente - parts_by_client = ( - db.query(Part.client_id, func.count(Part.part_number).label("count")) - .group_by(Part.client_id) - .all() - ) - - # Partes por país de origen - parts_by_country = ( - db.query( - Part.country_of_origin, func.count(Part.part_number).label("count") - ) - .filter(Part.country_of_origin.isnot(None)) - .group_by(Part.country_of_origin) - .all() - ) - - # Partes habilitadas vs deshabilitadas - enabled_parts = db.query(Part).filter(Part.is_active == 1).count() - disabled_parts = db.query(Part).filter(Part.is_active == 0).count() - - return { - "total_parts": total_parts, - "enabled_parts": enabled_parts, - "disabled_parts": disabled_parts, - "parts_by_client": [ - {"client_id": item[0], "count": item[1]} for item in parts_by_client - ], - "parts_by_country": [ - {"country": item[0], "count": item[1]} for item in parts_by_country - ], - } - except Exception as e: - logger.error(f"Error getting parts statistics: {e}") - raise HTTPException( - status_code=500, detail="Error retrieving parts statistics" - ) - - @staticmethod - def get_part_regulatory_info( - db: Session, client_id: int, part_number: str - ) -> Optional[dict]: - """ - Obtener información regulatoria específica de una parte - """ - try: - db_part = PartService.get_part(db, client_id, part_number) - if not db_part: - return None - - return { - "client_id": db_part.client_id, - "part_number": db_part.part_number, - "fraction": db_part.fraction, - "us_fraction": db_part.us_fraction, - "fda_key": db_part.fda_key, - "fcc_key": db_part.fcc_key, - "license_code": db_part.license_code, - "eccn": db_part.eccn, - "export_code": db_part.export_code, - "exclusion_symbol": db_part.exclusion_symbol, - "country_of_origin": db_part.country_of_origin, - } - except Exception as e: - logger.error(f"Error getting part regulatory info: {e}") - raise HTTPException( - status_code=500, detail="Error retrieving part regulatory information" - ) + raise HTTPException(500, "Error eliminando parte") \ No newline at end of file diff --git a/backend/api/v1/modules/a76/router.py b/backend/api/v1/modules/a76/router.py index e6a3aedb..6b808292 100644 --- a/backend/api/v1/modules/a76/router.py +++ b/backend/api/v1/modules/a76/router.py @@ -42,6 +42,8 @@ from .general_catalogs.electronic_notices.routes import router as electronic_not from .transportation.trailers.routes import router as trailers_router from .transportation.transporters.routes import router as transporters_router from .transportation.vehicles.routes import router as vehicles_router +from api.v1.modules.public.reference_data.material_types.routes import router as material_types_router + # Router principal router = APIRouter() @@ -96,3 +98,11 @@ router.include_router(error_catalogs_router, prefix="/a76") router.include_router(doda_router, prefix="/a76") router.include_router(prevalidators_router, prefix="/a76") router.include_router(electronic_notices_router, prefix="/a76") + + +# Registrar router de tipos de material públicos +router.include_router( + material_types_router, + prefix="/public/reference-data", + tags=["Reference Data"] +) diff --git a/backend/api/v1/router.py b/backend/api/v1/router.py index 9fd2618e..c17b0ee0 100644 --- a/backend/api/v1/router.py +++ b/backend/api/v1/router.py @@ -9,6 +9,7 @@ from fastapi import APIRouter from .modules.core.router import router as core_router from .modules.a76.router import router as a76_router from .modules.public.router import router as public_router +from .modules.a24.router import router as a24_router # Router principal router = APIRouter() @@ -17,6 +18,8 @@ router = APIRouter() router.include_router(core_router) router.include_router(a76_router) router.include_router(public_router) +# nuevas rutas de partes de anexo 24 +router.include_router(a24_router) # Health check diff --git a/frontend/messages/en.json b/frontend/messages/en.json index d4274cd5..541dac72 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -63,6 +63,11 @@ "back_flush": "Back Flush", "crossing_notice": "Crossing Notice" }, + "goods": { + "title": "Goods", + "classes": "Classes", + "parts": "Parts" + }, "pedimentos": { "title": "Pedimentos", "pedimento_management": "Pedimento Management", diff --git a/frontend/messages/es.json b/frontend/messages/es.json index 083691bc..9e2a85c5 100644 --- a/frontend/messages/es.json +++ b/frontend/messages/es.json @@ -63,6 +63,11 @@ "back_flush": "Back Flush", "crossing_notice": "Aviso de cruce" }, + "goods": { + "title": "Mercancías", + "classes": "Clases", + "parts": "Partes" + }, "pedimentos": { "title": "Pedimentos", "pedimento_management": "Gestión de Pedimentos", diff --git a/frontend/src/lib/api/dashboard/a76/classes.ts b/frontend/src/lib/api/dashboard/a76/classes.ts index a08c2832..21b6b160 100644 --- a/frontend/src/lib/api/dashboard/a76/classes.ts +++ b/frontend/src/lib/api/dashboard/a76/classes.ts @@ -1,107 +1,90 @@ -/** - * API para gestión de Classes (Clases A76) - */ import { api } from '$lib/api'; import type { ApiResponse } from '$lib/api'; +// --- INTERFACES --- + export interface A76Class { - id: number; - tenant_id: number; - company_id: number; - client_id: number; - class_code: string; - description_es: string | null; - description_en: string | null; - material_key: string | null; - unit_of_measure: string; - fraction: string; - us_fraction: string; - sub_key: string; - physical_review: number; - iva_exempt_fraction: string; - created_at: string; - updated_at: string; + id: number; + tenant_id: number; + company_id: number; + client_id: number; + class_code: string; + description_es: string | null; + description_en: string | null; + material_key: string | null; + unit_of_measure: string; + fraction: string; + us_fraction: string; + sub_key: string; + physical_review: number; + iva_exempt_fraction: string; + is_active?: boolean; // Agregado para el switch del formulario + created_at: string; + updated_at: string; } +// DTO para crear (match con tu formulario) export interface A76ClassCreate { - company_id: number; - client_id: number; - class_code: string; - description_es?: string | null; - description_en?: string | null; - material_key?: string | null; - unit_of_measure: string; - fraction: string; - us_fraction: string; - sub_key: string; - physical_review?: number; - iva_exempt_fraction: string; + company_id: number; + client_id: number; + class_code: string; + description_es?: string | null; + description_en?: string | null; + material_key?: string | null; + unit_of_measure?: string | null; + fraction?: string | null; + us_fraction?: string | null; + sub_key?: string | null; + physical_review?: number | null; + iva_exempt_fraction?: string | null; + is_active?: boolean; } -export interface A76ClassUpdate { - client_id?: number; - class_code?: string; - description_es?: string | null; - description_en?: string | null; - material_key?: string | null; - unit_of_measure?: string; - fraction?: string; - us_fraction?: string; - sub_key?: string; - physical_review?: number; - iva_exempt_fraction?: string; -} +// DTO para actualizar (Partial del create) +export interface A76ClassUpdate extends Partial {} export interface A76ClassListResponse { - items: A76Class[]; - total: number; - page: number; - page_size: number; + items: A76Class[]; + classes?: A76Class[]; + total: number; + page: number; + page_size: number; + size?: number; } export interface A76ClassListParams { - company_id: number; - page?: number; - page_size?: number; + company_id: number; + page?: number; + page_size?: number; + class_code?: string; + description?: string; + q?: string; // Agregado por si usas búsqueda general } -/** - * API de Classes - */ +// --- API OBJECT --- + export const classesApi = { - /** - * Obtener lista de classes con paginación - */ - list: (params: A76ClassListParams): Promise> => { - const { company_id, page = 1, page_size = 50 } = params; - return api.get(`/v1/a76/classes/?company_id=${company_id}&page=${page}&page_size=${page_size}`); - }, + list: (params: A76ClassListParams): Promise> => { + const query = new URLSearchParams(); + Object.entries(params).forEach(([key, value]) => { + if (value !== undefined && value !== null) query.append(key, value.toString()); + }); + return api.get(`/v1/a76/classes/?${query.toString()}`); + }, - /** - * Obtener un class por ID - */ - get: (id: number, company_id: number): Promise> => { - return api.get(`/v1/a76/classes/${id}?company_id=${company_id}`); - }, + get: (id: number, company_id: number): Promise> => { + return api.get(`/v1/a76/classes/${id}?company_id=${company_id}`); + }, - /** - * Crear un nuevo class - */ - create: (data: A76ClassCreate, company_id: number): Promise> => { - return api.post(`/v1/a76/classes/?company_id=${company_id}`, data); - }, + create: (data: A76ClassCreate, company_id: number): Promise> => { + return api.post(`/v1/a76/classes/?company_id=${company_id}`, data); + }, - /** - * Actualizar un class existente - */ - update: (id: number, data: A76ClassUpdate, company_id: number): Promise> => { - return api.put(`/v1/a76/classes/${id}?company_id=${company_id}`, data); - }, + update: (id: number, data: A76ClassUpdate, company_id: number): Promise> => { + return api.put(`/v1/a76/classes/${id}?company_id=${company_id}`, data); + }, - /** - * Eliminar un class - */ - delete: (id: number, company_id: number): Promise> => { - return api.delete(`/v1/a76/classes/${id}?company_id=${company_id}`); - } -}; + delete: (id: number, company_id: number): Promise> => { + return api.delete(`/v1/a76/classes/${id}?company_id=${company_id}`); + } +}; \ No newline at end of file diff --git a/frontend/src/lib/api/dashboard/a76/clients-providers.ts b/frontend/src/lib/api/dashboard/a76/clients-providers.ts index 4635703a..af66c1c5 100644 --- a/frontend/src/lib/api/dashboard/a76/clients-providers.ts +++ b/frontend/src/lib/api/dashboard/a76/clients-providers.ts @@ -1,173 +1,97 @@ -/** - * API Client para Clientes y Proveedores - * Gestiona las operaciones CRUD para clientes y proveedores - */ import { api } from '$lib/api'; +// --- Interfaces para Tablas Hijas --- + export interface ClientProviderAddress { id?: number; - streets?: string | null; + streets?: string | null; + exterior_number?: string | null; + interior_number?: string | null; neighborhood?: string | null; + municipality?: string | null; city?: string | null; state?: string | null; country?: string | null; - zip_code?: string | null; - client_id?: number; - interior_number?: string | null; - exterior_number?: string | null; - municipality?: string | null; + postal_code?: string | null; + email?: string | null; + phone?: string | null; + contact?: string | null; } export interface ClientProviderPrograms { - id?: number; - program_code?: string | null; - authorization_date?: string | null; - client_id?: number; + id?: number; + program?: string | null; + program_number?: string | null; + secon_auth_date?: number | null; // YYYYMMDD + prosec?: number | null; + manufacturer_id?: string | null; + tax_id?: string | null; + ctpat_svi?: string | null; + is_certified_company?: string | null; } +// --- Interfaz Principal --- + export interface ClientProvider { - id: number; - rfc: string; - name: string; - curp?: string | null; - residence_country?: string | null; - domicile_fiscal?: string | null; - foreign_tax_id?: string | null; - client_or_provider?: string | null; - is_active?: boolean; - tenant_id: number; - address?: ClientProviderAddress | null; - programs?: ClientProviderPrograms | null; -} - -export interface ClientProviderBasic { - id: number; - rfc: string; - name: string; - curp?: string | null; - residence_country?: string | null; - domicile_fiscal?: string | null; - foreign_tax_id?: string | null; - client_or_provider?: string | null; - is_active?: boolean; - tenant_id: number; + id: number; + rfc: string; + name: string; + short_name?: string | null; + curp?: string | null; + client_or_provider: 'client' | 'provider' | 'both'; + + // Campos planos de la tabla principal + type_nat_foreign?: string | null; + responsible?: string | null; + position?: string | null; + + // Booleanos (Coincidiendo con la BD) + is_national_provider?: boolean | null; + is_active?: boolean; + + // Relaciones Anidadas + address?: ClientProviderAddress | null; + programs?: ClientProviderPrograms | null; } export interface ClientProviderListResponse { - items: ClientProvider[]; - total: number; - page: number; - page_size: number; + items: ClientProvider[]; + total: number; + page: number; + page_size: number; } -export interface CreateClientProviderData { - rfc: string; - name: string; - curp?: string | null; - residence_country?: string | null; - domicile_fiscal?: string | null; - foreign_tax_id?: string | null; - client_or_provider?: string | null; - is_active?: boolean; - address?: Omit | null; - programs?: Omit | null; +// DTOs de Envío (excluyendo IDs automáticos) +export interface CreateClientProviderData extends Omit { + address?: ClientProviderAddress | null; + programs?: ClientProviderPrograms | null; } -export interface UpdateClientProviderData { - rfc?: string; - name?: string; - curp?: string | null; - residence_country?: string | null; - domicile_fiscal?: string | null; - foreign_tax_id?: string | null; - client_or_provider?: string | null; - is_active?: boolean; - address?: Partial | null; - programs?: Partial | null; -} +export interface UpdateClientProviderData extends Partial {} -/** - * API para Clientes y Proveedores - */ export const clientsProvidersApi = { - /** - * Lista todos los clientes y proveedores con paginación - * @param companyId - ID de la compañía - * @param page - Número de página (por defecto 1) - * @param pageSize - Tamaño de página (por defecto 50) - * @param filters - Filtros opcionales - */ - list: (companyId: number, page = 1, pageSize = 50, filters?: Record) => { - const params = new URLSearchParams({ - company_id: companyId.toString(), - page: page.toString(), - page_size: pageSize.toString() - }); + list: (companyId: number, page = 1, pageSize = 50, filters?: Record) => { + const params = new URLSearchParams({ + company_id: companyId.toString(), + page: page.toString(), + page_size: pageSize.toString() + }); + if (filters) { + Object.entries(filters).forEach(([key, value]) => { + if (value) params.append(key, value.toString()); + }); + } + return api.get(`/v1/a76/clients-providers?${params.toString()}`); + }, + get: (id: number, companyId: number) => + api.get(`/v1/a76/clients-providers/${id}?company_id=${companyId}`), + + create: (companyId: number, data: any) => + api.post(`/v1/a76/clients-providers?company_id=${companyId}`, data), - if (filters) { - Object.entries(filters).forEach(([key, value]) => { - if (value !== undefined && value !== null && value !== '') { - params.append(key, value.toString()); - } - }); - } + update: (id: number, companyId: number, data: any) => + api.patch(`/v1/a76/clients-providers/${id}?company_id=${companyId}`, data), - return api.get( - `/v1/a76/clients-providers/?${params.toString()}` - ); - }, - - /** - * Obtiene un cliente/proveedor por ID - * @param id - ID del cliente/proveedor - * @param companyId - ID de la compañía - */ - get: (id: number, companyId: number) => - api.get(`/v1/a76/clients-providers/${id}?company_id=${companyId}`), - - /** - * Obtiene información básica de un cliente/proveedor - * @param id - ID del cliente/proveedor - * @param companyId - ID de la compañía - */ - getBasic: (id: number, companyId: number) => - api.get( - `/v1/a76/clients-providers/${id}/basic?company_id=${companyId}` - ), - - /** - * Crea un nuevo cliente/proveedor - * @param companyId - ID de la compañía - * @param data - Datos del cliente/proveedor a crear - */ - create: (companyId: number, data: CreateClientProviderData) => - api.post(`/v1/a76/clients-providers/?company_id=${companyId}`, data), - - /** - * Actualiza un cliente/proveedor existente - * @param id - ID del cliente/proveedor a actualizar - * @param companyId - ID de la compañía - * @param data - Datos a actualizar - */ - update: (id: number, companyId: number, data: UpdateClientProviderData) => - api.patch(`/v1/a76/clients-providers/${id}?company_id=${companyId}`, data), - - /** - * Alterna el estado activo/inactivo de un cliente/proveedor - * @param id - ID del cliente/proveedor - * @param companyId - ID de la compañía - */ - toggleStatus: (id: number, companyId: number) => - api.put( - `/v1/a76/clients-providers/${id}/toggle-status/?company_id=${companyId}`, - {} - ), - - /** - * Elimina un cliente/proveedor - * @param id - ID del cliente/proveedor a eliminar - * @param companyId - ID de la compañía - */ - delete: (id: number, companyId: number) => - api.delete(`/v1/a76/clients-providers/${id}?company_id=${companyId}`) -}; + delete: (id: number, companyId: number) => + api.delete(`/v1/a76/clients-providers/${id}?company_id=${companyId}`) +}; \ No newline at end of file diff --git a/frontend/src/lib/api/dashboard/a76/general_catalogs/units-of-measure.ts b/frontend/src/lib/api/dashboard/a76/general_catalogs/units-of-measure.ts index 2aa553ca..f680bae3 100644 --- a/frontend/src/lib/api/dashboard/a76/general_catalogs/units-of-measure.ts +++ b/frontend/src/lib/api/dashboard/a76/general_catalogs/units-of-measure.ts @@ -183,7 +183,7 @@ export interface UnitOfMeasureGeneralUpdate { } export interface UnitOfMeasureGeneralListResponse { - items: UnitOfMeasureGeneral[]; + items: UnitOfMeasureGeneral[]; total: number; page: number; page_size: number; @@ -273,3 +273,38 @@ export async function updateUnitOfMeasureCustoms(id: number, data: UnitOfMeasure export async function deleteUnitOfMeasureCustoms(id: number, companyId: number): Promise> { return await api.delete(`/v1/a76/units-of-measure/customs/${id}/?company_id=${companyId}`); } + +export interface UnitOfMeasure { + id: number; + code: string; // Ej: KG, PZ + description: string | null; + description_en: string | null; + customs_code: string | null; + american_code: string | null; + created_at: string | null; + updated_at: string | null; +} + +export interface UnitOfMeasureListResponse { + items: UnitOfMeasure[]; + total: number; + page: number; + page_size: number; + pages: number; +} + +export async function getUnitsOfMeasure( + page: number = 1, + pageSize: number = 50, + companyId: number, + filters: Record = {} +): Promise> { + const queryParams = new URLSearchParams({ + page: page.toString(), + page_size: pageSize.toString(), + company_id: companyId.toString(), + ...filters + }); + // Apunta a /v1/a76/units-of-measure/ (La ruta base del router) + return await api.get(`/v1/a76/units-of-measure/?${queryParams.toString()}`); +} \ No newline at end of file diff --git a/frontend/src/lib/api/dashboard/a76/material-types.ts b/frontend/src/lib/api/dashboard/a76/material-types.ts new file mode 100644 index 00000000..e0c0e39a --- /dev/null +++ b/frontend/src/lib/api/dashboard/a76/material-types.ts @@ -0,0 +1,23 @@ +import { api } from '$lib/api'; + + +export interface MaterialType { + key: string; + type: string; + description: string; +} + + +export interface MaterialTypeListResponse { + items: MaterialType[]; + total: number; + page: number; + page_size: number; +} + +export const materialTypesApi = { + list: async (page = 1, pageSize = 100) => { + + return api.get(`/v1/public/reference-data/material-types/?page=${page}&page_size=${pageSize}`); + } +}; \ No newline at end of file diff --git a/frontend/src/lib/api/dashboard/a76/parts.ts b/frontend/src/lib/api/dashboard/a76/parts.ts new file mode 100644 index 00000000..88538db8 --- /dev/null +++ b/frontend/src/lib/api/dashboard/a76/parts.ts @@ -0,0 +1,150 @@ +import { api } from '$lib/api'; +import type { ApiResponse } from '$lib/api'; + +export interface FaData { + origin_country?: string | null; + sector?: string | null; + fraction_type?: string | null; +} + +export interface InvData { + part_type?: string | null; + material_type?: string | null; + reference_number?: string | null; + flex_reference_number?: string | null; + equivalent_uom?: string | null; + conversion_factor?: number | null; + stock_uom?: string | null; + alternate_uom?: string | null; + conversion_uom?: string | null; + added_value?: number | null; + added_value_type?: string | null; + assigned_client?: string | null; + supplier_code?: string | null; + is_textile?: string | null; + bom_version?: number | null; + is_repair?: string | null; + is_hazardous?: string | null; + emergency_number?: string | null; + danger_class?: string | null; + packaging_group?: string | null; + width?: string | null; + thickness?: string | null; + specification?: string | null; + total_value?: number | null; + direct_labor?: number | null; + general_expenses?: number | null; + total_expenses?: number | null; + depreciation?: number | null; + tooling?: number | null; + material_consumed?: number | null; + profit?: number | null; + us_fraction_alt?: string | null; + ca_fraction?: string | null; + ad_valorem_us?: number | null; + nafta_result?: string | null; + nafta_percentage?: number | null; + dta?: string | null; + dtb?: string | null; + dtg?: string | null; +} + + +export interface Part { + id: number; + tenant_id: number; + company_id: number; + client_id: number; + + // Identificación + part_number: string; + commercial_part_number: string | null; + + // Descripciones y Clase + description_spanish: string | null; + description_english: string | null; + part_class: string | null; + unit_of_measure: string | null; + + // Costos y Pesos + unit_cost: number | null; + currency_key: string | null; + currency_type: string | null; + unit_weight: number | null; + weight_type: string | null; + + // Regulatorio + fraction: string | null; + us_fraction: string | null; + fda_key: string | null; + fcc_key: string | null; + license_code: string | null; + eccn: string | null; + export_code: string | null; + exclusion_symbol: string | null; + + // Estado y Media + is_active: boolean; + part_photo: string | null; + created_at: string; + updated_at: string; + + + fa_data?: FaData | null; + inv_data?: InvData | null; +} + + +export interface PartCreate extends Omit { +} + + +export interface PartUpdate extends Partial {} + + +export interface PartListResponse { + items: Part[]; + total: number; + page: number; + page_size: number; + pages: number; +} + +export const partsApi = { + + list: (params: { + company_id: number; + page?: number; + page_size?: number; + q?: string + }) => { + const { company_id, page = 1, page_size = 50, q = '' } = params; + const skip = (page - 1) * page_size; + + const query = new URLSearchParams({ + company_id: company_id.toString(), + skip: skip.toString(), + limit: page_size.toString(), + description: q + }); + + return api.get(`/v1/a76/parts/?${query.toString()}`); + }, + + get: (id: number, company_id: number) => { + return api.get(`/v1/a76/parts/${id}?company_id=${company_id}`); + }, + + create: (data: PartCreate, company_id: number) => { + return api.post(`/v1/a76/parts/?company_id=${company_id}`, data); + }, + + update: (id: number, data: PartUpdate, company_id: number) => { + return api.put(`/v1/a76/parts/${id}?company_id=${company_id}`, data); + }, + + + delete: (id: number, company_id: number) => { + return api.delete(`/v1/a76/parts/${id}?company_id=${company_id}`); + } +}; \ No newline at end of file diff --git a/frontend/src/lib/components/dashboard/clients_and_providers/columns.ts b/frontend/src/lib/components/dashboard/clients_and_providers/columns.ts index ef8ea700..a09246ab 100644 --- a/frontend/src/lib/components/dashboard/clients_and_providers/columns.ts +++ b/frontend/src/lib/components/dashboard/clients_and_providers/columns.ts @@ -1,111 +1,101 @@ -import type { ColumnDef } from "@tanstack/table-core"; import { renderComponent, renderSnippet } from "$lib/components/ui/data-table/index.js"; import { createRawSnippet } from "svelte"; import DataTableActions from "./data-table-actions.svelte"; -import type { ClientProvider } from "$lib/api/dashboard/a76/clients-providers"; -export type { ClientProvider }; +export function createColumns(onSuccess) { + return [ + { + accessorKey: "id", + header: "ID", + cell: ({ row }) => { + const snippet = createRawSnippet((getData) => { + const { val } = getData(); + return { render: () => `${val}` }; + }); + return renderSnippet(snippet, { val: row.original.id }); + } + }, + { + accessorKey: "rfc", + header: "RFC", + cell: ({ row }) => { + const snippet = createRawSnippet((getData) => { + const { val } = getData(); + return { render: () => `${val}` }; + }); + return renderSnippet(snippet, { val: row.original.rfc }); + } + }, + { + accessorKey: "name", + header: "Nombre", + cell: ({ row }) => { + const snippet = createRawSnippet((getData) => { + const { val } = getData(); + return { render: () => `
${val}
` }; + }); + return renderSnippet(snippet, { val: row.original.name }); + } + }, + { + id: "country", + header: "País", + cell: ({ row }) => { + const snippet = createRawSnippet((getData) => { + const { val } = getData(); + return { render: () => `
${val || '-'}
` }; + }); + // Busca en address.country, si no existe pone null + const country = row.original.address?.country; + return renderSnippet(snippet, { val: country }); + } + }, + { + accessorKey: "client_or_provider", + header: "Tipo", + cell: ({ row }) => { + const snippet = createRawSnippet((getData) => { + const { val } = getData(); + const map = { client: 'Cliente', provider: 'Proveedor', both: 'Ambos' }; + const colors = { + client: 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300', + provider: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300', + both: 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-300' + }; + return { + render: () => `${map[val] || val}` + }; + }); + return renderSnippet(snippet, { val: row.original.client_or_provider }); + } + }, + // --- CORRECCIÓN AQUÍ --- + { + accessorKey: "is_active", + header: "Estado", + cell: ({ row }) => { + const snippet = createRawSnippet((getData) => { + const { val } = getData(); + + + const isActive = !!val; -export function createColumns(onSuccess?: () => void): ColumnDef[] { - return [ - { - accessorKey: "id", - header: "ID", - cell: ({ row }) => { - const idSnippet = createRawSnippet<[{ id: number }]>((getId) => { - const { id } = getId(); - return { - render: () => - `${id}` - }; - }); - return renderSnippet(idSnippet, { id: row.original.id }); - } - }, - { - accessorKey: "rfc", - header: "RFC", - cell: ({ row }) => { - const rfcSnippet = createRawSnippet<[{ rfc: string }]>((getRfc) => { - const { rfc } = getRfc(); - return { - render: () => - `${rfc}` - }; - }); - return renderSnippet(rfcSnippet, { rfc: row.original.rfc }); - } - }, - { - accessorKey: "name", - header: "Nombre", - cell: ({ row }) => { - const nameSnippet = createRawSnippet<[{ name: string }]>((getName) => { - const { name } = getName(); - return { - render: () => `
${name}
` - }; - }); - return renderSnippet(nameSnippet, { name: row.original.name }); - } - }, - { - accessorKey: "client_or_provider", - header: "Tipo", - cell: ({ row }) => { - const typeSnippet = createRawSnippet<[{ type: string | null | undefined }]>((getType) => { - const { type } = getType(); - const displayType = type === 'client' ? 'Cliente' : type === 'provider' ? 'Proveedor' : type === 'both' ? 'Ambos' : 'N/A'; - const colorClass = type === 'client' ? 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300' - : type === 'provider' ? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300' - : type === 'both' ? 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-300' - : 'bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-300'; - return { - render: () => `${displayType}` - }; - }); - return renderSnippet(typeSnippet, { type: row.original.client_or_provider }); - } - }, - { - accessorKey: "residence_country", - header: "País", - cell: ({ row }) => { - const countrySnippet = createRawSnippet<[{ country: string | null | undefined }]>((getCountry) => { - const { country } = getCountry(); - return { - render: () => `
${country || '-'}
` - }; - }); - return renderSnippet(countrySnippet, { country: row.original.residence_country }); - } - }, - { - accessorKey: "is_active", - header: "Estado", - cell: ({ row }) => { - const statusSnippet = createRawSnippet<[{ status: number | undefined }]>((getStatus) => { - const { status } = getStatus(); - const isEnabled = status === 1; - const statusText = isEnabled ? 'Activo' : 'Inactivo'; - const colorClass = isEnabled - ? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300' - : 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300'; - return { - render: () => `${statusText}` - }; - }); - return renderSnippet(statusSnippet, { status: row.original.is_active }); - } - }, - { - id: "actions", - cell: ({ row }) => { - return renderComponent(DataTableActions, { item: row.original, onSuccess }); - } - } - ]; -} - -// Mantener compatibilidad hacia atrás -export const columns = createColumns(); + const text = isActive ? 'Activo' : 'Inactivo'; + const color = isActive + ? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300' + : 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300'; + + return { + render: () => `${text}` + }; + }); + return renderSnippet(snippet, { val: row.original.is_active }); + } + }, + { + id: "actions", + header: "Acciones", + cell: ({ row }) => renderComponent(DataTableActions, { item: row.original, onSuccess }) + } + ]; +} \ No newline at end of file diff --git a/frontend/src/lib/components/dashboard/classes/columns.ts b/frontend/src/lib/components/dashboard/goods/classes/columns.ts similarity index 99% rename from frontend/src/lib/components/dashboard/classes/columns.ts rename to frontend/src/lib/components/dashboard/goods/classes/columns.ts index f5535b3c..69f88da4 100644 --- a/frontend/src/lib/components/dashboard/classes/columns.ts +++ b/frontend/src/lib/components/dashboard/goods/classes/columns.ts @@ -166,6 +166,7 @@ export function createColumns(onSuccess?: () => void): ColumnDef[] { }, { id: "actions", + header: "Acciones", cell: ({ row }) => { return renderComponent(DataTableActions, { item: row.original, onSuccess }); } diff --git a/frontend/src/lib/components/dashboard/classes/create-edit-dialog.svelte b/frontend/src/lib/components/dashboard/goods/classes/create-edit-dialog.svelte similarity index 100% rename from frontend/src/lib/components/dashboard/classes/create-edit-dialog.svelte rename to frontend/src/lib/components/dashboard/goods/classes/create-edit-dialog.svelte diff --git a/frontend/src/lib/components/dashboard/classes/data-table-actions.svelte b/frontend/src/lib/components/dashboard/goods/classes/data-table-actions.svelte similarity index 95% rename from frontend/src/lib/components/dashboard/classes/data-table-actions.svelte rename to frontend/src/lib/components/dashboard/goods/classes/data-table-actions.svelte index 51f21088..ad2ad6b6 100644 --- a/frontend/src/lib/components/dashboard/classes/data-table-actions.svelte +++ b/frontend/src/lib/components/dashboard/goods/classes/data-table-actions.svelte @@ -5,6 +5,7 @@ import { companyStore } from "$lib/stores/company.svelte"; import { EllipsisVertical, Pencil, LoaderCircle, Trash2 } from 'lucide-svelte'; import CreateEditDialog from "./create-edit-dialog.svelte"; + import { goto } from "$app/navigation"; let { item, @@ -88,7 +89,7 @@ Acciones - + { goto(`/dashboard/goods/classes/edit/${item.id}`); }} > Editar diff --git a/frontend/src/lib/components/dashboard/classes/data-table.svelte b/frontend/src/lib/components/dashboard/goods/classes/data-table.svelte similarity index 100% rename from frontend/src/lib/components/dashboard/classes/data-table.svelte rename to frontend/src/lib/components/dashboard/goods/classes/data-table.svelte diff --git a/frontend/src/lib/components/dashboard/goods/modales/client-selector-dialog.svelte b/frontend/src/lib/components/dashboard/goods/modales/client-selector-dialog.svelte new file mode 100644 index 00000000..65399818 --- /dev/null +++ b/frontend/src/lib/components/dashboard/goods/modales/client-selector-dialog.svelte @@ -0,0 +1,167 @@ + + + + + + Seleccionar Cliente + + Busca y selecciona el cliente propietario de la parte. + + + +
+ + +
+ +
+ {#if loading} +
+ +

Cargando catálogo...

+
+ {:else if filteredClients.length === 0} +
+

No se encontraron clientes.

+
+ {:else} + + + + + + + + + + + + {#each filteredClients as client} + + + + + + + + {/each} + +
IDRFCRazón SocialEstadoAcción
{client.id}{client.rfc} +
+ {#if client.client_or_provider === 'client'} + + {:else} + + {/if} + {client.name} +
+
+ {#if client.is_active} + + Activo + + {:else} + + Baja + + {/if} + + +
+ {/if} +
+ + +
+ Mostrando {filteredClients.length} registro(s) +
+ +
+
+
\ No newline at end of file diff --git a/frontend/src/lib/components/dashboard/goods/modales/material-type-selector-dialog.svelte b/frontend/src/lib/components/dashboard/goods/modales/material-type-selector-dialog.svelte new file mode 100644 index 00000000..5fa0974f --- /dev/null +++ b/frontend/src/lib/components/dashboard/goods/modales/material-type-selector-dialog.svelte @@ -0,0 +1,133 @@ + + + + + + Seleccionar Tipo de Material + Catálogo general. + + +
+ + +
+ +
+ {#if loading} +
+ +

Cargando catálogo...

+
+ {:else if filteredItems.length === 0} +
+

No se encontraron resultados.

+
+ {:else} + + + + + + + + + + + {#each filteredItems as item} + + + + + + + + + + {/each} + +
ClaveDescripciónTipoAcción
{item.key}{item.description} +
+ + {item.type} +
+
+ +
+ {/if} +
+ + + +
+
\ No newline at end of file diff --git a/frontend/src/lib/components/dashboard/goods/modales/unit-measure-dialog.svelte b/frontend/src/lib/components/dashboard/goods/modales/unit-measure-dialog.svelte new file mode 100644 index 00000000..0deb485c --- /dev/null +++ b/frontend/src/lib/components/dashboard/goods/modales/unit-measure-dialog.svelte @@ -0,0 +1,179 @@ + + + + + + Seleccionar Unidad de Medida + + Busca y selecciona una unidad del catálogo maestro. + + + +
+
+ + +
+ +
+ {#if loading} +
+ +
+ {/if} + + + + + Código + Descripción + + + + + {#if items.length === 0 && !loading} + + + No se encontraron resultados + + + {:else} + {#each items as item} + handleSelect(item)} + > + {item.code} + +
+ {item.description || '-'} + {#if item.description_en} + {item.description_en} + {/if} +
+
+ + + +
+ {/each} + {/if} +
+
+
+ +
+ Página {page} de {totalPages} +
+ + +
+
+
+
+
\ No newline at end of file diff --git a/frontend/src/lib/components/dashboard/goods/parts/class-selector-dialog.svelte b/frontend/src/lib/components/dashboard/goods/parts/class-selector-dialog.svelte new file mode 100644 index 00000000..5d03286a --- /dev/null +++ b/frontend/src/lib/components/dashboard/goods/parts/class-selector-dialog.svelte @@ -0,0 +1,166 @@ + + + + + + Seleccionar Clase (Anexo 24) + + Seleccione la clasificación del material. + + + +
+ + +
+ +
+ {#if loading} +
+ +

Cargando catálogo...

+
+ {:else if filteredItems.length === 0} +
+

No se encontraron clases.

+
+ {:else} + + + + + + + + + + + {#each filteredItems as item} + + + + + + + + + + {/each} + +
ClaveDescripciónUMAcción
+ + {item.class_code} + + +
+ + + {item.description_es || 'Sin descripción'} + +
+
+
+ + {item.unit_of_measure || '-'} +
+
+ +
+ {/if} +
+ + +
+ {filteredItems.length} registros encontrados +
+ +
+
+
\ No newline at end of file diff --git a/frontend/src/lib/components/dashboard/goods/parts/columns.ts b/frontend/src/lib/components/dashboard/goods/parts/columns.ts new file mode 100644 index 00000000..6230f6f1 --- /dev/null +++ b/frontend/src/lib/components/dashboard/goods/parts/columns.ts @@ -0,0 +1,177 @@ +import type { ColumnDef } from "@tanstack/table-core"; +import { renderComponent, renderSnippet } from "$lib/components/ui/data-table/index.js"; +import { createRawSnippet } from "svelte"; +import DataTableActions from "./data-table-actions.svelte"; +import type { Part } from "$lib/api/dashboard/a76/parts"; + +/** + * Formatea moneda (USD/MXN) + */ +function formatCurrency(amount: number | null, currency: string | null): string { + if (amount === null || amount === undefined) return '-'; + return new Intl.NumberFormat('en-US', { + style: 'currency', + currency: currency || 'USD', + minimumFractionDigits: 4 + }).format(amount); +} + +export function createColumns(onSuccess?: () => void): ColumnDef[] { + return [ + + { + accessorKey: "is_active", + header: "Status", + cell: ({ row }) => { + const statusSnippet = createRawSnippet<[{ active: boolean }]>((getStatus) => { + const { active } = getStatus(); + return { + render: () => active + ? `Activo` + : `Inactivo` + }; + }); + return renderSnippet(statusSnippet, { active: row.original.is_active }); + } + }, + + + { + accessorKey: "part_number", + header: "No. Parte", + cell: ({ row }) => { + const pnSnippet = createRawSnippet<[{ pn: string }]>((getPn) => { + const { pn } = getPn(); + return { + render: () => + `
${pn}
` + }; + }); + return renderSnippet(pnSnippet, { pn: row.original.part_number }); + } + }, + + + { + accessorKey: "description_spanish", + header: "Descripción", + cell: ({ row }) => { + const descSnippet = createRawSnippet<[{ desc: string }]>((getDesc) => { + const { desc } = getDesc(); + return { + render: () => + `
${desc || '-'}
` + }; + }); + return renderSnippet(descSnippet, { desc: row.original.description_spanish || '' }); + } + }, + + { + accessorKey: "description_english", + header: "Desc. Inglés", + cell: ({ row }) => { + const descEnSnippet = createRawSnippet<[{ desc: string }]>((getDesc) => { + const { desc } = getDesc(); + return { + render: () => + `
${desc || '-'}
` + }; + }); + return renderSnippet(descEnSnippet, { desc: row.original.description_english || '' }); + } + }, + + + { + accessorKey: "part_class", + header: "Clase", + cell: ({ row }) => { + const classSnippet = createRawSnippet<[{ cls: string }]>((getCls) => { + const { cls } = getCls(); + return { + render: () => `
${cls || '-'}
` + }; + }); + return renderSnippet(classSnippet, { cls: row.original.part_class || '' }); + } + }, + + + { + accessorKey: "commercial_part_number", + header: "Tipo", + cell: ({ row }) => { + const typeSnippet = createRawSnippet<[{ val: string }]>((getType) => { + const { val } = getType(); + return { + render: () => `
${val || '-'}
` + }; + }); + return renderSnippet(typeSnippet, { val: row.original.commercial_part_number || '' }); + } + }, + + // 7. FRACCION + { + accessorKey: "fraction", + header: "Fracción", + cell: ({ row }) => { + const fracSnippet = createRawSnippet<[{ fr: string }]>((getFrac) => { + const { fr } = getFrac(); + return { + render: () => `${fr || '-'}` + }; + }); + return renderSnippet(fracSnippet, { fr: row.original.fraction || '' }); + } + }, + + // 8. UMT (Unidad de Medida) + { + accessorKey: "unit_of_measure", + header: "UMT", + cell: ({ row }) => { + const umtSnippet = createRawSnippet<[{ um: string }]>((getUm) => { + const { um } = getUm(); + return { + render: () => + ` + ${um} + ` + }; + }); + return renderSnippet(umtSnippet, { um: row.original.unit_of_measure }); + } + }, + + // 9. COSTO + { + accessorKey: "unit_cost", + header: "Costo", + cell: ({ row }) => { + const costSnippet = createRawSnippet<[{ amount: number | null, curr: string | null }]>((getCost) => { + const { amount, curr } = getCost(); + return { + render: () => `
${formatCurrency(amount, curr)}
` + }; + }); + return renderSnippet(costSnippet, { + amount: row.original.unit_cost, + curr: row.original.currency_key + }); + } + }, + + // ACCIONES + { + id: "actions", + header: "", + cell: ({ row }) => { + return renderComponent(DataTableActions, { item: row.original, onSuccess }); + } + } + ]; +} + +export const columns = createColumns(); \ No newline at end of file diff --git a/frontend/src/lib/components/dashboard/goods/parts/create-edit-dialog.svelte b/frontend/src/lib/components/dashboard/goods/parts/create-edit-dialog.svelte new file mode 100644 index 00000000..aaaaafa4 --- /dev/null +++ b/frontend/src/lib/components/dashboard/goods/parts/create-edit-dialog.svelte @@ -0,0 +1,520 @@ + + + + + + {title} + + {isEdit ? 'Modifica los datos de la clase' : 'Completa los datos para crear una nueva clase'} + + + +
+ + {#if error} +
+ {error} +
+ {/if} + + + {#if companyStore.activeCompany} +
+
+ + + + +
+

+ {companyStore.activeCompany.name} +

+

+ ID: {companyStore.activeCompany.id} +

+
+
+
+ {/if} + + +
+ + {#if loadingClients} +
+
+ Cargando clientes... +
+ {:else if clients.length > 0} + + {:else} +
+ No hay clientes disponibles +
+ {/if} +
+ + +
+ + +
+ + +
+
+ +