Guard against missing marketplace tables when recording inventory operations
This commit is contained in:
@@ -122,16 +122,24 @@ def record_operation(conn, inventory_id, branch_id, operation_type, quantity,
|
|||||||
))
|
))
|
||||||
op_id = cur.fetchone()[0]
|
op_id = cur.fetchone()[0]
|
||||||
|
|
||||||
# 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.
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
INSERT INTO meli_sync_queue (inventory_id, action, status)
|
SELECT 1 FROM information_schema.tables
|
||||||
SELECT %s, 'stock_update', 'pending'
|
WHERE table_schema = 'public'
|
||||||
WHERE EXISTS (
|
AND table_name IN ('marketplace_listings', 'meli_sync_queue')
|
||||||
SELECT 1 FROM marketplace_listings
|
LIMIT 1
|
||||||
WHERE inventory_id = %s AND channel = 'mercadolibre' AND is_active = true
|
""")
|
||||||
)
|
if cur.fetchone():
|
||||||
ON CONFLICT DO NOTHING
|
cur.execute("""
|
||||||
""", (inventory_id, inventory_id))
|
INSERT INTO meli_sync_queue (inventory_id, action, status)
|
||||||
|
SELECT %s, 'stock_update', 'pending'
|
||||||
|
WHERE EXISTS (
|
||||||
|
SELECT 1 FROM marketplace_listings
|
||||||
|
WHERE inventory_id = %s AND channel = 'mercadolibre' AND is_active = true
|
||||||
|
)
|
||||||
|
ON CONFLICT DO NOTHING
|
||||||
|
""", (inventory_id, inventory_id))
|
||||||
|
|
||||||
cur.close()
|
cur.close()
|
||||||
return op_id
|
return op_id
|
||||||
|
|||||||
Reference in New Issue
Block a user