Skip to content
Snippets Groups Projects
Commit d924e217 authored by Dani Quilez's avatar Dani Quilez
Browse files

Merge branch 'feature/cd-api-landing' into 'dev'

Feature/cd api landing

See merge request !123
parents 04d87d8f 7d072c0c
No related branches found
No related tags found
4 merge requests!138Hotfix setup name error,!134Release v14.0.1.1.6,!129Draft: Release v14.0.1.1.5,!123Feature/cd api landing
Pipeline #30035 passed
This commit is part of merge request !134. Comments created here will be created in the context of that merge request.
......@@ -77,5 +77,3 @@
'auto_install': False,
'post_init_hook': 'post_init_hook',
}
......@@ -77,7 +77,8 @@ class LandingPage(models.Model):
token = "Bearer %s" % auth["token"]
landing_page_data = record.to_dict()
landing_page_data["status"] = new_status
landing_page_resource = LandingPageResource(record.wp_landing_page_id)
landing_page_resource = LandingPageResource(
record.wp_landing_page_id)
landing_page_resource.update(token, landing_page_data)
record.write({"status": new_status})
......@@ -29,15 +29,18 @@ class ResCompany(models.Model):
if rec.hierarchy_level == 'instance':
rec.parent_id_filtered_ids = False
elif rec.hierarchy_level == 'coordinator':
rec.parent_id_filtered_ids = self.search([('hierarchy_level', '=', 'instance')])
rec.parent_id_filtered_ids = self.search(
[('hierarchy_level', '=', 'instance')])
elif rec.hierarchy_level == 'community':
rec.parent_id_filtered_ids = self.search([('hierarchy_level', '=', 'coordinator')])
rec.parent_id_filtered_ids = self.search(
[('hierarchy_level', '=', 'coordinator')])
hierarchy_level = fields.Selection(selection=_HIERARCHY_LEVEL_VALUES, required=True, string="Hierarchy level",
default='community')
parent_id_filtered_ids = fields.One2many('res.company', compute=_compute_parent_id_filtered_ids, readonly=True,
store=False)
ce_tag_ids = fields.Many2many('crm.tag', string='Energy Community Services')
ce_tag_ids = fields.Many2many(
'crm.tag', string='Energy Community Services')
cooperator_journal = fields.Many2one(
"account.journal",
string="Cooperator Journal",
......@@ -72,26 +75,34 @@ class ResCompany(models.Model):
for rec in self:
if rec.hierarchy_level == 'instance':
if self.search_count([('hierarchy_level', '=', 'instance'), ('id', '!=', rec.id)]):
raise ValidationError(_('An instance company already exists'))
raise ValidationError(
_('An instance company already exists'))
if rec.parent_id:
raise ValidationError(_('You cannot create a instance company with a parent company.'))
raise ValidationError(
_('You cannot create a instance company with a parent company.'))
if rec.hierarchy_level == 'coordinator' and rec.parent_id.hierarchy_level != 'instance':
raise ValidationError(_('Parent company must be instance hierarchy level.'))
raise ValidationError(
_('Parent company must be instance hierarchy level.'))
if rec.hierarchy_level == 'community' and rec.parent_id.hierarchy_level != 'coordinator':
raise ValidationError(_('Parent company must be coordinator hierarchy level.'))
raise ValidationError(
_('Parent company must be coordinator hierarchy level.'))
@api.constrains('hierarchy_level', 'parent_id')
def _check_hierarchy_level(self):
for rec in self:
if rec.hierarchy_level == 'instance':
if self.search_count([('hierarchy_level', '=', 'instance'), ('id', '!=', rec.id)]):
raise ValidationError(_('An instance company already exists'))
raise ValidationError(
_('An instance company already exists'))
if rec.parent_id:
raise ValidationError(_('You cannot create a instance company with a parent company.'))
raise ValidationError(
_('You cannot create a instance company with a parent company.'))
if rec.hierarchy_level == 'coordinator' and rec.parent_id.hierarchy_level != 'instance':
raise ValidationError(_('Parent company must be instance hierarchy level.'))
raise ValidationError(
_('Parent company must be instance hierarchy level.'))
if rec.hierarchy_level == 'community' and rec.parent_id.hierarchy_level != 'coordinator':
raise ValidationError(_('Parent company must be coordinator hierarchy level.'))
raise ValidationError(
_('Parent company must be coordinator hierarchy level.'))
@api.model
def get_real_ce_company_id(self, api_param_odoo_compant_id):
......@@ -122,7 +133,8 @@ class ResCompany(models.Model):
("active", "=", True),
]
}
members = self.env["res.users"].sudo().search(domains_dict["in_kc_and_active"])
members = self.env["res.users"].sudo().search(
domains_dict["in_kc_and_active"])
return members
@api.model
......@@ -180,7 +192,8 @@ class ResCompany(models.Model):
return "https://somcomunitats.coop/ce/comunitat-energetica-prova/"
def get_keycloak_odoo_login_url(self):
login_provider_id = self.env.ref("energy_communities.keycloak_login_provider")
login_provider_id = self.env.ref(
"energy_communities.keycloak_login_provider")
return login_provider_id.get_auth_link()
def create_landing(self):
......
from . import schemas
from . import ce_landing_service
from . import ce_member_service
from . import crm_lead_service
from . import ce_member_profile_service
from . import ce_community_service
import logging
from odoo.addons.base_rest import restapi
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__)
class LandingService(Component):
_inherit = 'base.rest.service'
_name = "ce.landing.services"
_collection = "ce.services"
_inherit = "base.rest.private_abstract_service"
_name = "ce.landing.service"
_usage = "landing"
_description = """
CE WP landing page requests
"""
@restapi.method(
[(["/<int:odoo_landing_page_id>"], "GET")],
output_param=restapi.CerberusValidator("_validator_create"),
auth="api_key",
)
def get(self, _odoo_landing_page_id):
landing_page = self.env['landing.page'].browse(_odoo_landing_page_id)
def get(self, _id):
landing_page = self.env['landing.page'].browse(_id)
return self._to_dict(landing_page)
@staticmethod
def _to_dict(landing_page):
# TODO: move this method to model method?
# return landing.to_dict()
return {
"landing": {
"id": landing_page.id,
......@@ -58,5 +51,8 @@ class LandingService(Component):
}
}
def _validator_create(self):
def _validator_get(self):
return {}
def _validator_return_get(self):
return schemas.S_LANDING_PAGE_CREATE
......@@ -2,10 +2,12 @@ def boolean_validator(field, value, error):
if value and value not in ["true", "false"]:
error(field, "Must be a boolean value: true or false")
def ce_state_validator(field, value, error):
if value and value not in ["active", "on_building"]:
error(field, "Must be 'active' or 'on_building'")
S_CRM_LEAD_RETURN_CREATE = {
"id": {"type": "integer"},
}
......@@ -36,7 +38,8 @@ S_CRM_LEAD_CREATE_ALTA_CE = {
"partner_city": {"type": "string", "required": True},
"partner_state": {"type": "string", "required": True},
"partner_qty_members": {"type": "integer", "required": True},
"partner_legal_state": {"type": "string",
"partner_legal_state": {
"type": "string",
"check_with": ce_state_validator
},
"tag_ids": {
......@@ -59,7 +62,7 @@ S_CRM_LEAD_CREATE_ALTA_CE = {
"contact2_mobile": {"type": "string"},
"odoo_company_id": {"type": "integer", "required": True},
"source_xml_id": {"type": "string", "required": True},
"partner_map_place_form_url":{"type": "string", "required": False},
"partner_map_place_form_url": {"type": "string", "required": False},
"partner_language": {"type": "string"},
}
......@@ -107,7 +110,7 @@ S_PROFILE_RETURN_GET = {
"communities": {
"type": "list",
"schema": S_PROFILE_COMMUNITY_GET
},
},
"suscriptions": {
"type": "dict",
"schema": {
......@@ -169,38 +172,38 @@ S_COMMUNITY_SERVICE = {
}
S_COMMUNITY_RETURN_GET = {
"community": {
"community": {
"type": "dict",
"schema": {
"id": {"type": "integer"},
"name": {"type": "string"},
"birth_date": {"type": "string"},
"members": {
"type": "list",
"schema": {
"type": "dict",
"schema": S_COMMUNITY_MEMBER
}
},
"contact_info": {
"type": "dict",
"schema": {
"street": {"type": "string"},
"postal_code": {"type": "string"},
"city": {"type": "string"},
"state": {"type": "string"},
"country": {"type": "string"},
"phone": {"type": "string"},
"email": {"type": "string"},
"telegram": {"type": "string"},
"id": {"type": "integer"},
"name": {"type": "string"},
"birth_date": {"type": "string"},
"members": {
"type": "list",
"schema": {
"type": "dict",
"schema": S_COMMUNITY_MEMBER
}
},
"contact_info": {
"type": "dict",
"schema": {
"street": {"type": "string"},
"postal_code": {"type": "string"},
"city": {"type": "string"},
"state": {"type": "string"},
"country": {"type": "string"},
"phone": {"type": "string"},
"email": {"type": "string"},
"telegram": {"type": "string"},
},
},
"active_services": {
"type": "list",
"schema": {
"type": "dict",
"schema": S_COMMUNITY_SERVICE
},
"type": "list",
"schema": {
"type": "dict",
"schema": S_COMMUNITY_SERVICE
},
},
"allow_new_members": {"type": "boolean"},
"public_web_landing_url": {"type": "string"},
......@@ -246,3 +249,6 @@ S_LANDING_PAGE_CREATE = {
}
}
}
S_LANDING_PAGE_GET = {
"landing_id": {"type": "integer", "required": True, "empty": False}
}
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