# -*- coding: utf-8 -*- from odoo import http, fields from odoo.http import request import json import logging _logger = logging.getLogger(__name__) class ExpertController(http.Controller): @http.route('/expert_theme/test', type='http', auth='user') def test_controller(self): """Simple test endpoint to verify controller is working""" return request.make_json_response({ 'success': True, 'message': 'Controller is working!', 'timestamp': fields.Datetime.now() }) @http.route('/expert_theme/get_css_variables', type='http', auth='user') def get_css_variables(self): """Get CSS variables for the active theme configuration""" try: config = request.env['expert.theme.config'].get_active_config() css_variables = config.get_css_variables() return request.make_json_response({ 'success': True, 'css_variables': css_variables }) except Exception as e: return request.make_json_response({ 'success': False, 'error': str(e) }) @http.route('/expert_theme/apply_theme', type='http', auth='user', methods=['POST']) def apply_theme(self): """Apply theme changes immediately""" try: # Get the active configuration config = request.env['expert.theme.config'].get_active_config() # Apply the theme (this could trigger cache invalidation, etc.) config.apply_theme() return request.make_json_response({ 'success': True, 'message': 'Theme applied successfully!' }) except Exception as e: return request.make_json_response({ 'success': False, 'error': str(e) }) @http.route('/expert_theme/get_login_template_styles', type='http', auth='public', methods=['GET']) def get_login_template_styles(self): """Get CSS styles for the active login template (public access for login page)""" try: template = request.env['expert.login.template'].sudo().get_active_template() styles = template.get_template_styles() return request.make_json_response({ 'success': True, 'styles': styles }) except Exception as e: # Return default styles if error return request.make_json_response({ 'success': False, 'error': str(e), 'styles': {'background_color': '#FFFFFF'} }) @http.route('/expert_theme/get_installed_modules_http', type='http', auth='user') def get_installed_modules_http(self): """Return list of installed modules for the home page via HTTP""" try: # Get all installed modules installed_modules = request.env['ir.module.module'].search([ ('state', '=', 'installed'), ('name', '!=', 'expert_theme') # Exclude our own module ]) # Get all top-level menu items that belong to installed modules menu_items = request.env['ir.ui.menu'].search([ ('parent_id', '=', False), # Top level menus only ('active', '=', True), ('name', 'not in', ['Expert Home', 'Dashboard']) # Exclude our own menus ]) result = [] installed_module_names = installed_modules.mapped('name') debug_info = { 'total_installed_modules': len(installed_modules), 'total_menu_items': len(menu_items) } for menu in menu_items: # Check if this menu belongs to an installed module module_name = None if menu.web_icon and ',' in menu.web_icon: module_name = menu.web_icon.split(',')[0] # Include menu if it belongs to an installed module OR if it has no web_icon (base modules) if (module_name and module_name in installed_module_names) or not menu.web_icon: # Create URL based on action type - use proper Odoo navigation if menu.action and menu.action.type == 'ir.actions.act_window': # For act_window, use the action ID url = f'/web#action={menu.action.id}' elif menu.action and menu.action.type == 'ir.actions.client': # For client actions, use the action ID url = f'/web#action={menu.action.id}' elif menu.action and menu.action.type == 'ir.actions.server': # For server actions, use the action ID url = f'/web#action={menu.action.id}' else: # For menus without actions, use menu_id url = f'/web#menu_id={menu.id}' result.append({ 'id': menu.id, 'name': menu.name, 'web_icon': menu.web_icon or 'base,static/description/icon.png', 'action': menu.action.id if menu.action else False, 'url': url, 'module_name': module_name }) return request.make_json_response({ 'success': True, 'modules': result, 'debug_info': debug_info }) except Exception as e: return request.make_json_response({ 'success': False, 'error': str(e) })