Skip to content

Commit

Permalink
[MIG] muskathlon: Migration to 14.0
Browse files Browse the repository at this point in the history
WIP:
- 4M External Access
  • Loading branch information
ecino committed Feb 26, 2024
1 parent 5b2c9ff commit 1592d70
Show file tree
Hide file tree
Showing 97 changed files with 3,570 additions and 4,519 deletions.
1 change: 0 additions & 1 deletion muskathlon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
from . import models
from . import reports
from . import controllers
from . import forms
33 changes: 13 additions & 20 deletions muskathlon/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,44 @@
# pylint: disable=C8101
{
"name": "Muskathlon",
"version": "12.0.1.0.3",
"version": "14.0.1.0.0",
"category": "Reports",
"author": "Compassion CH",
"license": "AGPL-3",
"website": "http://www.compassion.ch",
"website": "https://www.compassion.ch",
"maintainers": ["ecino"],
"development_status": "Production/Stable",
"data": [
"security/ir.model.access.csv",
"security/access_rules.xml",
"data/default_sports.xml",
"data/ir_cron.xml",
"data/form_data.xml",
"data/res_users.xml",
"data/survey_muskathlon_medical_infos.xml",
"data/product.xml",
"data/event_type.xml",
"data/mail_template.xml",
"data/event_registration_stage.xml",
"data/event_type.xml",
"data/event_registration_task.xml",
"data/mail_template.xml",
"data/event_type_mail.xml",
"data/order_material_mail_template.xml",
"data/queue_job.xml",
"reports/muskathlon_view.xml",
"views/event_compassion_view.xml",
"views/partner_compassion_view.xml",
"views/recurring_contracts_view.xml",
"views/muskathlon_registrations.xml",
"views/notification_settings_view.xml",
"views/payment_transaction_view.xml",
"views/advocate_details.xml",
"templates/muskathlon_details.xml",
"templates/muskathlon_my_details.xml",
"templates/muskathlon_my_home.xml",
"templates/muskathlon_participant_details.xml",
"templates/muskathlon_page.xml",
"templates/muskathlon_registration_form.xml",
"templates/muskathlon_views.xml",
"templates/muskathlon_order_material.xml",
"templates/my_account_muskathlon.xml",
"templates/muskathlon_terms.xml",
"templates/my_tasks_forms.xml",
"templates/assets.xml",
],
"depends": [
"website_event_compassion", # compassion-switzerland
"survey_phone", # compassion-modules
"partner_compassion", # compassion-switzerland
"website_event_compassion",
],
"external_dependencies": {
"python": ["magic"],
},
"external_dependencies": {},
"demo": [],
"installable": True,
"auto_install": False,
Expand Down
265 changes: 14 additions & 251 deletions muskathlon/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,278 +6,41 @@
# The licence is in the file __manifest__.py
#
##############################################################################
import json
import urllib.error
import urllib.parse
import urllib.request
from datetime import datetime

from dateutil.relativedelta import relativedelta

from odoo.http import request, route

from odoo.addons.portal.controllers.portal import CustomerPortal
from odoo.addons.website_event_compassion.controllers.events_controller import (
EventsController,
)


class MuskathlonWebsite(EventsController, CustomerPortal):
@route(
'/event/<model("crm.event.compassion"):event>/',
auth="public",
website=True,
sitemap=EventsController.sitemap_events,
)
def event_page(self, event, **kwargs):
result = super(MuskathlonWebsite, self).event_page(event, **kwargs)
if event.website_muskathlon and result.mimetype == "application/json":
# The form is in a modal popup and should be returned in JSON
# and render in the modal (remove full_page option).
values = json.loads(result.data)
values["full_page"] = False
result.data = json.dumps(values)
return result

@route(
'/my/muskathlon/<model("event.registration"):registration>/donations',
auth="user",
website=True,
sitemap=False,
)
def my_muskathlon_details(self, registration, **kwargs):
reports = request.env["muskathlon.report"].search(
[
("user_id", "=", request.env.user.partner_id.id),
("event_id", "=", registration.compassion_event_id.id),
]
)
return request.render("muskathlon.my_details", {"reports": reports})

@route("/my/muskathlon", type="http", auth="user", website=True)
def muskathlon_my_account(self, form_id=None, **kw):
if not request.env.user.partner_id.is_muskathlon:
return request.redirect("/my/home")

""" Inject data for forms. """
values = self._prepare_portal_layout_values()

partner = values["partner"]
advocate_details_id = partner.advocate_details_id.id
registration = partner.registration_ids[:1]
form_success = False

# Load forms
kw["form_model_key"] = "cms.form.muskathlon.trip.information"
trip_info_form = self.get_form("event.registration", registration.id, **kw)
if form_id is None or form_id == trip_info_form.form_id:
trip_info_form.form_process()
form_success = trip_info_form.form_success

kw["form_model_key"] = "cms.form.advocate.details"
about_me_form = self.get_form("advocate.details", advocate_details_id, **kw)
if form_id is None or form_id == about_me_form.form_id:
about_me_form.form_process()
form_success = about_me_form.form_success

kw["form_model_key"] = "cms.form.muskathlon.passport"
passport_form = self.get_form("event.registration", registration.id, **kw)
if form_id is None or form_id == passport_form.form_id:
passport_form.form_process()
form_success = passport_form.form_success

kw["form_model_key"] = "cms.form.muskathlon.flight.details"
kw["registration_id"] = registration.id
flight_type = kw.get("flight_type")
kw["flight_type"] = "outbound"
flight = registration.flight_ids.filtered(lambda f: f.flight_type == "outbound")
outbound_flight_form = self.get_form("event.flight", flight.id, **kw)
if form_id is None or (
form_id == outbound_flight_form.form_id
and (not flight_type or flight_type == "outbound")
):
outbound_flight_form.form_process(**kw)
form_success = outbound_flight_form.form_success
kw["flight_type"] = "return"
flight = registration.flight_ids.filtered(lambda f: f.flight_type == "return")
return_flight_form = self.get_form("event.flight", flight.id, **kw)
if form_id is None or (
form_id == return_flight_form.form_id
and (not flight_type or flight_type == "return")
):
return_flight_form.form_process(**kw)
form_success = return_flight_form.form_success

kw["form_model_key"] = "cms.form.group.visit.criminal.record"
criminal_form = self.get_form("event.registration", registration.id, **kw)
if form_id is None or form_id == criminal_form.form_id:
criminal_form.form_process()
form_success = criminal_form.form_success

values.update(
class MuskathlonWebsite(EventsController):
def get_event_page_values(self, event):
result = super().get_event_page_values(event)
result.update(
{
"trip_info_form": trip_info_form,
"about_me_form": about_me_form,
"passport_form": passport_form,
"outbound_flight_form": outbound_flight_form,
"return_flight_form": return_flight_form,
"criminal_form": criminal_form,
"sport_disciplines": event.sport_discipline_ids,
}
)
values.update(kw)
if "registrations" not in values.keys():
registrations_array = []
for reg in partner.registration_ids:
registrations_array.append(reg)
values["registrations"] = registrations_array
# This fixes an issue that forms fail after first submission
if form_success:
result = request.redirect("/my/muskathlon")
else:
result = request.render("muskathlon.custom_portal_my_home", values)
return result

@route(
'/my/muskathlon/<model("event.registration"):registration>',
[
"/my/events/<model('event.registration'):registration>/fundraising",
],
auth="user",
website=True,
sitemap=False,
)
def muskathlon_order_material(self, registration, form_id=None, **kw):
# Load forms
kw["form_model_key"] = "cms.form.order.material"
kw["registration"] = registration
material_form = self.get_form("crm.lead", **kw)
if form_id is None or form_id == "order_material":
material_form.form_process()

kw["form_model_key"] = "cms.form.order.muskathlon.childpack"
childpack_form = self.get_form("crm.lead", **kw)
if form_id is None or form_id == "muskathlon_childpack":
childpack_form.form_process()

flyer = "/muskathlon/static/src/img/muskathlon_parrain_example_"
flyer += request.env.lang[:2] + ".jpg"

staff_id = (
request.env["res.config.settings"]
.get_param("muskathlon_order_notify_id")
)
values = {
"registration": registration,
"material_form": material_form,
"childpack_form": childpack_form,
"main_object": registration,
"flyer_image": flyer,
"staff_id": staff_id,
}
return request.render("muskathlon.my_muskathlon_order_material", values)

@route(
"/muskathlon_registration/" "<int:registration_id>/success",
type="http",
auth="public",
website=True,
sitemap=False,
)
def muskathlon_registration_successful(self, registration_id, **kwargs):
limit_date = datetime.now() - relativedelta(days=1)
registration = request.env["event.registration"].sudo().browse(registration_id)
if not registration.exists() or registration.create_date < limit_date:
return request.redirect("/events")

values = {
"registration": registration,
"event": registration.compassion_event_id,
}
return request.render("muskathlon.new_registration_successful_modal", values)

def get_event_page_values(self, event, **kwargs):
"""
Gets the values used by the website to render the event page.
:param event: crm.event.compassion record to render
:param kwargs: request arguments
:return: dict: values for the event website template
(must contain event, start_date, end_date, form,
main_object and website_template values)
"""
if event.website_muskathlon:
kwargs["form_model_key"] = "cms.form.event.registration.muskathlon"
values = super(MuskathlonWebsite, self).get_event_page_values(event, **kwargs)
if event.website_muskathlon:
values.update(
{
"disciplines": event.sport_discipline_ids.ids,
"website_template": "muskathlon.details",
}
)
return values

def get_participant_page_values(self, event, registration, **kwargs):
"""
Gets the values used by the website to render the participant page.
:param event: crm.event.compassion record to render
:param registration: event.registration record to render
:param kwargs: request arguments
:return: dict: values for the event website template
(must contain event, start_date, end_date, form,
main_object and website_template values)
"""
values = super(MuskathlonWebsite, self).get_participant_page_values(
event, registration, **kwargs
)
if event.website_muskathlon:
values["website_template"] = "muskathlon.participant_details"
return values

def get_donation_success_template(self, event):
if event.website_muskathlon:
return "muskathlon.donation_successful"
return super(MuskathlonWebsite, self).get_donation_success_template(event)

def _prepare_portal_layout_values(self):
values = super(MuskathlonWebsite, self)._prepare_portal_layout_values()
if "user" in values:
partner = values["user"].partner_id
else:
partner = request.env.user.partner_id

registrations = (
request.env["event.registration"]
.sudo()
.search([("partner_id", "=", partner.id)])
)
surveys = request.env["survey.user_input"].search(
[
(
"survey_id",
"in",
registrations.mapped("event_id.medical_survey_id").ids,
),
("partner_id", "=", partner.id),
]
)
surveys_not_started = (
surveys.filtered(lambda r: r.state == "new") if surveys else False
)
survey_not_started = surveys_not_started[0] if surveys_not_started else False
surveys_done = (
surveys.filtered(lambda r: r.state == "done") if surveys else False
)
survey_already_filled = surveys_done[0] if surveys_done else False

child_protection_charter = {
"has_agreed": partner.has_agreed_child_protection_charter,
"url": "/partner/%s/child-protection-charter?redirect=%s"
% (partner.uuid, urllib.parse.quote("/my/home", safe="")),
}

if registrations and partner.advocate_details_id:
values["registrations"] = registrations
elif registrations:
values["muskathlete_without_advocate_details"] = True

values.update(
{
"partner": partner,
"survey_url": request.env.ref("muskathlon.muskathlon_form").public_url,
"survey_not_started": survey_not_started,
"survey_already_filled": survey_already_filled,
"child_protection_charter": child_protection_charter,
}
)
return values
16 changes: 8 additions & 8 deletions muskathlon/data/event_registration_stage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<odoo>
<data noupdate="1">
<!-- Specific stages for Muskathlon -->
<record id="stage_unconfirmed" model="event.registration.stage">
<field name="name">Unconfirmed</field>
<field name="sequence">0</field>
<field name="fold" eval="False"/>
<field name="registration_state">draft</field>
</record>
<record id="stage_fill_profile" model="event.registration.stage">
<field name="name">Fill profile</field>
<field name="name">In Preparation</field>
<field name="sequence">2</field>
<field name="duration">30</field>
<field name="requirements">
* Activate account
* Fill urgency contact and passport information
* Upload large picture
* Complete medical survey
</field>
<field name="event_type_ids" eval="[(6, 0, [ref('event_type_muskathlon')])]"/>
<field name="registration_state">open</field>
</record>
</data>
</odoo>
Loading

0 comments on commit 1592d70

Please sign in to comment.