A Python package to interact with Odoo via JSON-RPC.
Project description
PyOdoo Connector
PyOdoo Connector is a Python package providing a convenient way to interact with Odoo platforms via JSON-RPC. It simplifies operations like logging in, executing commands, and managing records in an Odoo database.
Features
- Session Management: Handles login and session management automatically.
- CRUD Operations: Easy-to-use functions for creating, reading, updating, and deleting records.
- Method Execution: Supports calling custom methods defined in Odoo models.
- Error Handling: Implements error handling for HTTP and URL request errors.
- Report Downloading: Allows downloading reports from Odoo in PDF form.
Installation
Install Odoo Connector using pip:
pip install pyodoo_connect
Prerequisites
- Python 3.6 or higher.
- Access to an Odoo instance with the JSON-RPC interface enabled.
Ensure you have the necessary permissions to interact with the Odoo server as some operations might require administrative access.
Configuration
Before using this module, configure the connection parameters to match your Odoo instance settings:
- URL: The URL of your Odoo server.
- Database: The database name.
- Username: Your Odoo username.
- Password: Your Odoo password.
Usage
Here is a simple example to show how you can use Odoo Connector to interact with an Odoo instance:
Initializing the Connection
from pyodoo_connect import Odoo
odoo = Odoo('https://example-odoo.com/', 'your-db', 'your-username', 'your-password')
Basic Operations
- Get a Partner Record
partner = odoo.env['res.partner'].browse(9)
partner.name = 'New Partner Name'
- Execute a Method on a Record
partner.action_archive()
partner.update({'mobile': '12345678'})
- Search for Records
partner_ids = odoo.env['res.partner'].search([('name', '=', 'Abigail Peterson')])
print(partner_ids)
#[50]
- Read Records
print(partner.name)
records = odoo.env['res.partner'].read(ids=partner_ids, fields=['name', 'email'])
print(records)
#Wood Corner
#[{'id': 50, 'name': 'Abigail Peterson', 'email': 'abigail.peterson39@example.com'}]
- Create a New Record
new_partner_id = odoo.env['res.partner'].create({'name': 'New Partner', 'email': 'new@partner.com', 'is_company': True})
print(new_partner_id)
#100
- Update Records
#These are the ways to update records
partner.mobile = '+91 9746707744'
partner.write({'mobile': '+91 9746707744'})
odoo.env['res.partner'].write(ids=new_partner_id, values={'phone': '1234567890'})
- Update Relation fields (One2many or Many2many)
from pyodoo_connect import Command
partner.category_id = [Command.set([5,6])]
partner.write({'category_id': [Command.link([4,3])]})
odoo.env['res.partner'].write(ids=new_partner_id, values={'category_id': [Command.create({'name': 'New Tag'})]})
#All functions of Command can be used (create, update, delete, unlink, link, clear, set)
- Delete Records
odoo.env['res.partner'].unlink(ids=new_partner_id)
- Download a QWeb Report
odoo.download_report(report_name='sale.report_saleorder', record_ids=[52], file_name='Sales Report')
- Version
print(odoo.version)
#17.0
- With Context
record_id = odoo.env['purchase.order'].browse(14)
record_id.with_context({'send_rfq':True}).action_rfq_send()
#or
record_id.with_context(send_rfq=True).action_rfq_send()
- UID
print(odoo.uid)
#2
- User Context
print(odoo.env.context)
#{'lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 2}
- User Info
print(odoo.env.user_info)
#{'uid': 2, 'is_admin': True, 'name': 'Mitchell Admin', 'username': 'admin', 'partner_id': 3}
- Settings
print(odoo.env.settings)
#{'web_base_url': 'https://demo.odoo.com', 'localization': {'lang': 'en_US', 'tz': 'Europe/Brussels'}, 'company_details': {'current_company': 1, 'allowed_companies': {'2': {'id': 2, 'name': 'My Company (Chicago)', 'sequence': 10, 'child_ids': [], 'parent_id': False, 'timesheet_uom_id': 4, 'timesheet_uom_factor': 1.0}, '1': {'id': 1, 'name': 'My Company (San Francisco)', 'sequence': 0, 'child_ids': [], 'parent_id': False, 'timesheet_uom_id': 4, 'timesheet_uom_factor': 1.0}}, 'disallowed_ancestor_companies': {}}}
Contributing
Contributions are welcome! Please feel free to submit pull requests, report bugs, or suggest features.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Built Distribution
File details
Details for the file pyodoo_connect-0.1.4.tar.gz
.
File metadata
- Download URL: pyodoo_connect-0.1.4.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f40bc9f2dddba3bc7ec91468704d3fffdceb38f60ded9b6ba22344e45a778774 |
|
MD5 | c54dc9736009d9e64a5505fdbc3f8086 |
|
BLAKE2b-256 | 4d0cbcc4c0bf476f91434bea88731d0632a961455d58d81e93091298792d8145 |
File details
Details for the file pyodoo_connect-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: pyodoo_connect-0.1.4-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95774a72579020c17cbe7727f1816904d827d7a9d11960aa37e310ad44794a38 |
|
MD5 | 822b25ed1cd082293415f776b8d21683 |
|
BLAKE2b-256 | bc9cf8f7e6c85a96593fb415dafc89ca23c4406d4d7f7f228b48dcd325651d38 |