try this way:
# Import the xmlrpc.client library
import xmlrpc.client
# Define your Odoo server information
url = 'http://your_odoo_server_url/xmlrpc/2/common'
db = 'your_database_name'
username = 'your_username'
password = 'your_password'
# Create a connection to the Odoo server
common = xmlrpc.client.ServerProxy(url)
# Authenticate and get the user ID (uid)
uid = common.authenticate(db, username, password, {})
# Check if the authentication was successful
if uid:
# Define your product information
sku = 'your_product_sku'
name = 'New Product Name'
pv = 100.0
pa = 80.0
description = 'New Product Description'
categ = category_id # Replace with the actual category ID
producttype = 'your_product_type'
sale_ok = True
purchase_ok = True
# Search for the product ID
models = xmlrpc.client.ServerProxy('http://your_odoo_server_url/xmlrpc/2/object')
product_id = models.execute_kw(db, uid, password, 'product.template', 'search', [[['default_code', "=", sku]]])
if product_id:
# Update the product information
result = models.execute_kw(db, uid, password, 'product.template', 'write', [[product_id], {
'name': name,
'list_price': pv,
'standard_price': pa,
'description': description,
'categ_id': categ,
'detailed_type': producttype,
'sale_ok': sale_ok,
'purchase_ok': purchase_ok,
}])
if result:
# Flush the cache to ensure the changes are immediately visible
models.execute_kw(db, uid, password, 'ir.model.data', 'xmlid_to_res_id', ['product.template'], {})
models.execute_kw(db, uid, password, 'product.template', 'invalidate_all', [[]])
print("Product information updated successfully.")
else:
print("Failed to update product information.")
else:
print("Product not found.")
else:
print("Authentication failed.")