Skip to content

Commit

Permalink
event guest
Browse files Browse the repository at this point in the history
  • Loading branch information
em230418 committed Feb 28, 2024
1 parent a63e64c commit 596651c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
15 changes: 9 additions & 6 deletions tg_event_guest/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
class AuthSignupHome(BaseAuthSignupHome):
def get_auth_signup_qcontext(self):
qcontext = super(AuthSignupHome, self).get_auth_signup_qcontext()
if request.params.get("guest_register_code"):
guest = request.env["event.guest"]._get_by_code(
request.params.get("guest_register_code")
)
if not qcontext.get("guest_register_code") and request.params.get(
"guest_register_code"
):
qcontext["guest_register_code"] = request.params.get("guest_register_code")

guest_register_code = qcontext.get("guest_register_code")
if guest_register_code:
guest = request.env["event.guest"]._get_by_code(guest_register_code)
if guest:
if not qcontext.get("name"):
qcontext["name"] = guest.name or ""
if not qcontext.get("login"):
qcontext["login"] = guest.email or ""
qcontext["guest_register_code"] = request.params.get("guest_register_code")

return qcontext

Expand All @@ -26,7 +29,7 @@ def _signup_with_values(self, token, values):
guest = None
if (
bool(request)
and request.session.uid
and not (request.session.uid)
and qcontext.get("guest_register_code")
):
guest = request.env["event.guest"]._get_by_code(
Expand Down
8 changes: 7 additions & 1 deletion tg_event_guest/controllers/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ class CustomerPortal(BaseCustomerPortal):
def account(self, redirect=None, **post):
res = super(CustomerPortal, self).account(redirect, **post)

if not request.httprequest.method == "POST":
return res

partner = request.env.user.partner_id
guest = request.env.user.event_guest

if not guest:
return res

if not guest.result_attendee:
if not guest.result_attendee and guest.result_partner.passport:
Attendee = request.env["event.registration"].sudo()
vals = {
"name": partner.name,
"event_id": guest.event.id,
"partner_id": partner.id,
}
Expand All @@ -26,6 +30,8 @@ def account(self, redirect=None, **post):
vals["attendee_partner_id"] = partner.id

attendee = Attendee.create(vals)
attendee.action_confirm()

ctx = attendee.action_send_badge_email()["context"]
compose = (
attendee.env["mail.compose.message"].with_context(**ctx).create({})
Expand Down
8 changes: 6 additions & 2 deletions tg_event_guest/models/event_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ def _default_code(self):
)

invited_by = fields.Many2one("res.partner", readonly=True)
result_partner = fields.Many2one("res.partner", readonly=True)
result_attendee = fields.Many2one("event.registration", readonly=True)
result_partner = fields.Many2one(
"res.partner", string="Related partner", readonly=True
)
result_attendee = fields.Many2one(
"event.registration", string="Related attendee", readonly=True
)

_sql_constraints = [
(
Expand Down
2 changes: 1 addition & 1 deletion tg_event_guest/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def _compute_event_guest(self):
("result_partner", "in", self.mapped("partner_id").ids),
]
)
d = {x.partner_id.id: x.id for x in event_guests}
d = {x.result_partner.id: x.id for x in event_guests}
for user in self:
user.event_guest = d.get(user.partner_id.id, False)
11 changes: 11 additions & 0 deletions tg_event_guest/views/portal_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@
/>
</xpath>
</template>

<template id="signup" inherit_id="auth_signup.signup">
<xpath expr="//input[@name='csrf_token']" position="after">
<input
type="hidden"
name="guest_register_code"
t-if="guest_register_code"
t-att-value="guest_register_code"
/>
</xpath>
</template>
</odoo>

0 comments on commit 596651c

Please sign in to comment.