import xmlrpc.client

url = 'http://localhost:16001'
db = 'hazard_new'
username = 'admin'
password = '123'

# Try 123, then admin, then check
try:
    common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
    uid = common.authenticate(db, username, 'admin', {})
    if not uid:
        uid = common.authenticate(db, 'admin', '123', {})
    
    models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
    
    # Get sale order S00693
    sale_orders = models.execute_kw(db, uid, 'admin', 'sale.order', 'search_read', [[['name', '=', 'S00693']]], {'fields': ['id', 'name', 'shopify_fulfillment_status', 'state', 'message_ids']})
    print("Sale Order:", sale_orders)
    
    # Get pickings for S00693
    if sale_orders:
        pickings = models.execute_kw(db, uid, 'admin', 'stock.picking', 'search_read', [[['origin', '=', 'S00693']]], {'fields': ['id', 'name', 'state', 'message_ids']})
        print("Pickings:", pickings)
        
        # get messages
        msg_ids = pickings[0]['message_ids']
        if msg_ids:
            msgs = models.execute_kw(db, uid, 'admin', 'mail.message', 'read', [msg_ids], {'fields': ['body']})
            for m in msgs:
                print("Picking MSG:", m['body'])

except Exception as e:
    print("Error:", e)
