Fix: only sync ML stock when both marketplace_listings and meli_sync_queue exist
This commit is contained in:
@@ -125,12 +125,11 @@ def record_operation(conn, inventory_id, branch_id, operation_type, quantity,
|
|||||||
# Queue ML stock sync if this product has an active ML listing.
|
# Queue ML stock sync if this product has an active ML listing.
|
||||||
# Skip gracefully if the marketplace tables do not exist in this tenant.
|
# Skip gracefully if the marketplace tables do not exist in this tenant.
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT 1 FROM information_schema.tables
|
SELECT COUNT(*) FROM information_schema.tables
|
||||||
WHERE table_schema = 'public'
|
WHERE table_schema = 'public'
|
||||||
AND table_name IN ('marketplace_listings', 'meli_sync_queue')
|
AND table_name IN ('marketplace_listings', 'meli_sync_queue')
|
||||||
LIMIT 1
|
|
||||||
""")
|
""")
|
||||||
if cur.fetchone():
|
if cur.fetchone()[0] >= 2:
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
INSERT INTO meli_sync_queue (inventory_id, action, status)
|
INSERT INTO meli_sync_queue (inventory_id, action, status)
|
||||||
SELECT %s, 'stock_update', 'pending'
|
SELECT %s, 'stock_update', 'pending'
|
||||||
|
|||||||
Reference in New Issue
Block a user