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

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("Consultando TODOS los productos (activos e inactivos) en Odoo...")
    products = models.execute_kw(ODOO_DB, uid, ODOO_PASS,
        'product.product', 'search_read',
        [['|', ('active', '=', True), ('active', '=', False), ('barcode', '!=', False)]],
        {'fields': ['display_name', 'default_code', 'barcode', 'active']}
    )

    wrong_barcodes = []
    for p in products:
        if not p['barcode'].startswith('200001'):
            wrong_barcodes.append(p)
    
    print(f"\nSe encontraron {len(wrong_barcodes)} productos con barcode que NO empieza con 200001:\n")
    for p in wrong_barcodes:
        print(f"[{'ACTIVO' if p['active'] else 'INACTIVO'}] Producto: {p['display_name']} | SKU: {p['default_code']} | Barcode: {p['barcode']}")

if __name__ == '__main__':
    main()
