Skip to content

Commit

Permalink
[WIP] T0485 [MIG] website_compassion: rewrite registration process
Browse files Browse the repository at this point in the history
- Use Odoo traditional signup process but inject partner search
  capability given a reference (child or sponsor)
  • Loading branch information
ecino committed Sep 7, 2023
1 parent 37c300b commit e339a07
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 8 deletions.
16 changes: 9 additions & 7 deletions my_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,22 @@
"data": [
"security/access_rules.xml",
"security/ir.model.access.csv",
"template/my_account_components.xml",
"template/my_account_personal_info.xml",
"template/my_account_donations.xml",
"template/my_account_my_children.xml",
"template/my_account_write_a_letter.xml",
"template/my_account_contact_us.xml",
"template/login_template.xml",
"templates/my_account_components.xml",
"templates/my_account_personal_info.xml",
"templates/my_account_donations.xml",
"templates/my_account_my_children.xml",
"templates/my_account_write_a_letter.xml",
"templates/my_account_contact_us.xml",
"templates/login_template.xml",
"templates/signup.xml",
"views/correspondence_template_view.xml",
"views/partner_compassion_view.xml",
],
"depends": [
"child_protection",
"partner_communication_compassion",
"website_form",
"auth_signup",
],
"demo": [],
"installable": True,
Expand Down
1 change: 1 addition & 0 deletions my_compassion/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
##############################################################################

from . import my_account
from . import auth_signup
49 changes: 49 additions & 0 deletions my_compassion/controllers/auth_signup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
##############################################################################
#
# Copyright (C) 2023 Compassion CH (http://www.compassion.ch)
# @author: Emanuel Cino <ecino@compassion.ch>
#
# The licence is in the file __manifest__.py
#
##############################################################################

from odoo import _
from odoo.http import request
from odoo.addons.auth_signup.controllers.main import AuthSignupHome


class RegistrationController(AuthSignupHome):
def do_signup(self, qcontext):
"""
Check if a sponsor ref was given in order to try to match
an existing sponsor.
"""
sponsor_ref = qcontext.get("sponsor_ref")
if sponsor_ref:
sponsor = request.env["res.partner"].sudo().search(
[("ref", "=", sponsor_ref)], limit=1
)
if not sponsor:
# Try to find based on a child reference, either global or local
child = request.env["compassion.child"].sudo().search(
[
("state", "=", "P"),
"|",
("global_id", "=", sponsor_ref),
("local_id", "=", sponsor_ref),
], limit=1
)
sponsor = child.sponsor_id
if sponsor:
if sponsor.email.lower() != qcontext["login"].lower():
qcontext["error"] = _(
"The email address you entered is not the same "
"as the one in the system. Please try again."
)
return super().do_signup(qcontext)
# Prepare token for signup
sponsor.signup_prepare()
qcontext["token"] = sponsor.signup_token
else:
qcontext["error"] = _("No sponsor found with this reference")
return super().do_signup(qcontext)
File renamed without changes.
13 changes: 13 additions & 0 deletions my_compassion/templates/signup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<template id="signup_sponsor" inherit_id="auth_signup.fields">
<xpath expr="//div[@class='form-group field-name']" position="after">
<div class="form-group field-name">
<label for="sponsor_ref">Your sponsor or child reference</label>
<input t-att-type="'hidden' if only_passwords else 'text'" name="sponsor_ref" id="sponsor_ref" class="form-control form-control-sm" placeholder="Put any known reference here for matching with your account..."/>
</div>
</xpath>
</template>

</odoo>
2 changes: 1 addition & 1 deletion my_compassion_segmentation/controllers/my_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ def account(self, redirect=None, **post):
survey = request.env.ref(
"partner_segmentation.partner_segmentation_survey"
).sudo()
return request.redirect(urlparse(survey.public_url).path)
return request.redirect(urlparse(survey.session_link).path)
else:
return super().account(redirect, **post)

0 comments on commit e339a07

Please sign in to comment.