From d4e4e1f7f849afae2c9d739e93e4c24a09dcb1ed Mon Sep 17 00:00:00 2001 From: Kevin_Ramirez Date: Thu, 22 Jan 2026 08:10:57 -0600 Subject: [PATCH 1/4] Se corrigio el problema de los logos --- .../a76/general_catalogs/company/models.py | 5 +- .../a76/general_catalogs/company/routes.py | 56 +------ .../a76/general_catalogs/company/service.py | 12 ++ .../a76/general_catalogs/units-of-measure.ts | 2 +- .../components/sidebar/team-switcher.svelte | 6 +- frontend/src/lib/stores/company.svelte.ts | 24 +++ .../edit/[[id]]/+page.svelte | 94 ++++------- schema_dump.txt | 151 ++++++++++++++++++ 8 files changed, 227 insertions(+), 123 deletions(-) create mode 100644 schema_dump.txt diff --git a/backend/api/v1/modules/a76/general_catalogs/company/models.py b/backend/api/v1/modules/a76/general_catalogs/company/models.py index ae94fc89..fdcc0262 100644 --- a/backend/api/v1/modules/a76/general_catalogs/company/models.py +++ b/backend/api/v1/modules/a76/general_catalogs/company/models.py @@ -61,9 +61,9 @@ class Company(Base, TimestampMixin): # Configuración básica logo: Mapped[Optional[str]] = mapped_column(String(255)) - has_express_line: Mapped[Optional[bool]] = mapped_column(Boolean, default=False) + has_express_line: Mapped[Optional[str]] = mapped_column(String(2), default="N") order_format_type: Mapped[Optional[str]] = mapped_column(String(19)) - is_service_company: Mapped[Optional[bool]] = mapped_column(Boolean, default=False) + is_service_company: Mapped[Optional[str]] = mapped_column(String(2), default="N") client_name: Mapped[Optional[str]] = mapped_column(String(300)) subassembly_mode: Mapped[Optional[str]] = mapped_column(String(7)) @@ -78,6 +78,7 @@ class Company(Base, TimestampMixin): parts_replacement: Mapped[Optional[int]] = mapped_column(SmallInteger) activate_facmexame: Mapped[Optional[int]] = mapped_column(SmallInteger) part_reference: Mapped[Optional[int]] = mapped_column(SmallInteger) + part_reference: Mapped[Optional[int]] = mapped_column(SmallInteger) international_firm: Mapped[Optional[int]] = mapped_column(SmallInteger) # Configuraciones simples diff --git a/backend/api/v1/modules/a76/general_catalogs/company/routes.py b/backend/api/v1/modules/a76/general_catalogs/company/routes.py index cc59a1bc..6aadda85 100644 --- a/backend/api/v1/modules/a76/general_catalogs/company/routes.py +++ b/backend/api/v1/modules/a76/general_catalogs/company/routes.py @@ -312,68 +312,14 @@ async def update_company( return CompanyResponseDTO.model_validate(updated_company) -@router.post( - "/{company_id}/upload-logo", - response_model=dict, - summary="Upload company logo", -) -async def upload_company_logo( - company_id: int, - file: UploadFile = File(...), - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """Upload logo for a company""" - tenant_id = current_user.get("tenant_id") - if not tenant_id: - raise HTTPException( - status_code=status.HTTP_400_BAD_REQUEST, - detail="Tenant ID not found in user data", - ) - # 1. Verify company exists - company = CompanyService.get_by_id(db, company_id, tenant_id, 0) - if not company: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND, - detail="Company not found", - ) - - # 2. Define upload path - # Use a persistent path: 'app_data/logos/{company_id}' - upload_dir = Path(f"app_data/logos/{company_id}") - upload_dir.mkdir(parents=True, exist_ok=True) - - # 3. Save file - # Preserve original filename - filename = file.filename or "logo.png" - file_path = upload_dir / filename - - try: - # Check if file exists and remove it to avoid accumulation if needed, - # or just overwrite (shutil.copyfileobj overwrites) - with open(file_path, "wb") as buffer: - shutil.copyfileobj(file.file, buffer) - except Exception as e: - raise HTTPException( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=f"Could not save file: {e}", - ) - - # 4. Returns the absolute path keys - abs_path = str(file_path.absolute()) - - return {"path": abs_path} @router.get( "/{company_id}/logo/image", summary="Get company logo image", ) -@router.get( - "/{company_id}/logo/image", - summary="Get company logo image", -) + async def get_company_logo_image( company_id: int, db: Session = Depends(get_core_db), diff --git a/backend/api/v1/modules/a76/general_catalogs/company/service.py b/backend/api/v1/modules/a76/general_catalogs/company/service.py index 63835cd1..5ed24feb 100644 --- a/backend/api/v1/modules/a76/general_catalogs/company/service.py +++ b/backend/api/v1/modules/a76/general_catalogs/company/service.py @@ -112,7 +112,14 @@ class CompanyService: # Update only provided fields update_data = company_data.model_dump(exclude_unset=True) + boolean_fields_str = ["has_express_line", "is_service_company"] + for field, value in update_data.items(): + if field in boolean_fields_str: + # Convert boolean to "S"/"N" + if isinstance(value, bool): + value = "S" if value else "N" + setattr(company, field, value) try: @@ -177,6 +184,11 @@ class CompanyService: # 1. Preparar datos obj_data = data.model_dump(exclude_unset=True) + boolean_fields_str = ["has_express_line", "is_service_company"] + for field in boolean_fields_str: + if field in obj_data and isinstance(obj_data[field], bool): + obj_data[field] = "S" if obj_data[field] else "N" + # 2. Crear objeto SQLAlchemy db_obj = Company(**obj_data, tenant_id=tenant_id) 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 f680bae3..7b731651 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; diff --git a/frontend/src/lib/components/sidebar/team-switcher.svelte b/frontend/src/lib/components/sidebar/team-switcher.svelte index c61c8a3d..088b02df 100644 --- a/frontend/src/lib/components/sidebar/team-switcher.svelte +++ b/frontend/src/lib/components/sidebar/team-switcher.svelte @@ -10,10 +10,10 @@ const sidebar = useSidebar(); - // Derivar la URL del logo + // Derivar la URL del logo usando el endpoint específico let activeCompanyLogoUrl = $derived( companyStore.activeCompany?.logo - ? getBackendAssetUrl(companyStore.activeCompany.logo) + ? getBackendAssetUrl(`v1/a76/company/${companyStore.activeCompany.id}/logo/image?t=${new Date().getTime()}`) : null ); @@ -89,7 +89,7 @@
{#if company.logo} {company.name} diff --git a/frontend/src/lib/stores/company.svelte.ts b/frontend/src/lib/stores/company.svelte.ts index b3da0f1f..9f04bcdb 100644 --- a/frontend/src/lib/stores/company.svelte.ts +++ b/frontend/src/lib/stores/company.svelte.ts @@ -144,6 +144,30 @@ class CompanyStore { } } + /** + * Actualiza los datos de une empresa en el store localmente + * Útil para reflejar cambios inmediatos (ej: cambio de logo) sin recargar + */ + updateCompany(id: number, data: Partial) { + // 1. Actualizar en la lista + const index = this._companies.findIndex(c => c.id === id); + if (index !== -1) { + this._companies[index] = { ...this._companies[index], ...data }; + + // 2. Si es la activa, actualizar también + if (this._activeCompany?.id === id) { + this._activeCompany = { ...this._activeCompany, ...data }; + // Actualizar persistencia si es necesario + if (typeof window !== 'undefined') { + // Disparar evento para notificar cambios a componentes que no usan el store reactivo directo (si los hay) + window.dispatchEvent(new CustomEvent('companyChanged', { + detail: { companyId: id } + })); + } + } + } + } + /** * Restaura la compañía activa desde localStorage */ diff --git a/frontend/src/routes/dashboard/general_catalogs/company_information/edit/[[id]]/+page.svelte b/frontend/src/routes/dashboard/general_catalogs/company_information/edit/[[id]]/+page.svelte index 136f81ff..290ce649 100644 --- a/frontend/src/routes/dashboard/general_catalogs/company_information/edit/[[id]]/+page.svelte +++ b/frontend/src/routes/dashboard/general_catalogs/company_information/edit/[[id]]/+page.svelte @@ -14,6 +14,7 @@ uploadCompanyLogo, type Company } from '$lib/api/dashboard/a76/general_catalogs/company'; + import { companyStore } from '$lib/stores/company.svelte'; import { getBackendAssetUrl } from '$lib/utils'; import { ArrowLeft, LoaderCircle, Save, Upload, X, Building2, FileText, User, Settings } from 'lucide-svelte'; @@ -25,15 +26,18 @@ let loading = $state(false); let uploading = $state(false); let error = $state(null); + let activeTab = $state('general'); + let logoFile = $state(null); let logoPreview = $state(null); let currentLogo = $state(null); let uploadingLogo = $state(false); - let activeTab = $state('general'); - + // URL completa del logo derivada let currentLogoUrl = $derived( - logoPreview || getBackendAssetUrl(currentLogo) || '' + logoPreview + ? logoPreview + : (currentLogo ? getBackendAssetUrl(`v1/a76/company/${id}/logo/image?t=${new Date().getTime()}`) : '') ); // 2. Estado Inicial (Reset) @@ -104,7 +108,15 @@ is_service_company: item.is_service_company || false, order_format_type: item.order_format_type || '', ctpat_svi: item.ctpat_svi || '', - trusted_exporter_number: item.trusted_exporter_number || '' + trusted_exporter_number: item.trusted_exporter_number || '', + logo: item.logo || '', + previous_code: item.previous_code || 0, + client_name: item.client_name || '', + subassembly_mode: item.subassembly_mode || '', + broker_company: item.broker_company || '', + inter_db_name: item.inter_db_name || '', + prevalidator_key: item.prevalidator_key || '', + seventh_amendment: item.seventh_amendment || false }; // Guardar la URL del logo actual si existe if (item.logo) { @@ -118,6 +130,9 @@ } } + + const clean = (value: any) => (typeof value === 'string' ? value.trim() || null : value); + function handleLogoChange(event: Event) { const target = event.target as HTMLInputElement; const file = target.files?.[0]; @@ -170,6 +185,9 @@ currentLogo = response.data.logo_path; logoFile = null; logoPreview = null; + + // Actualizar el store reactivamente + companyStore.updateCompany(companyId, { logo: response.data.logo_path }); } } catch (e: any) { error = `Error al subir el logo: ${e.message}`; @@ -178,33 +196,6 @@ } } - const clean = (value: any) => (typeof value === 'string' ? value.trim() || null : value); - - async function handleFileSelect(e: Event) { - const input = e.target as HTMLInputElement; - if (!input.files || input.files.length === 0) return; - - const file = input.files[0]; - if (!isEdit) { - alert("Primero debes guardar la empresa antes de subir un logo."); - return; - } - - uploading = true; - try { - const res = await uploadCompanyLogo(Number(id), file); - if (res.data) { - formData.logo = res.data.path; - } else if (res.error) { - alert("Error al subir imagen: " + res.error); - } - } catch (err) { - alert("Error al intentar subir la imagen"); - } finally { - uploading = false; - } - } - async function handleSubmit() { error = null; loading = true; @@ -222,6 +213,7 @@ main_activity: clean(formData.main_activity), program: clean(formData.program), program_number: clean(formData.program_number), + prosec: Number(formData.prosec) || 0, prosec_authorization: clean(formData.prosec_authorization), responsible_name: clean(formData.responsible_name), responsible_last_name: clean(formData.responsible_last_name), @@ -239,7 +231,10 @@ broker_company: clean(formData.broker_company), inter_db_name: clean(formData.inter_db_name), prevalidator_key: clean(formData.prevalidator_key), - seventh_amendment: formData.seventh_amendment + seventh_amendment: formData.seventh_amendment, + // Ensure optional booleans are passed correctly or default to false/null if needed + has_express_line: formData.has_express_line, + is_service_company: formData.is_service_company }; const response = isEdit @@ -285,6 +280,8 @@
+ +
@@ -344,36 +341,9 @@
-
-
- -
- - {#if isEdit} -
- - -
- {/if} -
-

Sube una imagen para obtener su ruta local.

-
-
- - -
+
+ +
diff --git a/schema_dump.txt b/schema_dump.txt new file mode 100644 index 00000000..fbdc9a3b --- /dev/null +++ b/schema_dump.txt @@ -0,0 +1,151 @@ + Table "a76.company" + Column | Type | Collation | Nullable | Default +------------------------------+-----------------------------+-----------+----------+----------------------------------------- + id | integer | | not null | nextval('a76.company_id_seq'::regclass) + tenant_id | integer | | not null | + name | character varying(256) | | | + rfc | character varying(30) | | | + curp | character varying(19) | | | + main_activity | character varying(80) | | | + program | character varying(7) | | | + program_number | character varying(40) | | | + prosec | smallint | | | + prosec_authorization | character varying(20) | | | + sector1 | character varying(150) | | | + sector2 | character varying(150) | | | + sector3 | character varying(5) | | | + manufacturer_id | character varying(25) | | | + broker_company | character varying(6) | | | + responsible | character varying(80) | | | + responsible_name | character varying(20) | | | + responsible_last_name | character varying(20) | | | + responsible_mother_last_name | character varying(20) | | | + responsible_rfc | character varying(30) | | | + position | character varying(30) | | | + logo | character varying(255) | | | + has_express_line | character varying(2) | | | + order_format_type | character varying(19) | | | + is_service_company | boolean | | | + client_name | character varying(300) | | | + subassembly_mode | character varying(7) | | | + previous_code | smallint | | | + active_labels | smallint | | | + active_fractions | smallint | | | + activate_caat | smallint | | | + trans_interface | smallint | | | + american_costs | smallint | | | + scaf_readonly | smallint | | | + parts_replacement | smallint | | | + activate_facmexame | smallint | | | + part_reference | smallint | | | + international_firm | smallint | | | + ftp_key | character varying(10) | | | + sifra_path | character varying(255) | | | + version_type | character varying(20) | | | + sql_language | character varying(19) | | | + balance_operation_mode | character varying(50) | | | + inter_db_name | character varying(100) | | | + created_at | timestamp without time zone | | not null | now() + updated_at | timestamp without time zone | | not null | now() + deleted_at | timestamp without time zone | | | +Indexes: + "company_pkey" PRIMARY KEY, btree (id) + "ix_a76_company_tenant_id" btree (tenant_id) +Foreign-key constraints: + "company_tenant_id_fkey" FOREIGN KEY (tenant_id) REFERENCES core.tenants(id) +Referenced by: + TABLE "a76."CompanyVU"" CONSTRAINT "CompanyVU_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE + TABLE "a76.classes" CONSTRAINT "classes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.classification_concepts" CONSTRAINT "classification_concepts_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.clients_and_providers_address" CONSTRAINT "clients_and_providers_address_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.clients_and_providers" CONSTRAINT "clients_and_providers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.clients_and_providers_programs" CONSTRAINT "clients_and_providers_programs_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.company_address" CONSTRAINT "company_address_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE + TABLE "a76.company_certification" CONSTRAINT "company_certification_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE + TABLE "a76.company_cfdi" CONSTRAINT "company_cfdi_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE + TABLE "a76.company_digital_certificate" CONSTRAINT "company_digital_certificate_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE + TABLE "a76.company_electronic_agent" CONSTRAINT "company_electronic_agent_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE + TABLE "a76.company_prevalidator" CONSTRAINT "company_prevalidator_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE + TABLE "core.company_roles" CONSTRAINT "company_roles_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.country_rule_oct" CONSTRAINT "country_rule_oct_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.ctm_receipts" CONSTRAINT "ctm_receipts_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.customs_brokers" CONSTRAINT "customs_brokers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.customs_brokers_personnel" CONSTRAINT "customs_brokers_personnel_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.customs_brokers_vu" CONSTRAINT "customs_brokers_vu_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.depreciation_catalog" CONSTRAINT "depreciation_catalog_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.document_types_digitization" CONSTRAINT "document_types_digitization_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.doda_american_pedimentos" CONSTRAINT "doda_american_pedimentos_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.doda" CONSTRAINT "doda_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.doda_container_seals" CONSTRAINT "doda_container_seals_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.doda_containers" CONSTRAINT "doda_containers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.doda_pedimentos" CONSTRAINT "doda_pedimentos_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.driver" CONSTRAINT "driver_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.electronic_notices" CONSTRAINT "electronic_notices_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.equivalencies" CONSTRAINT "equivalencies_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.equivalency_items" CONSTRAINT "equivalency_items_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.error_catalogs" CONSTRAINT "error_catalogs_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.error_classifications" CONSTRAINT "error_classifications_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.exchange_rate" CONSTRAINT "exchange_rate_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a24.fa_classes" CONSTRAINT "fa_classes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a24.fa_item_lines" CONSTRAINT "fa_item_lines_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a24.fa_partes" CONSTRAINT "fa_partes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.fda_catalog" CONSTRAINT "fda_catalog_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.fraction_rule_octave" CONSTRAINT "fraction_rule_octave_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.identifier_details" CONSTRAINT "identifier_details_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.identifiers" CONSTRAINT "identifiers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.inpc" CONSTRAINT "inpc_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a24.inv_partes" CONSTRAINT "inv_partes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.invoice_collections" CONSTRAINT "invoice_collections_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.invoice_compliance_mx" CONSTRAINT "invoice_compliance_mx_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.invoice_financials" CONSTRAINT "invoice_financials_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.invoice_header" CONSTRAINT "invoice_header_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.invoice_logistics" CONSTRAINT "invoice_logistics_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.invoice_sales_details" CONSTRAINT "invoice_sales_details_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.item_line_series" CONSTRAINT "item_line_series_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.item_lines" CONSTRAINT "item_lines_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.items" CONSTRAINT "items_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.legends" CONSTRAINT "legends_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.multi_currency_types" CONSTRAINT "multi_currency_types_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.packages" CONSTRAINT "packages_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.packing_lists" CONSTRAINT "packing_lists_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.parts" CONSTRAINT "parts_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_config_additional" CONSTRAINT "pedimento_config_additional_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_config_calculations" CONSTRAINT "pedimento_config_calculations_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_config_parameters" CONSTRAINT "pedimento_config_parameters_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_config_surcharges" CONSTRAINT "pedimento_config_surcharges_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_config_update_rectification" CONSTRAINT "pedimento_config_update_rectification_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_config_updates" CONSTRAINT "pedimento_config_updates_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_containers" CONSTRAINT "pedimento_containers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_contributions" CONSTRAINT "pedimento_contributions_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_customs_offices" CONSTRAINT "pedimento_customs_offices_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_dates" CONSTRAINT "pedimento_dates_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_decrementables" CONSTRAINT "pedimento_decrementables_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_guides" CONSTRAINT "pedimento_guides_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_incrementables" CONSTRAINT "pedimento_incrementables_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_indexes" CONSTRAINT "pedimento_indexes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_packages" CONSTRAINT "pedimento_packages_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_payments" CONSTRAINT "pedimento_payments_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_rectification_destination" CONSTRAINT "pedimento_rectification_destination_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_rectification_origin" CONSTRAINT "pedimento_rectification_origin_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_seals" CONSTRAINT "pedimento_seals_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_transport_carriers" CONSTRAINT "pedimento_transport_carriers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_transport_means" CONSTRAINT "pedimento_transport_means_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimento_validation" CONSTRAINT "pedimento_validation_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.pedimentos" CONSTRAINT "pedimentos_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.permission_rule_oct" CONSTRAINT "permission_rule_oct_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.ports" CONSTRAINT "ports_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.prevalidators" CONSTRAINT "prevalidators_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "core.role_permissions" CONSTRAINT "role_permissions_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.seal" CONSTRAINT "seal_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.signatures" CONSTRAINT "signatures_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.subassembly_entries" CONSTRAINT "subassembly_entries_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.trailer" CONSTRAINT "trailer_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.transporter" CONSTRAINT "transporter_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.unit_conversions" CONSTRAINT "unit_conversions_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.units_of_measure" CONSTRAINT "units_of_measure_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.units_of_measure_general" CONSTRAINT "units_of_measure_general_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "core.user_company_permissions" CONSTRAINT "user_company_permissions_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "core.user_company_roles" CONSTRAINT "user_company_roles_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "core.user_tenants" CONSTRAINT "user_tenants_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + TABLE "a76.vehicle" CONSTRAINT "vehicle_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) + From 69fe605901a3b980804707a952f52740a8487a58 Mon Sep 17 00:00:00 2001 From: Kevin_Ramirez Date: Thu, 22 Jan 2026 08:22:29 -0600 Subject: [PATCH 2/4] Se borro archivos basura --- schema_dump.txt | 151 ------------------------------------------------ 1 file changed, 151 deletions(-) delete mode 100644 schema_dump.txt diff --git a/schema_dump.txt b/schema_dump.txt deleted file mode 100644 index fbdc9a3b..00000000 --- a/schema_dump.txt +++ /dev/null @@ -1,151 +0,0 @@ - Table "a76.company" - Column | Type | Collation | Nullable | Default -------------------------------+-----------------------------+-----------+----------+----------------------------------------- - id | integer | | not null | nextval('a76.company_id_seq'::regclass) - tenant_id | integer | | not null | - name | character varying(256) | | | - rfc | character varying(30) | | | - curp | character varying(19) | | | - main_activity | character varying(80) | | | - program | character varying(7) | | | - program_number | character varying(40) | | | - prosec | smallint | | | - prosec_authorization | character varying(20) | | | - sector1 | character varying(150) | | | - sector2 | character varying(150) | | | - sector3 | character varying(5) | | | - manufacturer_id | character varying(25) | | | - broker_company | character varying(6) | | | - responsible | character varying(80) | | | - responsible_name | character varying(20) | | | - responsible_last_name | character varying(20) | | | - responsible_mother_last_name | character varying(20) | | | - responsible_rfc | character varying(30) | | | - position | character varying(30) | | | - logo | character varying(255) | | | - has_express_line | character varying(2) | | | - order_format_type | character varying(19) | | | - is_service_company | boolean | | | - client_name | character varying(300) | | | - subassembly_mode | character varying(7) | | | - previous_code | smallint | | | - active_labels | smallint | | | - active_fractions | smallint | | | - activate_caat | smallint | | | - trans_interface | smallint | | | - american_costs | smallint | | | - scaf_readonly | smallint | | | - parts_replacement | smallint | | | - activate_facmexame | smallint | | | - part_reference | smallint | | | - international_firm | smallint | | | - ftp_key | character varying(10) | | | - sifra_path | character varying(255) | | | - version_type | character varying(20) | | | - sql_language | character varying(19) | | | - balance_operation_mode | character varying(50) | | | - inter_db_name | character varying(100) | | | - created_at | timestamp without time zone | | not null | now() - updated_at | timestamp without time zone | | not null | now() - deleted_at | timestamp without time zone | | | -Indexes: - "company_pkey" PRIMARY KEY, btree (id) - "ix_a76_company_tenant_id" btree (tenant_id) -Foreign-key constraints: - "company_tenant_id_fkey" FOREIGN KEY (tenant_id) REFERENCES core.tenants(id) -Referenced by: - TABLE "a76."CompanyVU"" CONSTRAINT "CompanyVU_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE - TABLE "a76.classes" CONSTRAINT "classes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.classification_concepts" CONSTRAINT "classification_concepts_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.clients_and_providers_address" CONSTRAINT "clients_and_providers_address_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.clients_and_providers" CONSTRAINT "clients_and_providers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.clients_and_providers_programs" CONSTRAINT "clients_and_providers_programs_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.company_address" CONSTRAINT "company_address_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE - TABLE "a76.company_certification" CONSTRAINT "company_certification_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE - TABLE "a76.company_cfdi" CONSTRAINT "company_cfdi_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE - TABLE "a76.company_digital_certificate" CONSTRAINT "company_digital_certificate_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE - TABLE "a76.company_electronic_agent" CONSTRAINT "company_electronic_agent_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE - TABLE "a76.company_prevalidator" CONSTRAINT "company_prevalidator_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) ON DELETE CASCADE - TABLE "core.company_roles" CONSTRAINT "company_roles_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.country_rule_oct" CONSTRAINT "country_rule_oct_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.ctm_receipts" CONSTRAINT "ctm_receipts_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.customs_brokers" CONSTRAINT "customs_brokers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.customs_brokers_personnel" CONSTRAINT "customs_brokers_personnel_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.customs_brokers_vu" CONSTRAINT "customs_brokers_vu_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.depreciation_catalog" CONSTRAINT "depreciation_catalog_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.document_types_digitization" CONSTRAINT "document_types_digitization_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.doda_american_pedimentos" CONSTRAINT "doda_american_pedimentos_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.doda" CONSTRAINT "doda_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.doda_container_seals" CONSTRAINT "doda_container_seals_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.doda_containers" CONSTRAINT "doda_containers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.doda_pedimentos" CONSTRAINT "doda_pedimentos_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.driver" CONSTRAINT "driver_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.electronic_notices" CONSTRAINT "electronic_notices_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.equivalencies" CONSTRAINT "equivalencies_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.equivalency_items" CONSTRAINT "equivalency_items_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.error_catalogs" CONSTRAINT "error_catalogs_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.error_classifications" CONSTRAINT "error_classifications_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.exchange_rate" CONSTRAINT "exchange_rate_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a24.fa_classes" CONSTRAINT "fa_classes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a24.fa_item_lines" CONSTRAINT "fa_item_lines_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a24.fa_partes" CONSTRAINT "fa_partes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.fda_catalog" CONSTRAINT "fda_catalog_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.fraction_rule_octave" CONSTRAINT "fraction_rule_octave_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.identifier_details" CONSTRAINT "identifier_details_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.identifiers" CONSTRAINT "identifiers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.inpc" CONSTRAINT "inpc_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a24.inv_partes" CONSTRAINT "inv_partes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.invoice_collections" CONSTRAINT "invoice_collections_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.invoice_compliance_mx" CONSTRAINT "invoice_compliance_mx_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.invoice_financials" CONSTRAINT "invoice_financials_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.invoice_header" CONSTRAINT "invoice_header_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.invoice_logistics" CONSTRAINT "invoice_logistics_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.invoice_sales_details" CONSTRAINT "invoice_sales_details_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.item_line_series" CONSTRAINT "item_line_series_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.item_lines" CONSTRAINT "item_lines_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.items" CONSTRAINT "items_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.legends" CONSTRAINT "legends_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.multi_currency_types" CONSTRAINT "multi_currency_types_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.packages" CONSTRAINT "packages_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.packing_lists" CONSTRAINT "packing_lists_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.parts" CONSTRAINT "parts_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_config_additional" CONSTRAINT "pedimento_config_additional_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_config_calculations" CONSTRAINT "pedimento_config_calculations_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_config_parameters" CONSTRAINT "pedimento_config_parameters_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_config_surcharges" CONSTRAINT "pedimento_config_surcharges_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_config_update_rectification" CONSTRAINT "pedimento_config_update_rectification_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_config_updates" CONSTRAINT "pedimento_config_updates_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_containers" CONSTRAINT "pedimento_containers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_contributions" CONSTRAINT "pedimento_contributions_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_customs_offices" CONSTRAINT "pedimento_customs_offices_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_dates" CONSTRAINT "pedimento_dates_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_decrementables" CONSTRAINT "pedimento_decrementables_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_guides" CONSTRAINT "pedimento_guides_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_incrementables" CONSTRAINT "pedimento_incrementables_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_indexes" CONSTRAINT "pedimento_indexes_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_packages" CONSTRAINT "pedimento_packages_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_payments" CONSTRAINT "pedimento_payments_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_rectification_destination" CONSTRAINT "pedimento_rectification_destination_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_rectification_origin" CONSTRAINT "pedimento_rectification_origin_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_seals" CONSTRAINT "pedimento_seals_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_transport_carriers" CONSTRAINT "pedimento_transport_carriers_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_transport_means" CONSTRAINT "pedimento_transport_means_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimento_validation" CONSTRAINT "pedimento_validation_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.pedimentos" CONSTRAINT "pedimentos_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.permission_rule_oct" CONSTRAINT "permission_rule_oct_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.ports" CONSTRAINT "ports_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.prevalidators" CONSTRAINT "prevalidators_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "core.role_permissions" CONSTRAINT "role_permissions_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.seal" CONSTRAINT "seal_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.signatures" CONSTRAINT "signatures_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.subassembly_entries" CONSTRAINT "subassembly_entries_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.trailer" CONSTRAINT "trailer_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.transporter" CONSTRAINT "transporter_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.unit_conversions" CONSTRAINT "unit_conversions_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.units_of_measure" CONSTRAINT "units_of_measure_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.units_of_measure_general" CONSTRAINT "units_of_measure_general_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "core.user_company_permissions" CONSTRAINT "user_company_permissions_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "core.user_company_roles" CONSTRAINT "user_company_roles_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "core.user_tenants" CONSTRAINT "user_tenants_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - TABLE "a76.vehicle" CONSTRAINT "vehicle_company_id_fkey" FOREIGN KEY (company_id) REFERENCES a76.company(id) - From e338236a1c4d4b08b0497da7e5275e47cf21ff6b Mon Sep 17 00:00:00 2001 From: Kevin_Ramirez Date: Thu, 22 Jan 2026 09:49:59 -0600 Subject: [PATCH 3/4] Se arreglo el problema de company --- .../a76/general_catalogs/company/models.py | 2 +- .../a76/general_catalogs/company/routes.py | 161 ++--------- .../a76/general_catalogs/company/service.py | 270 ++++++++++++++---- .../company/submodels/certification.py | 2 +- backend/debug_mapper.py | 15 + backend/inspect_schema.py | 20 ++ backend/verify_logo_presence.py | 32 +++ 7 files changed, 311 insertions(+), 191 deletions(-) create mode 100644 backend/debug_mapper.py create mode 100644 backend/inspect_schema.py create mode 100644 backend/verify_logo_presence.py diff --git a/backend/api/v1/modules/a76/general_catalogs/company/models.py b/backend/api/v1/modules/a76/general_catalogs/company/models.py index fdcc0262..61ccc8a6 100644 --- a/backend/api/v1/modules/a76/general_catalogs/company/models.py +++ b/backend/api/v1/modules/a76/general_catalogs/company/models.py @@ -63,7 +63,7 @@ class Company(Base, TimestampMixin): logo: Mapped[Optional[str]] = mapped_column(String(255)) has_express_line: Mapped[Optional[str]] = mapped_column(String(2), default="N") order_format_type: Mapped[Optional[str]] = mapped_column(String(19)) - is_service_company: Mapped[Optional[str]] = mapped_column(String(2), default="N") + is_service_company: Mapped[Optional[bool]] = mapped_column(Boolean, default=False) client_name: Mapped[Optional[str]] = mapped_column(String(300)) subassembly_mode: Mapped[Optional[str]] = mapped_column(String(7)) diff --git a/backend/api/v1/modules/a76/general_catalogs/company/routes.py b/backend/api/v1/modules/a76/general_catalogs/company/routes.py index 6aadda85..e6d4bc52 100644 --- a/backend/api/v1/modules/a76/general_catalogs/company/routes.py +++ b/backend/api/v1/modules/a76/general_catalogs/company/routes.py @@ -50,7 +50,8 @@ async def create_company( ) service = CompanyService(db) - return service.create_company_manually(data, tenant_id=tenant_id) + new_company = service.create_company_manually(data, tenant_id=tenant_id) + return CompanyResponseDTO.model_validate(service.flatten_company_dto(new_company)) @router.get( @@ -94,7 +95,10 @@ async def list_companies( total_pages = (total + page_size - 1) // page_size return { - "items": [CompanyResponseDTO.model_validate(item) for item in items], + "items": [ + CompanyResponseDTO.model_validate(service.flatten_company_dto(item)) + for item in items + ], "total": total, "page": page, "page_size": page_size, @@ -122,135 +126,12 @@ async def get_my_companies( service = CompanyService(db) companies = service.get_companies_by_tenant(tenant_id) - return [CompanyResponseDTO.model_validate(company) for company in companies] - - -@router.get( - "/status/exists", - response_model=dict, - summary="Check if company exists for tenant", -) -async def check_company_exists( - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """Check if a company exists for the current tenant""" - tenant_id = current_user.get("tenant_id") - if not tenant_id: - raise HTTPException( - status_code=status.HTTP_400_BAD_REQUEST, - detail="Tenant ID not found in user data", - ) - - service = CompanyService(db) - exists = service.exists_company(tenant_id) - - return {"exists": exists} - - -@router.get( - "/info/basic/{company_id}", - response_model=dict, - summary="Get basic company info", -) -async def get_basic_info( - company_id: int, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """Get basic information about a company""" - tenant_id = current_user.get("tenant_id") - company_id_from_user = current_user.get("company_id") - - # Validate access - validate_access_to_resource( - db, tenant_id, company_id_from_user, Company, company_id, "id" - ) - - company = CompanyService.get_by_id(db, company_id, tenant_id, company_id_from_user) - if not company: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND, - detail="Company not found", - ) - - return { - "id": company.id, - "name": company.name, - "rfc": company.rfc, - "program": company.program, - } - - -@router.get( - "/info/responsible/{company_id}", - response_model=dict, - summary="Get responsible person info", -) -async def get_responsible_info( - company_id: int, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """Get responsible person information for a company""" - tenant_id = current_user.get("tenant_id") - company_id_from_user = current_user.get("company_id") - - # Validate access - validate_access_to_resource( - db, tenant_id, company_id_from_user, Company, company_id, "id" - ) - - company = CompanyService.get_by_id(db, company_id, tenant_id, company_id_from_user) - if not company: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND, - detail="Company not found", - ) - - return { - "responsible": company.responsible, - "responsible_name": company.responsible_name, - "responsible_last_name": company.responsible_last_name, - "responsible_mother_last_name": company.responsible_mother_last_name, - "responsible_rfc": company.responsible_rfc, - "position": company.position, - } - - -@router.get( - "/info/program/{company_id}", - response_model=dict, - summary="Get program information", -) -async def get_program_info( - company_id: int, - db: Session = Depends(get_core_db), - current_user: dict = Depends(get_current_user), -): - """Get program information for a company""" - tenant_id = current_user.get("tenant_id") - company_id_from_user = current_user.get("company_id") - - # Validate access - validate_access_to_resource( - db, tenant_id, company_id_from_user, Company, company_id, "id" - ) - - company = CompanyService.get_by_id(db, company_id, tenant_id, company_id_from_user) - if not company: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND, - detail="Company not found", - ) - - return { - "program": company.program, - "program_number": company.program_number, - "prosec": company.prosec, - "prosec_authorization": company.prosec_authorization, - } + return [ + CompanyResponseDTO.model_validate(service.flatten_company_dto(company)) + for company in companies + ] +# ... existing code ... @router.get( "/{company_id}", @@ -270,6 +151,7 @@ async def get_company( detail="Tenant ID not found in user data", ) + service = CompanyService(db) company = CompanyService.get_by_id(db, company_id, tenant_id, 0) if not company: raise HTTPException( @@ -277,7 +159,7 @@ async def get_company( detail="Company not found", ) - return CompanyResponseDTO.model_validate(company) + return CompanyResponseDTO.model_validate(service.flatten_company_dto(company)) @router.put( @@ -299,17 +181,18 @@ async def update_company( detail="Tenant ID not found in user data", ) - updated_company = CompanyService.update(db, company_id, tenant_id, 0, data) + service = CompanyService(db) + updated_company = service.update(db, company_id, tenant_id, 0, data) if not updated_company: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail="Company not found", ) - return CompanyResponseDTO.model_validate(updated_company) + return CompanyResponseDTO.model_validate(service.flatten_company_dto(updated_company)) + - return CompanyResponseDTO.model_validate(updated_company) @@ -347,6 +230,13 @@ async def get_company_logo_image( raise HTTPException(status_code=404, detail="Logo file not found on server") return FileResponse(file_path) + + +@router.delete( + "/{company_id}", + status_code=status.HTTP_204_NO_CONTENT, + summary="Delete a company", +) async def delete_company( company_id: int, db: Session = Depends(get_core_db), @@ -443,7 +333,8 @@ async def upload_company_logo( # Actualizar la empresa con la ruta del logo update_data = CompanyUpdateDTO(logo=file_path) - updated_company = CompanyService.update(db, company_id, tenant_id, 0, update_data) + service = CompanyService(db) + updated_company = service.update(db, company_id, tenant_id, 0, update_data) return { "message": "Logo uploaded successfully", diff --git a/backend/api/v1/modules/a76/general_catalogs/company/service.py b/backend/api/v1/modules/a76/general_catalogs/company/service.py index 5ed24feb..90460e79 100644 --- a/backend/api/v1/modules/a76/general_catalogs/company/service.py +++ b/backend/api/v1/modules/a76/general_catalogs/company/service.py @@ -97,8 +97,139 @@ class CompanyService: logger.error(f"Error creating company: {str(e)}") raise HTTPException(status_code=500, detail="Error creating company") - @staticmethod + + # ==================== HELPERS FOR FIELD MAPPING ==================== + def _extract_company_fields(self, data: Dict[str, Any]) -> Dict[str, Any]: + """Extrae campos que pertenecen a la tabla Company principal""" + company_fields = [ + "name", "rfc", "curp", "main_activity", "program", "program_number", + "prosec", "prosec_authorization", "sector1", "sector2", "sector3", + "manufacturer_id", "broker_company", "responsible", "responsible_name", + "responsible_last_name", "responsible_mother_last_name", "responsible_rfc", + "position", "logo", "has_express_line", "order_format_type", + "is_service_company", "client_name", "subassembly_mode", "previous_code", + "active_labels", "active_fractions", "activate_caat", "trans_interface", + "american_costs", "scaf_readonly", "parts_replacement", "activate_facmexame", + "part_reference", "international_firm", "ftp_key", "sifra_path", + "version_type", "sql_language", "balance_operation_mode", "inter_db_name" + ] + return {k: v for k, v in data.items() if k in company_fields} + + def _extract_certification_fields(self, data: Dict[str, Any]) -> Dict[str, Any]: + """Extrae campos que pertenecen a CompanyCertification""" + cert_fields = [ + "is_certified_company", "certified_company_registration", + "certified_company_start_date", "certified_company_end_date", + "annex31_certification_date", "annex31_certification_number", + "annex31_modality", "annex31_company_type", "annex31_renewal_date", + "annex31_final_certification_date", "is_oea_company", "ctpat_svi", + "trusted_exporter_number", "neec_company" + ] + return {k: v for k, v in data.items() if k in cert_fields} + + def _extract_prevalidator_fields(self, data: Dict[str, Any]) -> Dict[str, Any]: + """Extrae campos que pertenecen a CompanyPrevalidator""" + # Note: 'prevalidator_key' in DTO maps to 'key' in model + fields = {} + if "prevalidator_key" in data: + fields["key"] = data["prevalidator_key"] + + # Add other fields if present in DTO in the future + return fields + + def flatten_company_dto(self, company: Company) -> Dict[str, Any]: + """Flattens Company and its submodels into a single dict for DTO validation""" + # 1. Base Company fields + result = { + k: getattr(company, k) + for k in company.__mapper__.c.keys() + } + # Explicitly ensure logo is present (defensive programming) + if hasattr(company, 'logo'): + result['logo'] = company.logo + + # Convert has_express_line from String "S"/"N" to Boolean + if hasattr(company, 'has_express_line'): + val = getattr(company, 'has_express_line', "N") + result['has_express_line'] = (val == "S") + + # 2. Certification fields + if company.certification: + cert_fields = [ + "is_certified_company", "certified_company_registration", + "certified_company_start_date", "certified_company_end_date", + "annex31_certification_date", "annex31_certification_number", + "annex31_modality", "annex31_company_type", "annex31_renewal_date", + "annex31_final_certification_date", "is_oea_company", "ctpat_svi", + "trusted_exporter_number", "neec_company" + ] + for field in cert_fields: + val = getattr(company.certification, field, None) + if val is not None: + result[field] = val + + # 3. Prevalidator fields + if company.prevalidator: + if company.prevalidator.key: + result["prevalidator_key"] = company.prevalidator.key + + return result + + # ==================== CRUD METHODS ==================== + + def create_company_manually(self, data: CompanyCreateDTO, tenant_id: int) -> Company: + from .submodels.certification import CompanyCertification + from .submodels.prevalidator import CompanyPrevalidator + + try: + # 1. Preparar datos + obj_data = data.model_dump(exclude_unset=True) + + # Handle boolean flags for Company (Hybrid Approach) + # has_express_line is String(2), is_service_company is Boolean + if "has_express_line" in obj_data and isinstance(obj_data["has_express_line"], bool): + obj_data["has_express_line"] = "S" if obj_data["has_express_line"] else "N" + + # 2. Extract fields for each model + company_data = self._extract_company_fields(obj_data) + cert_data = self._extract_certification_fields(obj_data) + preval_data = self._extract_prevalidator_fields(obj_data) + + # 3. Create Company + db_company = Company(**company_data, tenant_id=tenant_id) + self.db.add(db_company) + self.db.flush() # Generate ID + + # 4. Create Certification if data exists + if cert_data: + cert = CompanyCertification(**cert_data, company_id=db_company.id) + self.db.add(cert) + + # 5. Create Prevalidator if data exists + if preval_data: + preval = CompanyPrevalidator(**preval_data, company_id=db_company.id) + self.db.add(preval) + + # 6. Commit + self.db.commit() + self.db.refresh(db_company) + + return db_company + + except IntegrityError as e: + self.db.rollback() + logger.error(f"IntegrityError creating company manually: {str(e)}") + raise HTTPException( + status_code=400, + detail="Error de integridad: Es posible que esta empresa ya exista.", + ) + except Exception as e: + self.db.rollback() + logger.error(f"Error creating company manually: {str(e)}") + raise HTTPException(status_code=500, detail=f"Error creando empresa: {str(e)}") + def update( + self, # Changed to instance method to use self helper methods db: Session, company_id: int, tenant_id: int, @@ -106,30 +237,57 @@ class CompanyService: company_data: CompanyUpdateDTO, ) -> Optional[Company]: """Update a company""" - company = CompanyService.get_by_id(db, company_id, tenant_id, company_id_unused) + from .submodels.certification import CompanyCertification + from .submodels.prevalidator import CompanyPrevalidator + + # Use self.db if db is passed as None, or use passed db (legacy support) + session = db if db else self.db + + company = self.get_by_id(session, company_id, tenant_id, company_id_unused) if not company: return None # Update only provided fields update_data = company_data.model_dump(exclude_unset=True) - boolean_fields_str = ["has_express_line", "is_service_company"] - for field, value in update_data.items(): - if field in boolean_fields_str: - # Convert boolean to "S"/"N" - if isinstance(value, bool): - value = "S" if value else "N" - + # 1. Update Company fields + company_fields = self._extract_company_fields(update_data) + + # Hybrid Approach: has_express_line is String, is_service_company is Boolean + if "has_express_line" in company_fields and isinstance(company_fields["has_express_line"], bool): + company_fields["has_express_line"] = "S" if company_fields["has_express_line"] else "N" + + for field, value in company_fields.items(): setattr(company, field, value) + # 2. Update Certification + cert_fields = self._extract_certification_fields(update_data) + if cert_fields: + if company.certification: + for field, value in cert_fields.items(): + setattr(company.certification, field, value) + else: + new_cert = CompanyCertification(**cert_fields, company_id=company.id) + session.add(new_cert) + + # 3. Update Prevalidator + preval_fields = self._extract_prevalidator_fields(update_data) + if preval_fields: + if company.prevalidator: + for field, value in preval_fields.items(): + setattr(company.prevalidator, field, value) + else: + new_preval = CompanyPrevalidator(**preval_fields, company_id=company.id) + session.add(new_preval) + try: - db.commit() - db.refresh(company) + session.commit() + session.refresh(company) return company except Exception as e: - db.rollback() + session.rollback() logger.error(f"Error updating company {company_id}: {str(e)}") - raise HTTPException(status_code=500, detail="Error updating company") + raise HTTPException(status_code=500, detail=f"Error al actualizar la empresa: {str(e)}") @staticmethod def delete( @@ -141,19 +299,56 @@ class CompanyService: return False try: + # Manual cascade delete for submodels to ensure order and avoid FK issues + # (Even though cascade="all, delete-orphan" is set, manual deletion is safer for strict DBs) + + # 1. Delete Certification + if company.certification: + db.delete(company.certification) + + # 2. Delete Prevalidator + if company.prevalidator: + db.delete(company.prevalidator) + + # 3. Delete Electronic Agent + if company.electronic_agent: + db.delete(company.electronic_agent) + + # 4. Delete VU + if company.ventanilla_unica: + db.delete(company.ventanilla_unica) + + # 5. Delete CFDI + if company.cfdi: + db.delete(company.cfdi) + + # 6. Delete Digital Certificates + for cert in company.digital_certificates: + db.delete(cert) + + # 7. Delete Addresses + for addr in company.addresses: + db.delete(addr) + + # Flush to execute submodel deletions first + db.flush() + db.delete(company) db.commit() return True except IntegrityError as e: db.rollback() logger.error(f"IntegrityError deleting company {company_id}: {str(e)}") - # Check if it's a foreign key constraint - if "foreign key constraint" in str(e).lower(): - raise HTTPException( - status_code=400, - detail="No se puede eliminar la empresa porque tiene registros relacionados (facturas, conceptos, etc.)" - ) - raise HTTPException(status_code=400, detail="Error al eliminar la empresa") + # Try to get detailed error from psycopg2 + detail = "No se puede eliminar la empresa porque tiene registros relacionados." + if hasattr(e, 'orig') and hasattr(e.orig, 'diag'): + if e.orig.diag.message_detail: + detail += f" Detalles: {e.orig.diag.message_detail}" + + raise HTTPException( + status_code=400, + detail=detail + ) except Exception as e: db.rollback() logger.error(f"Error deleting company {company_id}: {str(e)}") @@ -176,37 +371,4 @@ class CompanyService: .filter(Company.tenant_id == tenant_id) .first() is not None - ) - - def create_company_manually(self, data: CompanyCreateDTO, tenant_id: int) -> Company: - - try: - # 1. Preparar datos - obj_data = data.model_dump(exclude_unset=True) - - boolean_fields_str = ["has_express_line", "is_service_company"] - for field in boolean_fields_str: - if field in obj_data and isinstance(obj_data[field], bool): - obj_data[field] = "S" if obj_data[field] else "N" - - # 2. Crear objeto SQLAlchemy - db_obj = Company(**obj_data, tenant_id=tenant_id) - - # 3. Guardar - self.db.add(db_obj) - self.db.commit() - self.db.refresh(db_obj) - - return db_obj - - except IntegrityError as e: - self.db.rollback() - logger.error(f"IntegrityError creating company manually: {str(e)}") - raise HTTPException( - status_code=400, - detail="Error de integridad: Es posible que esta empresa ya exista.", - ) - except Exception as e: - self.db.rollback() - logger.error(f"Error creating company manually: {str(e)}") - raise HTTPException(status_code=500, detail=f"Error creando empresa: {str(e)}") \ No newline at end of file + ) \ No newline at end of file diff --git a/backend/api/v1/modules/a76/general_catalogs/company/submodels/certification.py b/backend/api/v1/modules/a76/general_catalogs/company/submodels/certification.py index 5624704b..eea80e08 100644 --- a/backend/api/v1/modules/a76/general_catalogs/company/submodels/certification.py +++ b/backend/api/v1/modules/a76/general_catalogs/company/submodels/certification.py @@ -2,7 +2,7 @@ Modelo de certificaciones de empresa """ from typing import Optional, TYPE_CHECKING -from sqlalchemy import Integer, String, SmallInteger, ForeignKey +from sqlalchemy import Integer, String, SmallInteger, ForeignKey, Boolean from sqlalchemy.orm import Mapped, mapped_column, relationship from core.database import Base from api.v1.common.base_models import TimestampMixin diff --git a/backend/debug_mapper.py b/backend/debug_mapper.py new file mode 100644 index 00000000..cc19459b --- /dev/null +++ b/backend/debug_mapper.py @@ -0,0 +1,15 @@ +from api.v1.modules.a76.general_catalogs.company.models import Company +from api.v1.modules.a76.general_catalogs.company.service import CompanyService +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker + +print("Checking Company Mapper keys...") +try: + keys = Company.__mapper__.c.keys() + print(f"Keys found: {keys}") + if 'logo' in keys: + print("SUCCESS: 'logo' is in keys") + else: + print("FAILURE: 'logo' is NOT in keys") +except Exception as e: + print(f"Error: {e}") diff --git a/backend/inspect_schema.py b/backend/inspect_schema.py new file mode 100644 index 00000000..63a44ca6 --- /dev/null +++ b/backend/inspect_schema.py @@ -0,0 +1,20 @@ +from sqlalchemy import create_engine, text + +# Connect to DB (adjust for localhost) +DB_URL = "postgresql://postgres:postgres@localhost:5432/anexo76_core" +engine = create_engine(DB_URL) + +sql = """ +SELECT column_name, data_type, character_maximum_length +FROM information_schema.columns +WHERE table_name = 'company' AND table_schema = 'a76' +AND column_name IN ('has_express_line', 'is_service_company'); +""" + +try: + with engine.connect() as conn: + result = conn.execute(text(sql)) + for row in result: + print(f"Column: {row[0]}, Type: {row[1]}, Length: {row[2]}") +except Exception as e: + print(f"Error: {e}") diff --git a/backend/verify_logo_presence.py b/backend/verify_logo_presence.py new file mode 100644 index 00000000..9ccabeb1 --- /dev/null +++ b/backend/verify_logo_presence.py @@ -0,0 +1,32 @@ +from api.v1.modules.a76.general_catalogs.company.models import Company +from api.v1.modules.a76.general_catalogs.company.service import CompanyService +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker, Session +import os + +# Connect to DB (adjust for localhost) +DB_URL = "postgresql://postgres:postgres@localhost:5432/anexo76_core" +engine = create_engine(DB_URL) +SessionLocal = sessionmaker(bind=engine) +session = SessionLocal() + +try: + print("Querying first company...") + company = session.query(Company).first() + if company: + print(f"Company ID: {company.id}") + print(f"Direct Logo Access: '{company.logo}'") + + service = CompanyService(session) + flattened = service.flatten_company_dto(company) + + print(f"Flattened Logo: '{flattened.get('logo')}'") + + has_logo = 'logo' in flattened + print(f"Is 'logo' key in dict?: {has_logo}") + else: + print("No companies found in DB.") +except Exception as e: + print(f"Error: {e}") +finally: + session.close() From 587dfed2f2b43055bc7e721e8ebac5fa4e69cd11 Mon Sep 17 00:00:00 2001 From: Kevin_Ramirez Date: Thu, 22 Jan 2026 11:44:54 -0600 Subject: [PATCH 4/4] Se arreglo el catalogo de UM --- .../units_of_measure/routes.py | 6 ++ .../a76/general_catalogs/units-of-measure.ts | 2 +- .../goods/modales/unit-measure-dialog.svelte | 80 ++++++------------- 3 files changed, 32 insertions(+), 56 deletions(-) diff --git a/backend/api/v1/modules/a76/general_catalogs/units_of_measure/routes.py b/backend/api/v1/modules/a76/general_catalogs/units_of_measure/routes.py index 9a9b3db7..93fb39de 100644 --- a/backend/api/v1/modules/a76/general_catalogs/units_of_measure/routes.py +++ b/backend/api/v1/modules/a76/general_catalogs/units_of_measure/routes.py @@ -17,6 +17,7 @@ ace_router = TenantCRUDRoutes( id_name="id", enable_list=True, enable_filters=True, + max_page_size=10000, ).router router.include_router(ace_router) @@ -32,6 +33,7 @@ oma_router = TenantCRUDRoutes( id_name="id", enable_list=True, enable_filters=True, + max_page_size=10000, ).router router.include_router(oma_router) @@ -47,6 +49,7 @@ american_router = TenantCRUDRoutes( id_name="id", enable_list=True, enable_filters=True, + max_page_size=10000, ).router router.include_router(american_router) @@ -62,6 +65,7 @@ customs_router = TenantCRUDRoutes( id_name="id", enable_list=True, enable_filters=True, + max_page_size=10000, ).router router.include_router(customs_router) @@ -77,6 +81,7 @@ general_router = TenantCRUDRoutes( id_name="id", enable_list=True, enable_filters=True, + max_page_size=10000, ).router router.include_router(general_router) @@ -93,5 +98,6 @@ main_router = TenantCRUDRoutes( id_name="id", enable_list=True, enable_filters=True, + max_page_size=10000, ).router router.include_router(main_router) 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 7b731651..566c900e 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 @@ -295,7 +295,7 @@ export interface UnitOfMeasureListResponse { export async function getUnitsOfMeasure( page: number = 1, - pageSize: number = 50, + pageSize: number = 1000, companyId: number, filters: Record = {} ): Promise> { 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 index 2520f8b6..43f7e76b 100644 --- a/frontend/src/lib/components/dashboard/goods/modales/unit-measure-dialog.svelte +++ b/frontend/src/lib/components/dashboard/goods/modales/unit-measure-dialog.svelte @@ -16,15 +16,27 @@ } = $props(); let items = $state([]); + let allItems = $state([]); // Store full dataset let loading = $state(false); let searchTerm = $state(""); - let page = $state(1); - let totalPages = $state(1); - let searchTimeout: NodeJS.Timeout; + + // Derived state for filtering + $effect(() => { + if (!searchTerm) { + items = allItems; + } else { + const lowerTerm = searchTerm.toLowerCase(); + items = allItems.filter(item => + item.code.toLowerCase().includes(lowerTerm) || + (item.description && item.description.toLowerCase().includes(lowerTerm)) || + (item.description_en && item.description_en.toLowerCase().includes(lowerTerm)) + ); + } + }); // Cargar datos al abrir $effect(() => { - if (open && companyStore.activeCompany) { + if (open && companyStore.activeCompany && allItems.length === 0) { loadData(); } }); @@ -34,17 +46,12 @@ loading = true; try { - const filters = searchTerm ? { code: searchTerm } : {}; - // Nota: Si tu backend soporta búsqueda por descripción, úsalo aquí. - // Por ahora asumo búsqueda por 'code' o 'description' según tu filtro backend. - - const response = await getUnitsOfMeasure(page, 10, companyStore.activeCompany.id, { - q: searchTerm // Asumiendo que tu backend tiene un filtro genérico 'q' o usa 'code'/'description' - }); + // Fetch everything once using the high limit + const response = await getUnitsOfMeasure(1, 1000, companyStore.activeCompany.id, {}); if (response.data) { - items = response.data.items; - totalPages = response.data.pages; + allItems = response.data.items; + items = allItems; // Initialize view } } catch (error) { console.error("Error cargando unidades:", error); @@ -56,32 +63,13 @@ function handleSearch(e: Event) { const value = (e.target as HTMLInputElement).value; searchTerm = value; - page = 1; - - clearTimeout(searchTimeout); - searchTimeout = setTimeout(() => { - loadData(); - }, 500); + // No network call needed, $effect handles filtering } function handleSelect(item: UnitOfMeasure) { onSelect(item); open = false; } - - function nextPage() { - if (page < totalPages) { - page++; - loadData(); - } - } - - function prevPage() { - if (page > 1) { - page--; - loadData(); - } - } @@ -104,7 +92,7 @@ />
-
+
{#if loading}
@@ -146,27 +134,9 @@
- -
- Página {page} de {totalPages} -
- - -
+ +
+ Mostrando {items.length} registros