@@ -242,9 +242,10 @@ module.
242242Code Example
243243============
244244
245- The following examples showcase how to execute two of the :ref: `reference/orm/models/crud ` on a fake
246- database ``mycompany `` hosted on a fake website ``https://mycompany.example.com ``. Its comprehensive
247- documentation is be available at https://mycompany.example.com/doc
245+ The following examples showcase how to execute two of the :ref: `common ORM methods
246+ <reference/orm/models/crud>` on a dummy database ``mycompany `` hosted on the dummy website
247+ ``https://mycompany.example.com ``. Its :ref: `dynamic documentation
248+ <reference/external_api/dynamic_doc>` would be available at https://mycompany.example.com/doc.
248249
249250.. tabs ::
250251
@@ -360,7 +361,7 @@ The above example is equivalent to running::
360361 records = Model.search([("name", "ilike", "%deco%"), ("is_company", "=", True)])
361362 return json.dumps(records.ids)
362363
363- then in a new transaction::
364+ Then, in a new transaction::
364365
365366 records = self.env["res.partner"].with_context({"lang": "en_US"}).browse(ids)
366367 names = records.read(["name"])
@@ -409,17 +410,16 @@ The version function is replaced by the ``/web/version`` endpoint.
409410
410411 {"version_info": [19, 0, 0, "final", 0, ""], "version": "19.0"}
411412
412- The two ``login `` and ``authenticate `` functions return the user id corresponding to the user after
413- a successful login. The user id and password are necessary for subsequent RPC calls to the *object *
414- service. The JSON-2 API uses a different authentication scheme where neither the user id nor the
415- password are used. It is still possible to get the user own id doing a JSON-2 request for
416- ``res.users/context_get `` with no ids (the current user is extracted from the API key).
413+ The two ``login `` and ``authenticate `` functions return the user ID corresponding to the user after
414+ a successful login. The user ID and password are necessary for subsequent RPC calls to the *object *
415+ service. The JSON-2 API uses a different authentication scheme where neither the user ID nor the
416+ password are used. It is still possible to retrieve the user's own ID by sending a JSON-2 request to
417+ ``res.users/context_get `` with no ID (the current user is extracted from the API key).
417418
418419Database service
419420----------------
420421
421422.. seealso ::
422-
423423 :ref: `db_manager_security `
424424
425425The db service defines 13 fonctions:
@@ -441,30 +441,31 @@ The db service defines 13 fonctions:
441441Many of those function are accessible via the ``/web/database `` controllers. Those controllers
442442work hand-in-hand with the HTML form at ``/web/database/manager `` and are accessible via HTTP.
443443
444- The following controllers use verb ``POST `` and content-type ``application/x-www-form-urlencoded ``.
444+ The following controllers use the verb ``POST `` and content-type
445+ ``application/x-www-form-urlencoded ``.
445446
446- #. ``/web/database/create ``, takes inputs ``master_pwd ``, ``name ``, ``login ``, ``password ``,
447- ``demo ``, ``lang `` and ``phone ``.
448- #. ``/web/database/duplicate ``, takes inputs ``master_pwd ``, ``name ``, ``new_name `` and
447+ #. ``/web/database/create `` takes inputs ``master_pwd ``, ``name ``, ``login ``, ``password ``,
448+ ``demo ``, ``lang ``, and ``phone ``.
449+ #. ``/web/database/duplicate `` takes inputs ``master_pwd ``, ``name ``, ``new_name ``, and
449450 ``neutralize_database `` (not neutralized by default).
450- #. ``/web/database/drop ``, takes inputs ``master_pwd `` and ``name ``.
451- #. ``/web/database/backup ``, takes inputs ``master_pwd ``, ``name `` and ``backup_format `` (zip by
452- default), returns the backup in the http response.
453- #. ``/web/database/change_password ``, takes inputs ``master_pwd `` and ``master_pwd_new ``.
451+ #. ``/web/database/drop `` takes inputs ``master_pwd `` and ``name ``.
452+ #. ``/web/database/backup `` takes inputs ``master_pwd ``, ``name ``, and ``backup_format `` (zip by
453+ default), and returns the backup in the http response.
454+ #. ``/web/database/change_password `` takes inputs ``master_pwd `` and ``master_pwd_new ``.
454455
455- The following controller use verb ``POST `` and content-type ``multipart/form-data ``.
456+ The following controller uses the verb ``POST `` and content-type ``multipart/form-data ``.
456457
457- * ``/web/database/restore ``, takes inputs ``master_pwd ``, ``name ``, ``copy `` (not copied by
458+ * ``/web/database/restore `` takes inputs ``master_pwd ``, ``name ``, ``copy `` (not copied by
458459 default) and ``neutralize `` (not neutralized by default), it takes a file input ``backup_file ``.
459460
460- The following controller use verb ``POST `` and content-type ``application/json-rpc ``.
461+ The following controller uses the verb ``POST `` and content-type ``application/json-rpc ``.
461462
462- * ``/web/database/list ``, takes an empty json object as input, returns the database list under the
463- json response's ``result `` entry.
463+ * ``/web/database/list `` takes an empty JSON object as input, and returns the database list under
464+ the JSON response's ``result `` entry.
464465
465- The remaining function are: ``server_version ``, which exist under ``/web/version ``; ``list_lang ``
466- and ``list_countries `` which exist via JSON-2 on the ``res.lang `` and ``res.country `` models; and
467- ``migrate_databases `` which as no programmable API at the moment.
466+ The remaining function are: ``server_version ``, which exists under ``/web/version ``, ``list_lang ``,
467+ and ``list_countries ``, which exist via JSON-2 on the ``res.lang `` and ``res.country `` models, and
468+ ``migrate_databases ``, which as non- programmable API at the moment.
468469
469470Object service
470471--------------
@@ -476,72 +477,74 @@ The object service defines 2 fonctions:
476477
477478They both give for access to all public model methods, including the generic ORM ones.
478479
479- Both functions are stateless. It means that the database, user id and user password are to be
480+ Both functions are stateless. It means that the database, user ID and user password are to be
480481provided for each call. The model, method and arguments must be provided, too. The ``execute ``
481- function takes as many extra positional arguments as necessary. The ``execute_kw `` function takes a
482+ function takes as many extra positional arguments as necessary. The ``execute_kw `` function takes an
482483``args `` list of positional arguments and an optional ``kw `` dict of keyword arguments.
483484
484- The records ids are extracted from the first ``args ``. When the called method is decorated with
485- ``@api.model ``, no record ids are extracted and ``args `` is left as-is. It is only possible to give
486- a context with ``execute_kw `` as it is extracted from the keyword argument named ``context ``.
485+ The records IDs are extracted from the first ``args ``. When the called method is decorated with
486+ ``@api.model ``, no record ID is extracted, and ``args `` is left as-is. It is only possible to give a
487+ context with ``execute_kw ``, as it is extracted from the keyword argument named ``context ``.
487488
488- Example, to run the following:
489+ .. example ::
490+ To run the following:
489491
490- .. code :: python
492+ .. code :: python
491493
492- (env[' res.partner' ]
493- .with_user(2 ) # admin
494- .with_context(lang = ' en_US' )
495- .browse([1 , 2 , 3 ])
496- .read([' name' ], load = None )
497- )
494+ (env[' res.partner' ]
495+ .with_user(2 ) # admin
496+ .with_context(lang = ' en_US' )
497+ .browse([1 , 2 , 3 ])
498+ .read([' name' ], load = None )
499+ )
498500
499- Using XML-RPC (JSON-RPC would be similar):
501+ Using XML-RPC (JSON-RPC would be similar):
500502
501- .. code :: python
503+ .. code :: python
502504
503- from xmlrpc.client import ServerProxy
504- object = ServerProxy(... )
505- ids = [1 , 2 , 3 ]
506- fields = [' name' ]
507- load = None
505+ from xmlrpc.client import ServerProxy
506+ object = ServerProxy(... )
507+ ids = [1 , 2 , 3 ]
508+ fields = [' name' ]
509+ load = None
508510
509- object .execute(" database" , 2 , " admin" , " res.partner" , " read" , ids, fields, load)
510- object .execute(" database" , 2 , " admin" , " res.partner" , " search" , [
511- ids,
512- fields,
513- ], {
514- " context" : {" lang" : " en_US" },
515- " load" : load,
516- })
511+ object .execute(" database" , 2 , " admin" , " res.partner" , " read" , ids, fields, load)
512+ object .execute(" database" , 2 , " admin" , " res.partner" , " search" , [
513+ ids,
514+ fields,
515+ ], {
516+ " context" : {" lang" : " en_US" },
517+ " load" : load,
518+ })
517519
518520 The JSON-2 API replaces the object service with a few differences. The database must only be
519521provided (via the ``X-Odoo-Database `` HTTP header) on systems where there are multiple databases
520522available for a same domain. The login/password authentication scheme is replaced by an API key (via
521523the ``Authorization: bearer `` HTTP header). The ``model `` and ``method `` are placed in the URL. The
522524request body is a JSON object with all the methods arguments, plus ``ids `` and ``context ``. All
523- the arguments are named, there is no way in JSON-2 to call a function with positional arguments.
524-
525- Using JSON-2:
526-
527- .. code :: python
528-
529- import requests
530-
531- DATABSE = ...
532- DOMAIN = ...
533- API_KEY = " 6578616d706c65206a736f6e20617069206b6579"
534-
535- requests.post(
536- f " https:// { DOMAIN } /json/2/res.partner/read " ,
537- headers = {
538- # "X-Odoo-Database": DATABASE, # only when DOMAIN isn't enough
539- " Authorization" : f " bearer { API_KEY } " ,
540- },
541- json = {
542- " ids" : [1 , 2 , 3 ],
543- " context" : {" lang" : " en_US" },
544- " fields" : [" name" ],
545- " load" : None ,
546- },
547- ).json()
525+ the arguments are named; there is no way in JSON-2 to call a function with positional arguments.
526+
527+ .. example ::
528+ Using JSON-2:
529+
530+ .. code :: python
531+
532+ import requests
533+
534+ DATABSE = ...
535+ DOMAIN = ...
536+ API_KEY = " 6578616d706c65206a736f6e20617069206b6579"
537+
538+ requests.post(
539+ f " https:// { DOMAIN } /json/2/res.partner/read " ,
540+ headers = {
541+ # "X-Odoo-Database": DATABASE, # only when DOMAIN isn't enough
542+ " Authorization" : f " bearer { API_KEY } " ,
543+ },
544+ json = {
545+ " ids" : [1 , 2 , 3 ],
546+ " context" : {" lang" : " en_US" },
547+ " fields" : [" name" ],
548+ " load" : None ,
549+ },
550+ ).json()
0 commit comments