Skip to main content

CLO (Command-Line Odoo) - Perform API operations on Odoo instances from the command-line.

Project description

CLO (Command-Line Odoo)

Build Status Coverage PyPI version

Perform API operations on Odoo instances via the command-line.

Contents

Installation

pip3 install clo

Usage

clo [OPTIONS] ACTION ...

Globals

The following parameters apply to any Action.

Options

Flag(s) Argument Required Description                                                                         . Default
‑‑model
‑m
MODEL NO The Odoo model to perform an action on. Run clo explain models [-v] to list available options. "res.users"
‑‑env FILE NO Path to a .clorc file. See Requisites below for details. ".clorc"
‑‑inst
‑‑instance
URL NO The address of the Odoo instance. See Requisites below for details.
‑‑db
‑‑database
NAME NO The application database to perform operations on. See Requisites below for details.
‑‑user NAME NO The user to perform operations as. See Requisites below for details.
‑‑demo FILE NO Generate a demo instance from Odoo Cloud and save the connection properties to FILE. ".clorc"
‑‑out FILE NO Where to stream the output.
‑‑log LEVEL NO The level (OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE) of logs to produce. "WARN"
‑‑dry‑run NO Perform a "practice" run of the action; implies --log=DEBUG. false
‑‑help
‑h
NO Show this help message and exit.
‑‑version NO Show version of this program.

Requisites

The following inputs are required, but have multiple or special specifications. In the absense of these inputs, the program will ask for input:

  • --instance can be specified using environment variable CLO_INSTANCE.
  • --database can be specified using environment variable CLO_DATABASE.
  • --username can be specified using environment variable CLO_USERNAME.
  • The password (or API-key) MUST BE specified using environment variable CLO_PASSWORD.

clo also looks for a .clorc file in the working directory that contain these values, or the file specified by --env FILE, if it exists.

Actions

The Odoo instance is queried, or operated on, using ACTIONS. Each ACTION has it's own set of arguements; run clo ACTION --help for specific details.

Search

clo [OPTIONS] ACTION ... search [[-o|-n|-a] -d FIELD OPERATOR VALUE [-d ...]] [--offset POSITION] [--limit AMOUNT] [--order FIELD] [--count] [-h]

Searches for record IDs based on the search domain.

Options
Flag(s) Argument Required Description                                                                         . Default
‑‑domain
‑d
FIELD
OPERATOR
VALUE
NO A set of criterion to filter the search by (run clo explain domains for details). This option can be specified multiple times. []
‑‑or
‑o
NO A logical OR, placed before two or more domains (arity 2). Run clo explain logic for more details.
‑‑and
‑a
NO A logical AND to place before two or more domains (arity 2). Run clo explain logic for more details.
‑‑not
‑n
NO A logical OR to place before a signle domain (arity 1). Run clo explain logic for more details.
‑‑offset POSITION NO Number of results to ignore. 0
‑‑limit AMOUNT NO Maximum number of records to return.
‑‑order FIELD NO The field to sort the records by.
‑‑raw
‑r
NO Format output as space-separated IDs rather than pretty JSON. false
‑‑help
‑h
NO Show this help message and exit.

Count

clo [OPTIONS] ACTION ... count [--domain FIELD OPERATOR VALUE] [--or] [--and] [--not] [--limit AMOUNT] [--help]

Returns the number of records in the current model matching the provided domain.

Options
Flag(s) Argument Required Description                                                                         . Default
‑‑domain
‑d
FIELD
OPERATOR
VALUE
NO A set of criterion to filter the search by (run clo explain domains for details). This option can be specified multiple times. []
‑‑or
‑o
NO A logical OR, placed before two or more domains (arity 2). Run clo explain logic for more details.
‑‑and
‑a
NO A logical AND to place before two or more domains (arity 2). Run clo explain logic for more details.
‑‑not
‑n
NO A logical OR to place before a signle domain (arity 1). Run clo explain logic for more details.
‑‑limit AMOUNT NO Maximum number of records to return.
‑‑help
‑h
NO Show this help message and exit.

Read

clo [OPTIONS] ACTION ... read --ids ID [ID ...] [--fields FIELD [FIELD ...]] [--csv] [--help]

Retrieves the details for the records at the ID(s) specified.

Options
Flag(s) Argument Required Description                                                                         . Default
‑‑ids
‑i
ID YES The ID number(s) of the record(s) to perform the action on. Specifying - expects a space-separated list from STDIN.
‑‑fields
‑f
FIELD NO Field names to return (default is all fields). []
‑‑csv NO If True, outputs records in CSV format. false
‑‑help
‑h
NO Show this help message and exit.

Find

clo [OPTIONS] ACTION ... find [[-o|-n|-a] -d FIELD OPERATOR VALUE [-d ...]] [-f FIELD ...] [--offset POSITION] [--limit AMOUNT] [--order FIELD] [--csv [FILE]] [--help]

A shortcut that combines search and read into one execution.

Options
Flag(s) Argument Required Description                                                                         . Default
‑‑domain
‑d
FIELD
OPERATOR
VALUE
NO A set of criterion to filter the search by (run clo explain domains for details). This option can be specified multiple times. []
‑‑or
‑o
NO A logical OR, placed before two or more domains (arity 2). Run clo explain logic for more details.
‑‑and
‑a
NO A logical AND to place before two or more domains (arity 2). Run clo explain logic for more details.
‑‑not
‑n
NO A logical OR to place before a signle domain (arity 1). Run clo explain logic for more details.
‑‑fields
‑f
FIELD NO Field names to return (default is all fields). []
‑‑offset POSITION NO Number of results to ignore. 0
‑‑limit AMOUNT NO Maximum number of records to return.
‑‑order FIELD NO The field to sort the records by.
‑‑csv NO If True, outputs records in CSV format. false
‑‑help
‑h
NO Show this help message and exit.

Create

clo [OPTIONS] ACTION ... create --value FIELD VALUE [--help]

Creates new records in the current model.

Options
Flag(s) Argument Required Description                                                                         . Default
‑‑value
‑v
FIELD
VALUE
YES Key/value pair(s) that correspond to the field and assigment to be made, respectively.
‑‑help
‑h
NO Show this help message and exit.

Write

clo [OPTIONS] ACTION ... write --ids ID [ID ...] --value FIELD VALUE [--help]

Updates existing records in the current model.

Options
Flag(s) Argument Required Description                                                                         . Default
‑‑ids
‑i
ID YES The ID number(s) of the record(s) to perform the action on. Specifying - expects a space-separated list from STDIN.
‑‑value
‑v
FIELD
VALUE
YES Key/value pair(s) that correspond to the field and assigment to be made, respectively.
‑‑help
‑h
NO Show this help message and exit.

Delete

clo [OPTIONS] ACTION ... delete --ids ID [ID ...] [--help]

Deletes the records from the current model.

Options
Flag(s) Argument Required Description                                                                         . Default
‑‑ids
‑i
ID YES The ID number(s) of the record(s) to perform the action on. Specifying - expects a space-separated list from STDIN.
‑‑help
‑h
NO Show this help message and exit.

Fields

clo [OPTIONS] ACTION ... fields [--attributes NAME [NAME ...]] [--help]

Retrieves raw details of the fields available in the current model. For user-friendly formatting, run clo [OPTIONS] ACTION ... fields explain fields.

Options
Flag(s) Argument Required Description                                                                         . Default
‑‑attributes
‑‑attr
‑a
NAME NO Attribute(s) to return for each field, all if empty or not provided.
‑‑help
‑h
NO Show this help message and exit.

Explain

clo [OPTIONS] ACTION ... explain [--verbose] [--help] {models,domains,logic,fields}

Display documentation on a specified topic.

Positional
Argument Required Description                                                                         . Default
{models,domains,logic,fields} YES A topic to get further explanation on.
Options
Flag(s) Argument Required Description                                                                         . Default
‑‑verbose
‑v
NO Display more details. false
‑‑help
‑h
NO Show this help message and exit.

Concepts

The following breakdowns apply to search-style ACTIONS.

DOMAINS

A domain is a set of criteria, each criterion being a throuple of (FIELD, OPERATOR, VALUE) where:

FIELD: A field name of the current model, or a relationship traversal through a Many2one using dot-notation.

OPERATOR: An operand used to compare the FIELD with the value. Valid operators are:

          =, !=, >, >=, <, <=   Standard comparison operators.

          =?                    Unset or equals to (_returns true if value is either None or
                                False, otherwise behaves like `=`_).

          =[i]like              Matches `FIELD` against the value pattern. An underscore (_`_`_)
                                in the pattern matches any single character; a percent sign
                                (_`%`_) matches any string of zero or more characters. `=ilike`
                                makes the search case-insensitive.

          [not ][i]like         Matches (_or inverse-matches_) `FIELD` against the %value%
                                pattern. Similar to `=[i]like` but wraps value with `%` before
                                matching.

          [not ]in              Is—or is not—equal to any of the items from value, value should
                                be a list of items.

          child_of              Is a child (_descendant_) of a value record (_value can
                                be either one item or a list of items_). Takes the semantics
                                of the model into account (_i.e following the relationship
                                `FIELD` named by `VALUE`_).

          parent_of             Is a child (_ascendant_) of a value record (_value can
                                be either one item or a list of items_). Takes the semantics
                                of the model into account (_i.e following the relationship
                                `FIELD` named by `VALUE`_).

VALUE: Variable type, must be comparable (through OPERATOR) to the named FIELD.

LOGIC

Domain criteria can be combined using logical operators in prefix form:

--or -d login = user -d name = "John Smith" -d email = user@domain.com

is equivalent to login == "user" || name == "John Smith" || email == "user@domain.com"

--not -d login = user` or `-d login '!=' user

are equivalent to login != "user". --not is generally unneeded, save for negating the OPERATOR, child_of, or parent_of.

--and -d login = user -d name = "John Smith"

is equivalent to login == "user" && name == "John Smith"; though, successive domainsimply --and.

See Also

Banner

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.6.0] - 2023-10-21

Fixed

  • Issue where non-API-required options prompt user for requisites/credentials.

Changed

  • Env-vars now prefixed with CLO_ instead of OD_.
  • Auth env-vars no longer abbreviated.
  • --env now defaults to .clorc, instead of ~/.clorc.
  • --demo now accepts the save path, as opposed to using --out.
  • --demo now defaults to .clorc.

[0.5.0] - 2023-10-16

Added

  • Initial feature set.
  • Added tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clo-0.6.0.tar.gz (135.6 kB view details)

Uploaded Source

Built Distribution

clo-0.6.0-py3-none-any.whl (41.0 kB view details)

Uploaded Python 3

File details

Details for the file clo-0.6.0.tar.gz.

File metadata

  • Download URL: clo-0.6.0.tar.gz
  • Upload date:
  • Size: 135.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for clo-0.6.0.tar.gz
Algorithm Hash digest
SHA256 6c2e4d5b58ba8e96b0970fc7bf749495f12b4012ba7edd11e5cdbba966b551fa
MD5 d051383d34ec1dbdffbf181136a8f97f
BLAKE2b-256 82cc4123a24ee000b3332e2bfa1a027d2dcc097cee4d8e4810732e17e6dade05

See more details on using hashes here.

File details

Details for the file clo-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: clo-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 41.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for clo-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c343a2095c4794d10be73b31c6910561b591cd5756051ea569b6d45a5e0d75e
MD5 76ab2779bce21697ba73025b090b2b85
BLAKE2b-256 15746006be2ced0784f1aca13d2e2f41b7e596fc0eb17bb48f09f93826d3d57e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page