A simple Python library to make CRUD process easier
Project description
Odoo XMLRPC Wrapper
A small wrapper for oversimplifying CRUD operations and connecting to the Odoo External API with the Python xmlrpc module.
Index
Getting Started
Installing via pip
pip install odoo-xmlrpc-wrapper
A Simple Connection
from odoo_xmlrpc_wrapper import odoo_xmlrpc_wrapper as oxw
HOST = "odoo.myhost.com"
DB = "my_test_db"
USERLOGIN = "mymailtologin@odoo.com"
PASSWORD = "mypass"
bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD)
Prints:
Successfully Logged
Name: Mitchell Admin
DB: my_test_db
HOST: https://odoo.myhost.com
VERSION: saas~16.1
CRUD Operations
Once the model to be processed in the CRUD functions is entered, the following other You do not need to specify the model again as long as the model does not change to the operation functions.
Create
bot.create("res.partner", {"name": "John Doe"})
Read
bot.read(ids=[84], fields=["name"])
Returns: [{"id": 84, "name": "John Doe"}]
Update
bot.update(the_id=84, the_obj={"name": "Jane Doe"})
Delete
bot.delete(ids=[84])
Miscellaneous
Search
bot.search(constraints=[("name", "=", "Mitchell Admin")])
Returns:
[2]
Search and Read
bot.search_read(constraints=[("name", "=", "Mitchell Admin")])
Returns: [{'id': 2, 'name': 'Mitchell Admin'}]
Count
bot.count()
Returns: 78
Get Fields
bot.get_fields("res.partner.title", attributes=["type"])
Output:
{
"name": {"type": "char"},
"shortcut": {"type": "char"},
"id": {"type": "integer"},
"display_name": {"type": "char"},
"create_uid": {"type": "many2one"},
"create_date": {"type": "datetime"},
"write_uid": {"type": "many2one"},
"write_date": {"type": "datetime"},
}
A Little Detail
Bot Instance
bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD) # Simple Connection
bot = oxw.Bot(HOST, DB, USERLOGIN, PASSWORD, secured=False) # For http:// (no-ssl) (localhost)
bot = oxw.Bot(test=True) # For XMLRPC Tests from Odoo saas
If you are going to connect to a host with an unencrypted http protocol such as localhost,
secured=False
must be specified.
test=True
allows you to connect to one of Odoo's own xmlrpc test servers. Odoo assigns
you a random host, database, user and password from the demo servers. You don't need other
attributes when test option is selected.
Active Model
The default model when a bot instance is initialized is "res.users"
. So when you command
bot.count()
it returns active users total as an integer.
You can assign the active model at any time with bot.model = "model.name"
or when calling
any next method, such as bot.count("res.partner")
Contribution
Feel free to contribute. This project needs a fine exception handling.
License
Copyright 2023 Cagatay URESIN
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 odoo_xmlrpc_wrapper-1.1.1.tar.gz
.
File metadata
- Download URL: odoo_xmlrpc_wrapper-1.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98eab285eff942351d50811686226c383a1718c98015b53569b5013a0bdbadcc |
|
MD5 | f40ef37fff817d9de7981785718de08e |
|
BLAKE2b-256 | c500f581e27b97eb9b47793e561009502f20872411429a9493a01f90832c39b8 |
File details
Details for the file odoo_xmlrpc_wrapper-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: odoo_xmlrpc_wrapper-1.1.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21b9fe0c58ba115b439e547db652e982f9c8415cc4cd09a2bb096ff7a6704685 |
|
MD5 | 65c270625c0a3bc7960b436975efa3f3 |
|
BLAKE2b-256 | 5c7197a3652053f19e33d1e7918010d775504f584b9901950527d631ef7c631c |