How to do it...

The following code is not meant to run within Odoo, but as simple scripts:

  1. First, we query the list of installed modules via XMLRPC:
#!/usr/bin/env python3
from xmlrpc.client import ServerProxy

db = 'odoo11'
user = 'admin'
password = 'admin'
uid = ServerProxy('http://localhost:8069/xmlrpc/2/common')
    .authenticate(db, user, password, {})
odoo = ServerProxy('http://localhost:8069/xmlrpc/2/object')
installed_modules = odoo.execute_kw(
  db, uid, password, 'ir.module.module', 'search_read',
  [[('state', '=', 'installed')], ['name']],
{'context': {'lang': 'fr_FR'}},
) for module in installed_modules: print(module['name'])
  1. Then, we do the same with JSONRPC:
import json
from urllib.request import Request, urlopen

db = 'odoo11'
user = 'admin'
password = 'admin'

request = Request(
  'http://localhost:8069/web/session/authenticate',
  json.dumps({
    'jsonrpc': '2.0',
      'params': {
        'db': db,
        'login': user,
        'password': password,
      },
  }).encode('utf8'),
  {'Content-type': 'application/json'})
result = urlopen(request).read()
result = json.loads(result.decode('utf-8'))
session_id = result['result']['session_id']
request = Request(
    'http://localhost:8069/web/dataset/call_kw',
    json.dumps({
      'jsonrpc': '2.0',
      'params': {
        'model': 'ir.module.module',
        'method': 'search_read',
        'args': [
          [('state', '=', 'installed')],
          ['name'],
        ],
        'kwargs': {'context': {'lang': 'fr_FR'}},
      },
    }).encode('utf8'),
    {
        'X-Openerp-Session-Id': session_id,
        'Content-type': 'application/json',
    })
result = urlopen(request).read()
result = json.loads(result.decode('utf-8'))
for module in result['result']:
  print(module['name'])

Both code snippets will print a list of installed modules, and because they pass a context that sets the language to French, the list will be in French if there are translations available.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.114.221