From af27b9a018aab0ab14abefabf60695325e588d6b Mon Sep 17 00:00:00 2001 From: Fasil | Python/Odoo Developer Date: Sun, 8 Dec 2024 15:18:55 +0300 Subject: [PATCH] Release v0.1.6 ## New Features 1. **Session ID Based Authentication** - Added ability to connect to Odoo using only URL and session ID - Useful for maintaining existing sessions or connecting with pre-authenticated sessions - Simplified connection process when session ID is already available ## Improvements 1. **Connection Flexibility** - Modified OdooAPI class to handle both credential-based and session-based authentication - Added validation to ensure either session ID or complete credentials are provided - Improved error handling for session validation ## Technical Changes 1. **API Changes** - Updated `connect_odoo()` function signature to make credentials optional when session ID is provided - Modified internal session validation logic to work with both authentication methods - Added new parameter validations in OdooAPI class initialization ## Breaking Changes - None. All existing functionality remains backward compatible ## Migration Guide No migration needed. Existing code will continue to work as before. To use the new session ID feature, simply provide the session ID instead of credentials. ## Bug Fixes - Improved error handling when invalid session IDs are provided - Better validation of connection parameters ## Security Notes - Session IDs should be treated as sensitive information - It's recommended to use HTTPS when connecting with session IDs - Session expiration policies of your Odoo instance still apply ## Usage Recommendations 1. Use credential-based authentication for: - Initial connections - Automated scripts - When session persistence isn't required 2. Use session ID authentication for: - Maintaining existing sessions - Integration with other systems that already have valid sessions - Reducing authentication overhead in trusted environments --- README.md | 26 +++++++++++++++++--------- pyodoo_connect/__init__.py | 2 +- pyodoo_connect/odoo.py | 24 ++++++++++++++++++++---- pyproject.toml | 2 +- setup.cfg | 2 +- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 961c1f1..d623a2e 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,12 @@ A powerful Python package for interacting with Odoo platforms via JSON-RPC. This - 🔍 Smart record browsing and caching - 📊 Efficient batch operations - 🌐 Context management +- 🔑 Session ID based authentication (New in 0.1.6) ## Installation ```bash -pip install pyodoo_connect +pip install pyodoo_connect --upgrade ``` ### Requirements @@ -28,21 +29,30 @@ pip install pyodoo_connect ### Basic Connection +You can connect to Odoo in two ways: + +#### 1. Using Credentials (Traditional) ```python from pyodoo_connect import connect_odoo -# Connect to Odoo +# Connect using credentials odoo, session_id = connect_odoo( url="https://your-odoo-instance.com", db="your_database", username="your_username", password="your_password" ) +``` + +#### 2. Using Session ID (New in 0.1.6) +```python +from pyodoo_connect import connect_odoo -# Check connection -if odoo: - print("Successfully connected!") - print(f"Session ID: {session_id}") +# Connect using existing session ID +odoo, session_id = connect_odoo( + url="https://your-odoo-instance.com", + session_id="your_session_id" +) ``` ## Usage Examples @@ -229,6 +239,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file - **Name:** Fasil - **Email:** fasilwdr@hotmail.com -- **WhatsApp:** [Contact](https://wa.me/966538952934) -- **Facebook:** [Profile](https://www.facebook.com/fasilwdr) -- **Instagram:** [Profile](https://www.instagram.com/fasilwdr) \ No newline at end of file +- **WhatsApp:** [Contact](https://wa.me/966538952934) \ No newline at end of file diff --git a/pyodoo_connect/__init__.py b/pyodoo_connect/__init__.py index 9b92758..e220586 100644 --- a/pyodoo_connect/__init__.py +++ b/pyodoo_connect/__init__.py @@ -11,4 +11,4 @@ from .odoo import connect_odoo from .tools import Command -__version__ = "0.1.5" +__version__ = "0.1.6" diff --git a/pyodoo_connect/odoo.py b/pyodoo_connect/odoo.py index 93f7fea..6193f51 100644 --- a/pyodoo_connect/odoo.py +++ b/pyodoo_connect/odoo.py @@ -285,9 +285,12 @@ def read(self, ids: List[int], fields: List[str] = None) -> List[Dict]: class OdooAPI: - def __init__(self, url: str, db: str, username: str, password: str, session_id: str = None): + def __init__(self, url: str, db: str = None, username: str = None, password: str = None, session_id: str = None): if not url: raise OdooValidationError("URL cannot be empty") + if not any([session_id, all([db, username, password])]): + raise OdooValidationError("Either session_id or (db, username, password) must be provided") + self.url = url.rstrip('/') self.db = db self.username = username @@ -446,10 +449,23 @@ def _make_request(self, endpoint: str, payload: dict) -> Optional[dict]: raise OdooRequestError(f"Unexpected error: {str(e)}") -def connect_odoo(url: str, db: str, username: str, password: str, session_id: str = None) -> tuple[ - Optional[OdooAPI], Optional[str]]: +def connect_odoo(url: str, db: str = None, username: str = None, password: str = None, + session_id: str = None) -> tuple[Optional[OdooAPI], Optional[str]]: + """ + Connect to Odoo using either credentials or session ID. + + Args: + url: Odoo instance URL + db: Database name (optional if session_id is provided) + username: Username (optional if session_id is provided) + password: Password (optional if session_id is provided) + session_id: Existing session ID (optional if credentials are provided) + + Returns: + tuple: (OdooAPI instance, session_id) or (None, None) if connection fails + """ try: - api = OdooAPI(url, db, username, password, session_id) + api = OdooAPI(url=url, db=db, username=username, password=password, session_id=session_id) if api.connect(): return api, api.session_id raise OdooAuthenticationError("Failed to connect to Odoo server") diff --git a/pyproject.toml b/pyproject.toml index 792c377..aab895a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pyodoo_connect" -version = "0.1.5" +version = "0.1.6" description = "A Python package to interact with Odoo via JSON-RPC." authors = [{ name = "Fasil", email = "fasilwdr@hotmail.com" }] license = { file = "LICENSE" } diff --git a/setup.cfg b/setup.cfg index 0347c0c..ff25460 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pyodoo_connect -version = 0.1.5 +version = 0.1.6 author = Fasil author_email = fasilwdr@hotmail.com description = A Python package to interact with Odoo via JSON-RPC.