Skip to content

Commit

Permalink
Merge pull request #3 from fasilwdr/dev
Browse files Browse the repository at this point in the history
Release v0.1.6
  • Loading branch information
fasilwdr authored Dec 8, 2024
2 parents feedbf2 + af27b9a commit bc20d80
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -229,6 +239,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

- **Name:** Fasil
- **Email:** [email protected]
- **WhatsApp:** [Contact](https://wa.me/966538952934)
- **Facebook:** [Profile](https://www.facebook.com/fasilwdr)
- **Instagram:** [Profile](https://www.instagram.com/fasilwdr)
- **WhatsApp:** [Contact](https://wa.me/966538952934)
2 changes: 1 addition & 1 deletion pyodoo_connect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
from .odoo import connect_odoo
from .tools import Command

__version__ = "0.1.5"
__version__ = "0.1.6"
24 changes: 20 additions & 4 deletions pyodoo_connect/odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }]
license = { file = "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pyodoo_connect
version = 0.1.5
version = 0.1.6
author = Fasil
author_email = [email protected]
description = A Python package to interact with Odoo via JSON-RPC.
Expand Down

0 comments on commit bc20d80

Please sign in to comment.