import psycopg2
import json

conn = psycopg2.connect(dbname="hazard_new", user="odoo", password="odoo", host="localhost", port="5432")
cur = conn.cursor()

ref = 'HRS-GLV-CABRET-U-WHT-L'
cur.execute("""
    SELECT pt.id, pt.name, pp.id, pp.default_code
    FROM product_product pp
    JOIN product_template pt ON pp.product_tmpl_id = pt.id
    WHERE pp.default_code = %s
""", (ref,))

for row in cur.fetchall():
    print("Template ID:", row[0])
    print("Template Name (JSONb):", row[1])
    print("Product ID:", row[2])

cur.close()
conn.close()
