Introducing the ERPpeek client

ERPpeek is a versatile tool that can be used both as an interactive Command-line Interface (CLI) and as a Python library, with a more convenient API than the one provided by xmlrpclib. It is available from the PyPi index and can be installed with the following:

$ pip install -U erppeek

On a Unix system, if you are installing it system wide, you might need to prepend sudo to the command.

The ERPpeek API

The erppeek library provides a programming interface, wrapping around xmlrpclib, which is similar to the programming interface we have for the server-side code.

Our point here is to provide a glimpse of what ERPpeek has to offer, and not to provide a full explanation of all its features.

We can start by reproducing our first steps with xmlrpclib using erppeek as follows:

>>> import erppeek
>>> api = erppeek.Client('http://localhost:8069', 'v8dev', 'admin', 'admin')
>>> api.common.version()
>>> api.count('res.partner', [])
>>> api.search('res.partner', [('country_id', '=', 'be'), ('parent_id', '!=', False)])
>>> api.read('res.partner', [43], ['id', 'name', 'parent_id'])

As you can see, the API calls use fewer arguments and are similar to the server-side counterparts.

But ERPpeek doesn't stop here, and also provides a representation for Models. We have the following two alternative ways to get an instance for a model, either using the model () method or accessing an attribute in camel case:

>>> m = api.model('res.partner')
>>> m = api.ResPartner

Now we can perform actions on that model as follows:

>>> m.count([('name', 'like', 'Packt%')])
1
>>> m.search([('name', 'like', 'Packt%')])
[76]

It also provides client-side object representation for records as follows:

>>> recs = m.browse([('name', 'like', 'Packt%')])
>>> recs
<RecordList 'res.partner,[76]'>
>>> recs.name
['Packt']

As you can see, ERPpeek goes a long way from plain xmlrpclib, and makes it possible to write code that can be reused server side with little or no modification.

The ERPpeek CLI

Not only can erppeek be used as a Python library, it is also a CLI that can be used to perform administrative actions on the server. Where the odoo shell command provided a local interactive session on the host server, erppeek provides a remote interactive session on a client across the network.

Opening a command line, we can have a peek at the options available, as shown in the following:

$ erppeek --help

Let's see a sample session as follows:

$ erppeek --server='http://localhost:8069' -d v8dev -u admin
Usage (some commands):
    models(name)                    # List models matching pattern
    model(name)                     # Return a Model instance
(...)
Password for 'admin':
Logged in as 'admin'
v8dev >>> model('res.users').count()
3
v8dev >>> rec = model('res.partner').browse(43)
v8dev >>> rec.name
'Michel Fletcher'

As you can see, a connection was made to the server, and the execution context provided a reference to the model() method to get model instances and perform actions on them.

The erppeek.Client instance used for the connection is also available through the client variable. Notably, it provides an alternative to the web client to manage the following modules installed:

  • client.modules(): This can search and list modules available or installed
  • client.install(): This performs module installation
  • client.upgrade(): This orders modules to be upgraded
  • client.uninstall(): This uninstalls modules

So, ERPpeek can also provide good service as a remote administration tool for Odoo servers.

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

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