service Package

odoo_rpc_client.service.get_service_class(name)[source]

Return service class specified by it’s name

class odoo_rpc_client.service.ServiceBase(service, client, name)[source]

Bases: object

Base class for all Services

Parameters:
  • service – instance of original service class. must support folowing syntax service.service_method(args) to call remote methods
  • client – instance of Client, this service is binded to
clean_cache()[source]

To be implemented by subclasses, if needed

client

Related Client instance

name

Service name

class odoo_rpc_client.service.ServiceManager(client)[source]

Bases: extend_me.Extensible, odoo_rpc_client.utils.DirMixIn

Class to hold services related to specific client and to automaticaly clean service cached on update of service classes

Usage:

services = ServiceManager(client)
services.service_list          # get list of registered services
services.object                # returns service with name 'object'
services['common']             # returns service with name 'common'
services.get_service('report') # returns service named 'report'
clean_cache()[source]

Cleans manager’s service cache.

classmethod clean_caches()[source]

Cleans saved service instances, so on next access new service instances will be generated. This usualy happens when new service extension enabled (new class inherited from ServiceBase created)

clean_service_caches()[source]

Clean caches of all services handled by this mananger usualy this should be called on module update, when list of available objects or reports changed

client

Client instance this ServiceManager is bounded to

get_service(name)[source]

Returns instance of service with specified name

Parameters:name – name of service
Returns:specified service instance
service_list

Returns list of all registered services

db Module

class odoo_rpc_client.service.db.DBService(service, client, name)[source]

Bases: odoo_rpc_client.service.service.ServiceBase

Service class to simplify interaction with ‘db’ service

class Meta[source]

Bases: object

name = 'db'
create_db(password, dbname, demo=False, lang='en_US', admin_password='admin')[source]

Create new database on server, named dbname

Parameters:
  • password (str) – super admin password
  • dbname (str) – name of database to create
  • demo (bool) – load demo data or not. Default: False
  • lang (str) – language to be used for database. Default: ‘en_US’
  • admin_password (str) – password to be used for ‘Administrator’ database user. Default: ‘admin’
Returns:

Client instance logged to created database as admin user.

Return type:

instance of odoo_rpc_client.client.Client

db_exist(db)[source]

Check if database exists

Parameters:db (str|Client) – name of database or Client instance with client.dbname is not None
Returns:True if database exists else False
Return type:bool
drop_db(password, db)[source]

Drop specified database

Parameters:
  • password (str) – super admin password
  • db (str|Client) – name of database or Client instance with client.dbname is not None
Raise:

ValueError (unsupported value of db argument)

dump_db(password, db, **kwargs)[source]

Dump database

Note, that from defined arguments, may be passed other arguments (for example odoo version 9.0 requires format arg to be passed)

Note, this method may consume huge amout of memory. In production dump/restore have to be done by other means.

Parameters:
  • password (str) – super admin password
  • db (str|Client) – name of database or Client instance with client.dbname is not None
  • format (str) – (only odoo 9.0) (default: zip)
Raise:

ValueError (unsupported value of db argument)

Returns:

byte-string with base64 encoded data

Return type:

bytes

list_db()[source]

Display list of databses of thist connection

restore_db(password, dbname, data, **kwargs)[source]

Restore database

Note, this method may consume huge amout of memory. In production dump/restore have to be done by other means.

Parameters:
  • password (str) – super admin password
  • dbname (str) – name of database
  • data (bytes) – restore data (base64 encoded string)
  • copy (bool) – (only odoo 8.0+) if set to True, then new db-uid will be generated. (default: False)
Returns:

True

Return type:

bool

server_base_version()[source]

Returns server base version (‘9.0’, ‘8.0’, etc) parsed via pkg_resources.parse_version. No info about comunity / enterprise here

server_version()[source]

Returns server version.

(Already parsed with pkg_resources.parse_version)

server_version_str()[source]

Return server version (not wrapped by pkg.parse_version)

object Module

class odoo_rpc_client.service.object.ObjectService(*args, **kwargs)[source]

Bases: odoo_rpc_client.service.service.ServiceBase

Service class to simplify interaction with ‘object’ service Particulary, implements logic of choosing execute method (‘execute’ or ‘execute_kw’) The last one cannot work with keyword arguments(

class Meta[source]

Bases: object

name = 'object'
clean_cache()[source]

Cleans service cache, to fill them with fresh data on next call of related methods

execute(obj, method, *args, **kwargs)[source]

First arguments should be ‘object’ and ‘method’ and next will be passed to method of given object

execute_wkf(object_name, signal, object_id)[source]

Triggers workflow event on specified object

Parameters:
  • object_name (str) – name of object/model to trigger workflow on
  • signal (str) – name of signal to send to workflow
  • object_id (int) – ID of document (record) to send signal to
get_registered_objects()[source]

Returns list of registered objects in database

WARNING: This method is deprecated, and will not be working
for Odoo 14.0+

report Module

Report printing logic

Best way to generate report is:

data_records = client['res.partner'].search_records([], limit=10)
report = client.services.report['res.partner'].generate(data_records)
report.content

Or if it is desired to save it on disk:

data_records = client['res.partner'].search_records([], limit=10)
report = client.services.report['res.partner'].generate(data_records)
report.save('filename to save report with')

where report is instance of ReportResult and report.content returns already base64 decoded content of report, which could be directly written to file (or just use report.save(path) method)

class odoo_rpc_client.service.report.Report(service, report)[source]

Bases: extend_me.Extensible

Class that represents report.

useful to simplify report generation

Parameters:
  • service (ReportService) – instance of report service to bind report to
  • report (Record) – model of report action
generate(model_data, report_type='pdf', context=None)[source]

Generate report

Parameters:
  • model_data – RecordList or Record or list of obj_ids. represent document or documents to generate report for
  • report_type (str) – Type of report to generate. default is ‘pdf’.
  • context (dict) – Aditional info. Optional.
Raises:

ReportError

Returns:

ReportResult instance that contains generated report

Return type:

ReportResult

name

Name of report

report_action

Action of this report

service

Service this report is binded to

class odoo_rpc_client.service.report.ReportResult(report, result, path=None)[source]

Bases: extend_me.Extensible

Just a simple and extensible wrapper on report result

As variant of usage - wrap result returned by server methods report_get and render_report like:

ReportResult(report_get(report_id))
content

Report file content. Already base64-decoded

format

Report format

path

Path where file is located or will be located on save

result

Base64-encoded report content. To get already decoded report content, use .content property

Raises:ReportError – When .state property is False. This may appear in case when report is not ready yet, when using report and report_get methods
save(path=None)[source]

Save’s file by specified path or if no path specified save it in temp dir with automaticly generated name.

state

Result status. only if True, other fields are available

class odoo_rpc_client.service.report.ReportService(*args, **kwargs)[source]

Bases: odoo_rpc_client.service.service.ServiceBase

Service class to simplify interaction with ‘report’ service

class Meta[source]

Bases: object

name = 'report'
available_reports

Returns dictionary with all available reports

{<report name> : <Report instance>}

generate_report(report_name, report_data, report_type='pdf', context=None)[source]

Generate specified report for specifed report data. Report data could be RecordList or Record instance. Result is wrapped into ReportResult class

Parameters:
  • report_name (str) – string representing name of report service
  • report_data – RecordList or Record or (‘model_name’, obj_ids) represent document or documents to generate report for
  • report_type (str) – Type of report to generate. default is ‘pdf’.
  • context (dict) – Aditional info. Optional.
Raises:

ReportError

Returns:

ReportResult instance that contains generated report

Return type:

ReportResult

render_report(report_name, model, ids, report_type='pdf', context=None)[source]

Proxy to report service render_report method

NOTE: available after version 6.1.

Parameters:
  • report_name (str) – string representing name of report service
  • model (str) – name of model to generate report for
  • ids (list of int | int) – list of object ID to get report for (or just single id)
  • report_type (str) – Type of report to generate. default is ‘pdf’.
  • context (dict) – Aditional info. Optional.
Returns:

dictinary with keys: - ‘state’: boolean, True if report generated correctly - ‘result’: base64 encoded content of report file - ‘format’: string representing report format

Return type:

dict

report(report_name, model, ids, report_type='pdf', context=None)[source]

Proxy to report service report method

Parameters:
  • report_name (str) – string representing name of report service
  • model (str) – name of model to generate report for
  • ids (list of int | int) – list of object ID to get report for (or just single id)
  • report_type (str) – Type of report to generate. default is ‘pdf’.
  • context (dict) – Aditional info. Optional.
Returns:

ID of report to get by method report_get

Return type:

int

report_get(report_id)[source]

Proxy method to report service report_get method

Parameters:report_id (int) – int that represents ID of report to get (value returned by report method)
Returns:dictinary with keys:
  • ’state’: boolean, True if report generated correctly
  • ’result’: base64 encoded content of report file
  • ’format’: string representing format, report generated in
Return type:dict

service Module

odoo_rpc_client.service.service.get_service_class(name)[source]

Return service class specified by it’s name

class odoo_rpc_client.service.service.ServiceBase(service, client, name)[source]

Bases: object

Base class for all Services

Parameters:
  • service – instance of original service class. must support folowing syntax service.service_method(args) to call remote methods
  • client – instance of Client, this service is binded to
clean_cache()[source]

To be implemented by subclasses, if needed

client

Related Client instance

name

Service name

class odoo_rpc_client.service.service.ServiceManager(client)[source]

Bases: extend_me.Extensible, odoo_rpc_client.utils.DirMixIn

Class to hold services related to specific client and to automaticaly clean service cached on update of service classes

Usage:

services = ServiceManager(client)
services.service_list          # get list of registered services
services.object                # returns service with name 'object'
services['common']             # returns service with name 'common'
services.get_service('report') # returns service named 'report'
clean_cache()[source]

Cleans manager’s service cache.

classmethod clean_caches()[source]

Cleans saved service instances, so on next access new service instances will be generated. This usualy happens when new service extension enabled (new class inherited from ServiceBase created)

clean_service_caches()[source]

Clean caches of all services handled by this mananger usualy this should be called on module update, when list of available objects or reports changed

client

Client instance this ServiceManager is bounded to

get_service(name)[source]

Returns instance of service with specified name

Parameters:name – name of service
Returns:specified service instance
service_list

Returns list of all registered services