Skip to content

Normalize catalog, load from legacy .dm and add subtipo/nombre_cuenta support in classifier and GUI#3

Open
ElPoot wants to merge 1 commit intomainfrom
codex/understand-repo-for-app-3-development
Open

Normalize catalog, load from legacy .dm and add subtipo/nombre_cuenta support in classifier and GUI#3
ElPoot wants to merge 1 commit intomainfrom
codex/understand-repo-for-app-3-development

Conversation

@ElPoot
Copy link
Owner

@ElPoot ElPoot commented Feb 27, 2026

Motivation

  • Provide robust catalog normalization and recovery, ingesting legacy .dm account definitions and ensuring a consistent minimal catalog shape via _normalize_catalog.
  • Support richer classification metadata (separate subtipo and nombre_cuenta) to map invoices to a deeper folder hierarchy and store precise account information in the DB.
  • Show destination preview and let the user select Tipo/Cuenta in the UI so classifications produce consistent paths on the network drive.

Description

  • Added CATALOG_DM_PATH and _normalize_name helper and implemented CatalogManager methods: load, load_from_dm, save, categorias, subtipos, cuentas, add_cuenta, and _normalize_catalog; defaults and minimum entries are enforced and malformed catalog files are backed up and replaced.
  • Implemented DM parser in load_from_dm that reads legacy catalogo_de_cuentas.dm and populates COMPRAS, GASTOS and OGND branches based on parent codes.
  • Added build_dest_folder, _month_bucket, and imports to classifier.py to compute destination paths on the network drive using network_drive() and sanitize_folder_name and to bucket by month.
  • Extended ClassificationDB schema to ensure subtipo and nombre_cuenta columns exist, updated get_record, get_records_map, and upsert to populate and return subtipo/nombre_cuenta, and adjusted upsert to backfill subcategoria for compatibility.
  • Updated classify_record signature and logic to accept subtipo and nombre_cuenta, compute year default, use build_dest_folder for destination, and persist the extended metadata to DB; preserved atomic copy/sha256 verification and safe removal logic.
  • Updated GUI (main_window.py) to hold a CatalogManager, pass it through the loader, expose Tipo (subtipo), Cuenta and Destino preview fields, update category/subtype/account selection logic and validation rules per category, and include subtipo/nombre_cuenta in exports and previous-classification display.

Testing

  • Ran the project's test suite with pytest against the modified codebase and the existing tests completed successfully.
  • Performed import/smoke tests by launching the GUI and exercising catalog loading, subtype/account selection, destination preview, and a basic classification flow (no regressions observed in automated checks).

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f9f1f8d9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +937 to +939
subtipos = self.catalog_manager.subtipos(cat)
self._subtipo_cb.configure(values=subtipos, state="readonly" if subtipos else "disabled")
self._subtipo_var.set(subtipos[0] if subtipos else "")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Populate OGND type selector with real OGND codes

When cat == "OGND", this code still fills the selector from subtipos("OGND"), but the catalog shape built in CatalogManager stores OGND values under OGND -> TIPOS -> {OGND,DNR,ORS,CNR}; that means the UI exposes only TIPOS and _classify_selected then saves/routes every OGND invoice as .../OGND/TIPOS. In practice users cannot choose DNR/ORS/CNR, so OGND classifications are written to the wrong destination and metadata.

Useful? React with 👍 / 👎.

tipo_ognd = sanitize_folder_name(stp or "OGND")
return base / "OGND" / tipo_ognd

raise ValueError(f"Categoría no soportada: {categoria}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Support legacy categories before rejecting destination build

Older client catalogs include INGRESOS (the previous default), and _normalize_catalog preserves unknown categories, so the category list can still offer INGRESOS after upgrade. build_dest_folder now rejects anything outside COMPRAS/GASTOS/OGND, so selecting that legacy category causes classification to fail with ValueError instead of moving the PDF, which is a migration regression for existing metadata.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant