#!/usr/bin/env python3
"""
Odoo Company Setup Script for HR, Finance, and Approvals
"""
import os
import sys
import json
from pathlib import Path
# Add the src directory to Python path
project_root = Path(__file__).parent
src_path = project_root / 'src'
sys.path.insert(0, str(src_path))
try:
from odoo_mcp.odoo_client import OdooClient
from odoo_mcp.config import OdooConfig
except ImportError as e:
print(f"Error importing modules: {e}")
sys.exit(1)
def setup_company_modules():
"""Set up essential modules for HR, Finance, and Approvals"""
# Load configuration
config_file = project_root / 'odoo_config.json'
if not config_file.exists():
print("ā odoo_config.json not found!")
return False
with open(config_file, 'r') as f:
config_data = json.load(f)
print("š Setting up Odoo for your company...")
print(f"š Connecting to: {config_data['url']}")
print(f"š Database: {config_data['db']}")
try:
# Create Odoo client
client = OdooClient(
url=config_data['url'],
db=config_data['db'],
username=config_data['username'],
password=config_data['password']
)
print("ā
Connected to Odoo successfully!")
# Check current user permissions
user_info = client._execute('res.users', 'read', [client.uid], ['name'])
print(f"š¤ Logged in as: {user_info[0]['name']}")
# Essential modules to install/check
essential_modules = [
'hr', # Human Resources
'hr_holidays', # Leave Management
'hr_expense', # Expense Management
'hr_timesheet', # Timesheets
'account', # Accounting
'account_invoicing', # Invoicing
'purchase', # Purchase Management
'approvals', # Approvals Workflow
'hr_expense_approve', # Expense Approvals
]
print("\nš¦ Checking essential modules...")
# Get installed modules
installed_modules = client._execute(
'ir.module.module',
'search_read',
[('state', '=', 'installed')],
['name', 'display_name']
)
installed_names = [mod['name'] for mod in installed_modules]
print(f"ā
Currently installed: {len(installed_names)} modules")
# Check which essential modules are missing
missing_modules = []
for module in essential_modules:
if module not in installed_names:
# Check if module exists and can be installed
available = client._execute(
'ir.module.module',
'search_read',
[('name', '=', module), ('state', 'in', ['uninstalled', 'to install'])],
['name', 'display_name', 'state']
)
if available:
missing_modules.extend(available)
if missing_modules:
print(f"\nš„ Found {len(missing_modules)} modules to install:")
for module in missing_modules:
print(f" - {module['display_name']} ({module['name']})")
else:
print("ā
All essential modules are already installed!")
# Company setup
print("\nš¢ Setting up company information...")
# Get current company
company = client._execute('res.company', 'search_read', [('id', '=', 1)],
['name', 'email', 'phone', 'website', 'currency_id'])
if company:
current_company = company[0]
print(f"Current company: {current_company['name']}")
print(f"Email: {current_company.get('email', 'Not set')}")
print(f"Phone: {current_company.get('phone', 'Not set')}")
print(f"Currency: {current_company.get('currency_id', ['Not set'])[1] if current_company.get('currency_id') else 'Not set'}")
# HR Setup
print("\nš„ HR Module Setup:")
# Check for HR employees
employees = client._execute('hr.employee', 'search_count', [])
print(f" š Current employees: {employees}")
# Check departments
departments = client._execute('hr.department', 'search_read', [], ['name'])
print(f" š¢ Departments: {len(departments)}")
for dept in departments[:5]: # Show first 5
print(f" - {dept['name']}")
# Finance Setup
print("\nš° Finance Module Setup:")
# Check chart of accounts
accounts = client._execute('account.account', 'search_count', [])
print(f" š Chart of accounts: {accounts} accounts")
# Check journals
journals = client._execute('account.journal', 'search_read', [], ['name', 'type'])
print(f" š Journals: {len(journals)}")
for journal in journals[:5]: # Show first 5
print(f" - {journal['name']} ({journal['type']})")
# Approvals Setup
print("\nā
Approvals Module Setup:")
# Check approval categories
try:
approval_categories = client._execute('approval.category', 'search_read', [], ['name'])
print(f" š Approval categories: {len(approval_categories)}")
for cat in approval_categories:
print(f" - {cat['name']}")
except Exception as e:
print(f" ā ļø Approvals module may not be installed: {e}")
# User Management
print("\nš¤ User Management:")
users = client._execute('res.users', 'search_read', [('active', '=', True)], ['name', 'login'])
print(f" š Active users: {len(users)}")
for user in users[:5]: # Show first 5
print(f" - {user['name']} ({user['login']})")
print("\nš Odoo setup assessment completed!")
print("\nš Next Steps:")
print("1. Install missing modules if needed")
print("2. Configure company information")
print("3. Set up departments and job positions")
print("4. Create employee records")
print("5. Configure approval workflows")
print("6. Set up accounting (chart of accounts, taxes)")
print("7. Create user accounts and assign permissions")
return True
except Exception as e:
print(f"ā Error setting up Odoo: {e}")
return False
if __name__ == "__main__":
success = setup_company_modules()
sys.exit(0 if success else 1)