import odoo
import json

def verify_lab_order_products(cr):
    cr.execute("""
        SELECT
            so.name AS order_name,
            sol.id AS line_id,
            pt.name->>'en_US' AS product_name,
            pt.is_analysis
        FROM
            sale_order so
        JOIN
            sale_order_line sol ON so.id = sol.order_id
        JOIN
            product_product pp ON sol.product_id = pp.id
        JOIN
            product_template pt ON pp.product_tmpl_id = pt.id
        WHERE
            so.is_lab_request = TRUE;
    """)
    return cr.fetchall()

if __name__ == '__main__':
    db_name = 'lims_demo'
    registry = odoo.registry(db_name)
    with registry.cursor() as cr:
        results = verify_lab_order_products(cr)
        
        print(json.dumps(results, indent=4))
