I am trying to access and display data from one of my custom modules via the Odoo api But this error appears: Access to fetch at 'https://xx-xx.xx.xxx/api/get_project' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource . If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. Even though I have already made the headers
I use Odoo 17
this my code:
@http.route('/api/get_project', type='http', auth='public', method=['GET'], crsf=False, cors="*") def get_custom_projects(self, **kwargs): custom_projects = request.env['custom.project'].search([]) data = [] for project in custom_projects: project_data = { 'id': project.id, 'name': project.project.name, 'description': project.description, 'project_manager': project.project_manager.name if project.project_manager else None, 'customer': project.customer.name if project.customer else None, 'project_stage': project.project_stage, 'employees': [{'id': emp.id, 'name': emp.name} for emp in project.employee_ids], 'tasks': [{'id': task.id, 'name': task.name} for task in project.task_ids], } data.append(project_data)
headers = { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', # Ganti '*' dengan domain yang diizinkan jika perlu } return request.make_response(json.dumps(data), headers=[('Content-Type', 'application/json')])