feat: dropdown filtra marcas y modelos por ano seleccionado

Al seleccionar ano, solo muestra marcas/modelos disponibles para ese ano.
Toyota 2020: 92 modelos vs 625 sin filtro.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-02 08:06:34 +00:00
parent 67e214db15
commit 10e318bfd7
4 changed files with 69 additions and 29 deletions

View File

@@ -27,32 +27,53 @@ NORTH_AMERICA_BRANDS = (
)
def get_brands(master_conn):
"""Get vehicle brands available in Mexico/USA/Canada that have MYE entries."""
def get_brands(master_conn, year_id=None):
"""Get vehicle brands available in Mexico/USA/Canada that have MYE entries.
If year_id is provided, only brands that have models for that year."""
cur = master_conn.cursor()
cur.execute("""
SELECT DISTINCT b.id_brand, b.name_brand
FROM brands b
JOIN models m ON m.brand_id = b.id_brand
JOIN model_year_engine mye ON mye.model_id = m.id_model
WHERE b.name_brand = ANY(%s)
ORDER BY b.name_brand
""", (list(NORTH_AMERICA_BRANDS),))
if year_id:
cur.execute("""
SELECT DISTINCT b.id_brand, b.name_brand
FROM brands b
JOIN models m ON m.brand_id = b.id_brand
JOIN model_year_engine mye ON mye.model_id = m.id_model
WHERE b.name_brand = ANY(%s) AND mye.year_id = %s
ORDER BY b.name_brand
""", (list(NORTH_AMERICA_BRANDS), year_id))
else:
cur.execute("""
SELECT DISTINCT b.id_brand, b.name_brand
FROM brands b
JOIN models m ON m.brand_id = b.id_brand
JOIN model_year_engine mye ON mye.model_id = m.id_model
WHERE b.name_brand = ANY(%s)
ORDER BY b.name_brand
""", (list(NORTH_AMERICA_BRANDS),))
rows = cur.fetchall()
cur.close()
return [{'id_brand': r[0], 'name_brand': r[1]} for r in rows]
def get_models(master_conn, brand_id):
"""Get models for a brand that have MYE entries (fast, no vehicle_parts scan)."""
def get_models(master_conn, brand_id, year_id=None):
"""Get models for a brand that have MYE entries.
If year_id is provided, only models available for that year."""
cur = master_conn.cursor()
cur.execute("""
SELECT DISTINCT m.id_model, m.name_model
FROM models m
JOIN model_year_engine mye ON mye.model_id = m.id_model
WHERE m.brand_id = %s
ORDER BY m.name_model
""", (brand_id,))
if year_id:
cur.execute("""
SELECT DISTINCT m.id_model, m.name_model
FROM models m
JOIN model_year_engine mye ON mye.model_id = m.id_model
WHERE m.brand_id = %s AND mye.year_id = %s
ORDER BY m.name_model
""", (brand_id, year_id))
else:
cur.execute("""
SELECT DISTINCT m.id_model, m.name_model
FROM models m
JOIN model_year_engine mye ON mye.model_id = m.id_model
WHERE m.brand_id = %s
ORDER BY m.name_model
""", (brand_id,))
rows = cur.fetchall()
cur.close()
return [{'id_model': r[0], 'name_model': r[1]} for r in rows]