feat: MercadoLibre integration + inventory bulk publish + WhatsApp bridge fixes
- Add MercadoLibre OAuth, listings, orders, webhooks and category search - New marketplace_external_bp.py, meli_service.py, marketplace_external_service.py - New marketplace_external.html/js with ML management UI - Inventory: bulk publish to ML with category autocomplete, listing type and shipping selectors - Inventory: new .btn--meli styles, select/label CSS fixes - WhatsApp bridge: rate limiting, 440/515/408 error handling, stale watchdog - DB migration v3.4_meli_integration.sql for marketplace_listings, orders, sync_queue - Add Celery tasks for ML sync and webhook processing - Sidebar: MercadoLibre navigation link
This commit is contained in:
@@ -230,29 +230,42 @@ def get_engines(master_conn, model_id, year_id):
|
||||
return [{'id_mye': r[0], 'name_engine': r[1], 'trim_level': r[2] or ''} for r in rows]
|
||||
|
||||
|
||||
def get_categories(master_conn, mye_id):
|
||||
def get_categories(master_conn, mye_id, allowed_brands=None):
|
||||
"""Get part categories that have parts for this vehicle (mye_id).
|
||||
|
||||
Uses a subquery on vehicle_parts filtered by mye_id (indexed),
|
||||
then JOINs through parts -> part_groups -> part_categories.
|
||||
Uses COUNT with a safety LIMIT on the subquery.
|
||||
|
||||
If allowed_brands is provided, only counts parts that have at least one
|
||||
aftermarket equivalent from those manufacturers.
|
||||
"""
|
||||
cur = master_conn.cursor()
|
||||
cur.execute("""
|
||||
brand_filter = ""
|
||||
params = [mye_id]
|
||||
if allowed_brands:
|
||||
brand_filter = """AND EXISTS (
|
||||
SELECT 1 FROM aftermarket_parts ap2
|
||||
JOIN manufacturers m2 ON m2.id_manufacture = ap2.manufacturer_id
|
||||
WHERE ap2.oem_part_id = p.id_part AND UPPER(m2.name_manufacture) = ANY(%s)
|
||||
)"""
|
||||
params.append(allowed_brands)
|
||||
cur.execute(f"""
|
||||
SELECT pc.id_part_category,
|
||||
COALESCE(pc.name_es, pc.name_part_category) AS name,
|
||||
sub.cnt
|
||||
FROM (
|
||||
SELECT pg.category_id, COUNT(*) AS cnt
|
||||
SELECT pg.category_id, COUNT(DISTINCT p.id_part) AS cnt
|
||||
FROM vehicle_parts vp
|
||||
JOIN parts p ON p.id_part = vp.part_id
|
||||
JOIN part_groups pg ON pg.id_part_group = p.group_id
|
||||
WHERE vp.model_year_engine_id = %s
|
||||
{brand_filter}
|
||||
GROUP BY pg.category_id
|
||||
) sub
|
||||
JOIN part_categories pc ON pc.id_part_category = sub.category_id
|
||||
ORDER BY name
|
||||
""", (mye_id,))
|
||||
""", params)
|
||||
rows = cur.fetchall()
|
||||
cur.close()
|
||||
return [{'id_part_category': r[0], 'name': translate_category(r[1]), 'part_count': r[2]} for r in rows]
|
||||
|
||||
Reference in New Issue
Block a user