#!/usr/bin/env python3
import xmlrpc.client

ODOO_URL = 'http://localhost:16001'
ODOO_DB = 'hazard_new'
ODOO_USER = 'admin'
ODOO_PASS = 'admin'

def main():
    common = xmlrpc.client.ServerProxy(f'{ODOO_URL}/xmlrpc/2/common')
    uid = common.authenticate(ODOO_DB, ODOO_USER, ODOO_PASS, {})
    models = xmlrpc.client.ServerProxy(f'{ODOO_URL}/xmlrpc/2/object')

    print("Buscando productos vinculados a Shopify con stock 0 en Odoo...")
    products = models.execute_kw(ODOO_DB, uid, ODOO_PASS,
        'product.product', 'search_read',
        [[('shopify_inventory_item_id', '!=', False), ('qty_available', '<=', 0)]],
        {'fields': ['display_name', 'default_code', 'qty_available']}
    )

    print(f"\nSe encontraron {len(products)} variantes vinculadas a Shopify que en Odoo tienen 0 (o menos) de stock:\n")
    for p in products:
        print(f"[{p['default_code']}] {p['display_name']} -> Stock Odoo: {p['qty_available']}")

if __name__ == '__main__':
    main()
