fix(catalog): unifica modelos duplicados por variante de carroceria/generacion

- catalog_service.get_models ahora agrupa variantes (p. ej. AVEO Saloon,
  AVEO Hatchback) bajo un unico display_name y devuelve variant_ids.
- Se elige el id_model mas bajo como canonico para presentacion.
- /catalog/years y /catalog/engines aceptan model_id como lista separada
  por comas para consultar todos los MYEs de las variantes agrupadas.
- catalog.js usa variant_ids al cargar años/motores y en el selector
  desplegable (incluyendo carga desde VIN).
This commit is contained in:
2026-06-15 18:24:58 +00:00
parent 85ecf52561
commit f5711ae22f
3 changed files with 87 additions and 37 deletions

View File

@@ -150,12 +150,18 @@ def models():
@catalog_bp.route('/years', methods=['GET'])
@require_auth('catalog.view')
def years():
model_id = request.args.get('model_id', type=int)
if not model_id:
model_id_param = request.args.get('model_id', '')
if not model_id_param:
return jsonify({'error': 'model_id required'}), 400
try:
model_ids = [int(x) for x in model_id_param.split(',') if x]
except ValueError:
return jsonify({'error': 'model_id must be a comma-separated list of integers'}), 400
if not model_ids:
return jsonify({'error': 'model_id required'}), 400
def _do(master, tenant, branch_id):
mye_ids = catalog_service._get_mye_ids_with_parts(tenant, tenant_id=g.tenant_id, master_conn=master) if tenant else None
data = catalog_service.get_years(master, model_id, mye_ids=mye_ids)
data = catalog_service.get_years(master, model_ids, mye_ids=mye_ids)
return jsonify({'data': data})
return _with_conns(_do)
@@ -176,13 +182,19 @@ def years_all():
@catalog_bp.route('/engines', methods=['GET'])
@require_auth('catalog.view')
def engines():
model_id = request.args.get('model_id', type=int)
model_id_param = request.args.get('model_id', '')
year_id = request.args.get('year_id', type=int)
if not model_id or not year_id:
if not model_id_param or not year_id:
return jsonify({'error': 'model_id and year_id required'}), 400
try:
model_ids = [int(x) for x in model_id_param.split(',') if x]
except ValueError:
return jsonify({'error': 'model_id must be a comma-separated list of integers'}), 400
if not model_ids:
return jsonify({'error': 'model_id required'}), 400
def _do(master, tenant, branch_id):
mye_ids = catalog_service._get_mye_ids_with_parts(tenant, tenant_id=g.tenant_id, master_conn=master) if tenant else None
data = catalog_service.get_engines(master, model_id, year_id, mye_ids=mye_ids)
data = catalog_service.get_engines(master, model_ids, year_id, mye_ids=mye_ids)
return jsonify({'data': data})
return _with_conns(_do)