how to configure api correctly on odoo cloud?
i did it on prem and it work fine but on cloud it does not
here is my python code :
import xmlrpc.client
import pandas as pd
from tabulate import tabulate
# Odoo API information
url = 'myurl'
db = 'mydatabsename'
username = 'myuser'
password = 'my api key'
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
common.version()
print(common.version())
uid = common.authenticate(db, username, password, {})
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
print(models)
try:
# Change the model to 'sale.order.line' and adjust the query as needed
records = models.execute_kw(
db, uid, password, 'sale.order.line', 'search_read',
[[('state', '=', 'sale')]],
{'fields': ['id','order_id','product_template_id', 'product_id','display_name', 'product_uom_qty', 'price_unit', 'product_uom', 'write_date', 'name' ,'qty_delivered'],
'limit': 100, 'order': 'write_date desc'}
)
# Extract relevant fields and flatten the data
data = []
for record in records:
product_info = models.execute_kw(
db, uid, password, 'product.product', 'read',
[[record['product_id'][0]]],
{'fields': ['name']}
)[0]
data.append({
'Date': record['write_date'],
'Sales Order Number': record['order_id'],
'Product': record['name'],
#'Product': product_info.get('name', ''),
#'Product Full Name': record['display_name'],
'Quantity': record['product_uom_qty'],
'Price Per Unit': record['price_unit'],
'Qty Delivered': record['qty_delivered']
#'Unit': record['product_uom']
})
df = pd.DataFrame(data)
# Print the table
print(tabulate(df, headers='keys', tablefmt='fancy_grid', showindex=False))
# Export to Excel file
excel_file_path = 'sales_order_lines_with_details.xlsx'
df.to_excel(excel_file_path, index=False)
print(f"Sales order lines with details exported to {excel_file_path}")
except xmlrpc.client.Fault as e:
print(f"Error executing Odoo API method: {e}")
finally:
print("Script execution completed.")