# Odoo XMLRPC Helper Functions
A small set of wrapper functions for facilitating CRUD operations in Odoo via
XMLRPC.
## Getting Started
### Installing via pip
pip install odoo_rpc_helper
### A Simple Connection
```python
from odoo_rpc_helpers import OdooRPCHelper
DB = "test" # Set this to your database name
USERNAME = "admin" # Set this to a real username on the DB
PASSWORD = "admin" # Set this to the password for user above
URL = "http://localhost:8069" # Set this to the server URL
odoo = OdooRPCHelper(DB, USERNAME, PASSWORD, URL)
partner_id = odoo.create("res.partner", {"name": "Test Partner"})[0]
odoo.write("res.partner", [partner_id], {"phone": "+1 (123) 456-7890"})
partner = odoo.search_read(
"res.partner",
[['id', '=', partner_id]],
['name', 'phone']
)[0]
print(f"We have a partner with ID {partner['id']} named {partner['name']} "
f" with phone {partner['phone']}")
odoo.unlink("res.partner", [partner_id])
```
## OdooRPCHelper Class
A class to help with various CRUD operations on an Odoo database via XMLRPC.
### Methods
#### __init__
`__init__(self, database: str, username: str, password: str, url: str = 'http://localhost:8069')`
Initialize the helper and authenticate with the Odoo server.
- **Parameters**:
- `database`: The name of the Odoo database to access
- `username`: The username of the user to execute XMLRPC requests as
- `password`: The password of the user to execute XMLRPC requests as
- `url`: The URL of the Odoo server
#### execute_kw
`execute_kw(self)`
Wrapper around `self.models.execute_kw`, to save effort on rewriting arguments. Simply omit the database, uid, and password arguments as they will be populated from instance variables.
#### create
`create(self, model: str, fields: Dict)`
Wrapper for `execute_kw create`. Create a single record.
- **Parameters**:
- `model`: The model of which to create a record.
- `fields`: The fields to assign during creation.
- **Return**: The ID of the created record.
#### create_multi
`create_multi(self, model: str, fields_list: List[Dict])`
Wrapper for `execute_kw create`. Create one or more records. Exactly like calling `model.create` with a list of dicts in Odoo.
- **Parameters**:
- `model`: The model of which to create a record.
- `fields_list`: The list of dictionaries of fields to assign.
- **Return**: The ID(s) of the created record(s).
#### search
`search(self, model: str, domain: List)`
Wrapper for `execute_kw search` on a model.
- **Parameters**:
- `model`: The Odoo model to search.
- `domain`: The regular Odoo-style domain. This function wraps it for the XMLRPC call.
- **Return**: The list of record IDs found in the search.
#### search_read
`search_read(self, model: str, domain: List, fields: List[str] = None)`
Wrapper for `execute_kw search_read` on a model.
- **Parameters**:
- `model`: The Odoo model to search.
- `domain`: The regular Odoo-style domain.
- `fields`: The fields to be loaded. All fields loaded by default.
- **Return**: A list of dictionaries containing the loaded record fields.
#### read
`read(self, model: str, res_ids: List[int], fields: List[str])`
Wrapper for calling read on a model.
- **Parameters**:
- `model`: The Odoo model to browse.
- `res_ids`: The IDs of the records to browse.
- `fields`: The fields to be read.
- **Return**: List of dictionaries with the requested fields.
#### write
`write(self, model: str, res_ids: List[int], fields: Dict)`
Wrapper for calling write on a model.
- **Parameters**:
- `model`: Model to write to.
- `res_ids`: Record IDs to write to.
- `fields`: Fields to write.
#### unlink
`unlink(self, model: str, res_ids: List[int])`
Wrapper for calling unlink on a model.
- **Parameters**:
- `model`: Model to call unlink on.
- `res_ids`: Record IDs to unlink.
Raw data
{
"_id": null,
"home_page": "https://github.com/bemade/odoo_rpc_helper",
"name": "odoo-rpc-helper",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "odoo rpc xmlrpc",
"author": "Marc Durepos",
"author_email": "marc@bemade.org",
"download_url": "https://files.pythonhosted.org/packages/bd/65/fb7e22777f34d3b03cef7855188964915c84ed1cc6c68042f0e1b5134792/odoo_rpc_helper-0.0.6.tar.gz",
"platform": null,
"description": "# Odoo XMLRPC Helper Functions\n\nA small set of wrapper functions for facilitating CRUD operations in Odoo via\nXMLRPC.\n\n## Getting Started\n\n### Installing via pip\n\n pip install odoo_rpc_helper\n\n### A Simple Connection\n\n```python\nfrom odoo_rpc_helpers import OdooRPCHelper\n\nDB = \"test\" # Set this to your database name\nUSERNAME = \"admin\" # Set this to a real username on the DB\nPASSWORD = \"admin\" # Set this to the password for user above\nURL = \"http://localhost:8069\" # Set this to the server URL\n\nodoo = OdooRPCHelper(DB, USERNAME, PASSWORD, URL)\n\npartner_id = odoo.create(\"res.partner\", {\"name\": \"Test Partner\"})[0]\nodoo.write(\"res.partner\", [partner_id], {\"phone\": \"+1 (123) 456-7890\"})\npartner = odoo.search_read(\n \"res.partner\",\n [['id', '=', partner_id]],\n ['name', 'phone']\n)[0]\nprint(f\"We have a partner with ID {partner['id']} named {partner['name']} \"\n f\" with phone {partner['phone']}\")\nodoo.unlink(\"res.partner\", [partner_id])\n```\n\n## OdooRPCHelper Class\n\nA class to help with various CRUD operations on an Odoo database via XMLRPC.\n\n### Methods\n\n#### __init__\n`__init__(self, database: str, username: str, password: str, url: str = 'http://localhost:8069')`\nInitialize the helper and authenticate with the Odoo server.\n- **Parameters**:\n - `database`: The name of the Odoo database to access\n - `username`: The username of the user to execute XMLRPC requests as\n - `password`: The password of the user to execute XMLRPC requests as\n - `url`: The URL of the Odoo server\n\n#### execute_kw\n`execute_kw(self)`\nWrapper around `self.models.execute_kw`, to save effort on rewriting arguments. Simply omit the database, uid, and password arguments as they will be populated from instance variables.\n\n#### create\n`create(self, model: str, fields: Dict)`\nWrapper for `execute_kw create`. Create a single record.\n- **Parameters**:\n - `model`: The model of which to create a record.\n - `fields`: The fields to assign during creation.\n- **Return**: The ID of the created record.\n\n#### create_multi\n`create_multi(self, model: str, fields_list: List[Dict])`\nWrapper for `execute_kw create`. Create one or more records. Exactly like calling `model.create` with a list of dicts in Odoo.\n- **Parameters**:\n - `model`: The model of which to create a record.\n - `fields_list`: The list of dictionaries of fields to assign.\n- **Return**: The ID(s) of the created record(s).\n\n#### search\n`search(self, model: str, domain: List)`\nWrapper for `execute_kw search` on a model.\n- **Parameters**:\n - `model`: The Odoo model to search.\n - `domain`: The regular Odoo-style domain. This function wraps it for the XMLRPC call.\n- **Return**: The list of record IDs found in the search.\n\n#### search_read\n`search_read(self, model: str, domain: List, fields: List[str] = None)`\nWrapper for `execute_kw search_read` on a model.\n- **Parameters**:\n - `model`: The Odoo model to search.\n - `domain`: The regular Odoo-style domain.\n - `fields`: The fields to be loaded. All fields loaded by default.\n- **Return**: A list of dictionaries containing the loaded record fields.\n\n#### read\n`read(self, model: str, res_ids: List[int], fields: List[str])`\nWrapper for calling read on a model.\n- **Parameters**:\n - `model`: The Odoo model to browse.\n - `res_ids`: The IDs of the records to browse.\n - `fields`: The fields to be read.\n- **Return**: List of dictionaries with the requested fields.\n\n#### write\n`write(self, model: str, res_ids: List[int], fields: Dict)`\nWrapper for calling write on a model.\n- **Parameters**:\n - `model`: Model to write to.\n - `res_ids`: Record IDs to write to.\n - `fields`: Fields to write.\n\n#### unlink\n`unlink(self, model: str, res_ids: List[int])`\nWrapper for calling unlink on a model.\n- **Parameters**:\n - `model`: Model to call unlink on.\n - `res_ids`: Record IDs to unlink.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple wrapper for more easily running Odoo RPC commands.",
"version": "0.0.6",
"project_urls": {
"Homepage": "https://github.com/bemade/odoo_rpc_helper"
},
"split_keywords": [
"odoo",
"rpc",
"xmlrpc"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fbcb4434f1aee4719c72fcf72e8b4d73e28401ef99e69c9ebf059430bf3009c0",
"md5": "413db3e6d3cd116621745802420bd58c",
"sha256": "268f61118d4ddb846b2cab301ed4dedec137899d5d4cf1c28e30aae1e954accc"
},
"downloads": -1,
"filename": "odoo_rpc_helper-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "413db3e6d3cd116621745802420bd58c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5722,
"upload_time": "2024-04-22T20:28:28",
"upload_time_iso_8601": "2024-04-22T20:28:28.246165Z",
"url": "https://files.pythonhosted.org/packages/fb/cb/4434f1aee4719c72fcf72e8b4d73e28401ef99e69c9ebf059430bf3009c0/odoo_rpc_helper-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bd65fb7e22777f34d3b03cef7855188964915c84ed1cc6c68042f0e1b5134792",
"md5": "cc84446a703094ce6d6d31f2c9ab178f",
"sha256": "1a4bce8ba784102bfd17413a8247a2c2eccc2df5a0d51da7f41a57adbd2e8f3d"
},
"downloads": -1,
"filename": "odoo_rpc_helper-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "cc84446a703094ce6d6d31f2c9ab178f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4741,
"upload_time": "2024-04-22T20:28:29",
"upload_time_iso_8601": "2024-04-22T20:28:29.740563Z",
"url": "https://files.pythonhosted.org/packages/bd/65/fb7e22777f34d3b03cef7855188964915c84ed1cc6c68042f0e1b5134792/odoo_rpc_helper-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-22 20:28:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bemade",
"github_project": "odoo_rpc_helper",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "odoo-rpc-helper"
}