Skip to content
Snippets Groups Projects
Commit 09d04d92 authored by Xavier Bonet's avatar Xavier Bonet
Browse files

Merge branch 'FIX_rest_api_swagger_issue' into 'main'

FIX rest api swagger issue

See merge request !53
parents 10b8e4c2 6da84776
No related branches found
No related tags found
1 merge request!53FIX rest api swagger issue
Pipeline #20166 passed
......@@ -7,6 +7,7 @@ from odoo.addons.component.core import Component
from odoo import _
from datetime import datetime
from . import schemas
from odoo.http import request
_logger = logging.getLogger(__name__)
......@@ -27,7 +28,8 @@ class CommunityService(Component):
auth="api_key",
)
def get(self, _odoo_company_id):
endpoint_args = self.work.request.endpoint_arguments
endpoint_args = self.work and hasattr(
self.work, 'request') and self.work.request.endpoint_arguments or None
company_id = self.env['res.company'].get_real_ce_company_id(
_odoo_company_id)
......@@ -39,14 +41,14 @@ class CommunityService(Component):
"No Odoo Company found for odoo_company_id %s") % _odoo_company_id}
)
if 'method_name' in endpoint_args and endpoint_args.get('method_name') == 'members':
if endpoint_args and 'method_name' in endpoint_args and endpoint_args.get('method_name') == 'members':
return self._to_dict_members(company_id.get_ce_members())
else:
return self._to_dict_community(company_id)
def _validator_return_community_get(self):
endpoint_args = self.work.request.endpoint_arguments
if 'method_name' in endpoint_args and endpoint_args.get('method_name') == 'members':
endpoint_args = self.work and hasattr(self.work, 'request') and self.work.request.endpoint_arguments or None
if endpoint_args and 'method_name' in endpoint_args and endpoint_args.get('method_name') == 'members':
return schemas.S_COMMUNITY_MEMBERS_RETURN_GET
else:
return schemas.S_COMMUNITY_RETURN_GET
......@@ -66,7 +68,7 @@ class CommunityService(Component):
@staticmethod
def _to_dict_community(company):
resp = {'community':{
resp = {'community': {
'id': company.id,
'name': company.name,
'birth_date': company.foundation_date and company.foundation_date.strftime('%Y-%m-%d') or '',
......@@ -88,6 +90,7 @@ class CommunityService(Component):
resp['community'].update(CommunityService._to_dict_members(
company.get_ce_members()))
resp['community'].update({'active_services': company.get_active_services()})
resp['community'].update(
{'active_services': company.get_active_services()})
return resp
......@@ -72,8 +72,8 @@ class CRMLeadService(Component):
return self._to_dict(sr)
def _validator_create(self):
source = self.work.request.params.get('source_xml_id', False)
if source == 'ce_source_creation_ce_proposal':
source = self.work and hasattr(self.work, 'request') and self.work.request.params.get('source_xml_id', False) or None
if source and source == 'ce_source_creation_ce_proposal':
return schemas.S_CRM_LEAD_CREATE_ALTA_CE
return schemas.S_CRM_LEAD_CREATE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment