Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
5451 Widoki

how to load a translation with jsonrpc(python lib odoorpc) ?

thanks !

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

Try like following

from odoorpc import ODOO

# Connect to the Odoo server
odoo = ODOO('localhost', port=8069)
db_name = 'your_database'
user = 'your_username'
password = 'your_password'
odoo.login(db_name, user, password)

# Get the JSON-RPC client from the ODOO instance
jsonrpc = odoo.jsonrpc

# Load the translation module
module_name = 'base' # Replace with the module name you want to load translations for
jsonrpc.load_module(module_name)

# Logout from 

In the above code, you first establish a connection to the Odoo server using the ODOO class from the odoorpc library. Then, you log in to the Odoo server using the login method with your database name, username, and password.

Next, you retrieve the JSON-RPC client object from the odoo instance. The jsonrpc object allows you to perform JSON-RPC requests to the Odoo server.

To load the translation module, you use the load_module method of the jsonrpc client and provide the name of the module you want to load translations for. In the example, 'base' is used as an example module name. Replace it with the actual module name you want to load translations for.

Finally, you log out from the Odoo server using the logout method to close the session.

Remember to replace 'localhost', 8069, 'your_database', 'your_username', and 'your_password' with the appropriate values for your Odoo server configuration

Regards

Awatar
Odrzuć
Najlepsza odpowiedź

To load a translation using JSON-RPC in the Python library odoorpc, you can use the execute_kw method to call the load_module_translation method of the ir.module.module model in Odoo.

from odoorpc import ODOO

# Establish a connection to the Odoo server
odoo = ODOO(host='your-odoo-host', port=8069)
db_name = 'your-database-name'
user = 'your-username'
password = 'your-password'
odoo.login(database=db_name, login=user, password=password)

# Specify the module name for which you want to load the translation
module_name = 'your-module-name'

# Call the load_module_translation method to load the translation
module_obj = odoo.env['ir.module.module']
result = module_obj.execute_kw('load_module_translation', [module_name])

# Check the result of the translation loading operation
if result:
print('Translation loaded successfully.')
else:
print('Translation loading failed.')

# Logout from the Odoo server
odoo.logout()

Note: Ensure that you have the odoorpc library installed in your Python environment before running the code. You can install it using pip: pip install odoorpc.
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
lis 21
6073
2
mar 15
6085
1
kwi 25
942
0
lut 25
1176
0
sty 21
3596