Beautiful, robust CLI for Odoo
Project description
click-odoo helps you create and run beautiful and robust command line scripts for Odoo. It is based on the excellent Click library.
Quick start
Install it in a (preferably virtual) environment where Odoo is installed:
pip install click-odoo
Assuming the following script named list-users.py.
#!/usr/bin/env click-odoo
from __future__ import print_function
for u in env['res.users'].search([]):
print(u.login, u.name)
It can be run with:
click-odoo -d dbname --log-level=error list-users.py
or:
./list-users.py -d dbname --log-level=error
The third technique to create scripts looks like this. Assuming the following script named list-users2.py.
#!/usr/bin/env python
from __future__ import print_function
import click
import click_odoo
@click.command()
@click_odoo.env_options(default_log_level='error')
@click.option('--say-hello', is_flag=True)
def main(env, say_hello):
if say_hello:
click.echo("Hello!")
for u in env['res.users'].search([]):
print(u.login, u.name)
if __name__ == '__main__':
main()
It can be run like this:
$ ./list-users2.py --help Usage: list-users2.py [OPTIONS] Options: -c, --config PATH Specify the Odoo configuration file. Other ways to provide it are with the ODOO_RC or OPENERP_SERVER environment variables, or ~/.odoorc (Odoo >= 10) or ~/.openerp_serverrc. -d, --database TEXT Specify the database name. --log-level TEXT Specify the logging level. Accepted values depend on the Odoo version, and include debug, info warn, error. [default: error] --say-hello --help Show this message and exit. $ ./list-users2.py --say-hello -d dbname Hello! admin Administrator ...
Supported Odoo versions
Odoo version 8, 9, 10 and 11 are supported.
In version 8, Odoo logs to stdout by default. On other versions it is stderr. click-odoo attemps to use stderr for Odoo 8 too.
Database transactions
click-odoo does not commit the transaction for you. To persist changes made to the database, use env.cr.commit().
Command line interface (click-odoo)
Usage: click-odoo [OPTIONS] [SCRIPT] [SCRIPT_ARGS]...
Execute a python script in an initialized Odoo environment. The script has
access to a 'env' global variable which is an odoo.api.Environment
initialized for the given database. If no script is provided, the script
is read from stdin or an interactive console is started if stdin appears
to be a terminal.
Options:
-c, --config PATH Specify the Odoo configuration file. Other
ways to provide it are with the ODOO_RC or
OPENERP_SERVER environment variables, or
~/.odoorc (Odoo >= 10) or
~/.openerp_serverrc.
-d, --database TEXT Specify the database name.
--log-level TEXT Specify the logging level. Accepted values
depend on the Odoo version, and include
debug, info, warn, error. [default: info]
-i, --interactive / --no-interactive
Inspect interactively after running the
script.
--shell-interface TEXT Preferred shell interface for interactive
mode. Accepted values are ipython, ptpython,
bpython, python. If not provided they are
tried in this order.
--help Show this message and exit.
Most options above are the same as odoo options and behave the same. Additional options can be set the the configuration file. Note however that most server-related options (workers, http interface etc) are ignored because no server is actually started when running a script.
An important feature of click-odoo compared to, say, odoo shell is the capability to pass arguments to scripts.
In order to avoid confusion between click-odoo options and your script options and arguments, it is recommended to separate them with --:
click-odoo -d dbname -- list-users.py -d a b ./list-users.py -d dbname -- -d a b
In both examples above, sys.argv[1:] will contain ['-d', 'a', 'b'] in the script.
API
click_odoo.env_options decorator
TODO
OdooEnvironment context manager (experimental)
This package also provides an experimental an OdooEnvironment context manager.
Example:
from click_odoo import OdooEnvironment
with OdooEnvironment(database='dbname') as env:
env['res.users'].search([])
Useful links
pypi page: https://pypi-hypernode.com/pypi/click-odoo
code repository: https://github.com/acsone/click-odoo
report issues at: https://github.com/acsone/click-odoo/issues
Credits
Author:
Stéphane Bidoul (ACSONE)
Inspiration has been drawn from:
odoo’s own shell command
Maintainer
This project is maintained by ACSONE SA/NV.
Changes
1.0.0a1 (2018-03-19)
first alpha
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file click-odoo-1.0.0a1.tar.gz
.
File metadata
- Download URL: click-odoo-1.0.0a1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3a24e364a8a2201f05d5b34fe8aee63b6f2ad246ef2a51d330358d3b0b13251 |
|
MD5 | 29dfc4b16097be9ffa4df4eda4305002 |
|
BLAKE2b-256 | cd28e832510a1fbdfc0fd618835f38f507f43be90ba6211869ac4db35b77b0e1 |
File details
Details for the file click_odoo-1.0.0a1-py2.py3-none-any.whl
.
File metadata
- Download URL: click_odoo-1.0.0a1-py2.py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c68dc0b817fe40e243b8cc61a5f70a0d7dc532d60c8b0f2a1a5dc72dd108f636 |
|
MD5 | 3f7b8f43c18f2a6ce8833ef14d2cb0a1 |
|
BLAKE2b-256 | 51fc777685f73e2ec97e3e14ef63372f39f04b368afc9f824018457c1e5227e9 |