Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0] [MIG] tg_event_guest #41

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions tg_event_guest/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
============
Event guests
============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:fc7a7eef77a1909fe77e3bb8cd041eedadb7eb2b7ee189bf08b1e902481bc4ea
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-it--projects--llc%2Ftg--addons-lightgray.png?logo=github
:target: https://github.com/it-projects-llc/tg-addons/tree/17.0/tg_event_guest
:alt: it-projects-llc/tg-addons

|badge1| |badge2| |badge3|

Module for inviting guests to event

**Table of contents**

.. contents::
:local:

Usage
=====

Preparing guest
---------------

- Go to main menu -> Events -> Guests
- Create record with following mandatory fields set:

- Name
- Email
- Event
- Event ticket

- Save
- Run Actions -> Send mail
- In "Send mail" wizard leave everything default
- Send
- RESULT: email with invitation link is sent
- RESULT: invitation link is the same as in guest form

Guest registering
-----------------

- Copy "Invitation link" from event guest form or from invitiation
email as actual guest
- Open that link in browser as logged out user (probably in
Incognito/Private mode)
- Register and set password
- RESULT: you will be redirected to contact details portal page
- Fill in all required fields and press "Confirm"
- RESULT: new registration created. Event and event ticket are used
guest form, that is filled in "Preparing guest" section

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/it-projects-llc/tg-addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/it-projects-llc/tg-addons/issues/new?body=module:%20tg_event_guest%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* IT-Projects LLC

Contributors
------------

- Eugene Molotov (https://github.com/em230418)

Maintainers
-----------

This module is part of the `it-projects-llc/tg-addons <https://github.com/it-projects-llc/tg-addons/tree/17.0/tg_event_guest>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions tg_event_guest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from . import controllers
from . import wizard
19 changes: 19 additions & 0 deletions tg_event_guest/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": """Event guests""",
"version": "17.0.0.2.0",
"author": "IT-Projects LLC",
"support": "[email protected]",
"website": "https://github.com/it-projects-llc/tg-addons",
"license": "LGPL-3",
"depends": [
"auth_signup",
"event_sale",
"portal",
],
"data": [
"security/ir.model.access.csv",
"data/mail_template_data.xml",
"views/event_guest_views.xml",
"views/portal_templates.xml",
],
}
2 changes: 2 additions & 0 deletions tg_event_guest/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import portal
from . import main
34 changes: 34 additions & 0 deletions tg_event_guest/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from odoo import _
from odoo.http import request

from odoo.addons.auth_signup.controllers.main import (
AuthSignupHome as BaseAuthSignupHome,
)


class AuthSignupHome(BaseAuthSignupHome):
def get_auth_signup_qcontext(self):
qcontext = super().get_auth_signup_qcontext()
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 ""
if request.session.uid:
qcontext["error"] = _("You need to logout to register guest")

return qcontext

def _prepare_signup_values(self, qcontext):
values = super()._prepare_signup_values(qcontext)
if qcontext.get("guest_register_code"):
values["guest_register_code"] = qcontext["guest_register_code"]
return values
63 changes: 63 additions & 0 deletions tg_event_guest/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from odoo.http import request, route

from odoo.addons.portal.controllers.portal import CustomerPortal as BaseCustomerPortal


class CustomerPortal(BaseCustomerPortal):
@route()
def home(self, **kw):
guest = request.env.user.event_guest
if guest and not guest.result_attendee:
return request.redirect("/my/account")
return super().home(**kw)

@route()
def account(self, redirect=None, **post):
if not request.httprequest.method == "POST":
if post.get("guest_register_code"):
guest = request.env["event.guest"]._get_by_code(
post["guest_register_code"]
)
if guest.guest_partner == request.env.user.partner_id:
guest.result_partner = request.env.user.partner_id

res = super().account(redirect, **post)

if not request.httprequest.method == "POST":
# we are handling only POST requests here
return res

if res.status_code == 200:
# some fields are not correct
return res

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

if not guest:
return res

if not guest.result_attendee:
Attendee = request.env["event.registration"].sudo()
vals = {
"name": partner.name,
"event_id": guest.event.id,
"event_ticket_id": guest.event_ticket.id,
"partner_id": partner.id,
}

# additional field from partner_event
if "attendee_partner_id" in Attendee._fields:
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({})
)
compose.action_send_mail()
guest.result_attendee = attendee

return res
29 changes: 29 additions & 0 deletions tg_event_guest/data/mail_template_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="email_template_partner" model="mail.template">
<field name="name">Guest Mass Mail</field>
<field name="model_id" ref="model_event_guest" />
<field name="email_to">{{ object.email }}</field>
<field name="subject">Invitation to {{ object.event.name }}</field>
<field name="auto_delete" eval="True" />
<field name="body_html" type="html">
<p>Hello, <t t-out="object.name or ''">object name</t>!</p>
<br />
<p>
Please complete your registration to <t
t-out="object.event.display_name or ''"
>event display_name</t> using the
<a t-attf-href="{{ object.invite_url }}" href="">link</a>
</p>
<p>Thank you!</p>
<br />
<p>You are receiving this email because <t
t-out="object.invited_by.name or ''"
>invited_by name</t> has invited you to <t
t-out="object.event.display_name or ''"
>event display_name</t>. Please, let us know if you believe this email has been sent to you by mistake.</p>
<br />
<p>Tribal Gathering Crew</p>
</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions tg_event_guest/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import event_guest
from . import res_users
92 changes: 92 additions & 0 deletions tg_event_guest/models/event_guest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from random import choice as random_choice
from string import ascii_lowercase, digits
from urllib.parse import urljoin

from odoo import api, fields, models


class EventGuest(models.Model):
_name = "event.guest"
_inherit = "mail.thread"
_description = "Event Guest"
_order = "id DESC"

@api.model
def _default_code(self):
return "".join([random_choice(ascii_lowercase + digits) for i in range(8)])

name = fields.Char(required=True)
email = fields.Char(required=True)
event = fields.Many2one(
"event.event", required=True, domain="[('stage_id.pipe_end', '=', False)]"
)
guest_partner = fields.Many2one(
"res.partner", compute="_compute_guest_partner", store=True
)

event_ticket = fields.Many2one(
"event.event.ticket",
required=True,
domain="[('event_id', '=', event), ('price', '=', 0)]",
)
code = fields.Char(
index=True, required=True, default=lambda self: self._default_code()
)

invite_url = fields.Char("Invite URL", compute="_compute_invite_url", store=False)
invited_by = fields.Many2one("res.partner", readonly=True)
guest_of = fields.Many2one("res.partner")

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

_sql_constraints = [
(
"code_unique",
"unique(code)",
"Code must be unique",
),
]

@api.model
def _get_by_code(self, code):
return self.sudo().search(
[
("code", "=", code),
],
limit=1,
)

@api.depends("email")
def _compute_guest_partner(self):
with_email = self.filtered("email")
for record in self:
record.guest_partner = self.env["res.partner"].search(
[
("email", "=", record.email),
],
limit=1,
)

(self - with_email).write(
{
"guest_partner": False,
}
)

@api.depends("code", "event", "guest_partner")
def _compute_invite_url(self):
for guest in self:
if guest.event:
if guest.guest_partner:
path = f"/my/account?guest_register_code={guest.code}"
else:
path = f"/web/signup?guest_register_code={guest.code}&redirect=%2Fmy%2Faccount" # noqa: B950 E501

guest.invite_url = urljoin(guest.event.get_base_url(), path)
else:
guest.invite_url = False
34 changes: 34 additions & 0 deletions tg_event_guest/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from odoo import api, fields, models


class ResUsers(models.Model):
_inherit = "res.users"

event_guest = fields.Many2one("event.guest", compute="_compute_event_guest")

def _compute_event_guest(self):
event_guests = self.env["event.guest"].search(
[
("result_partner", "in", self.mapped("partner_id").ids),
]
)
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)

@api.model
def signup(self, values, token=None):
guest_register_code = values.pop("guest_register_code", False)
res = super().signup(values, token)
if guest_register_code:
guest = self.env["event.guest"]._get_by_code(guest_register_code)
if guest and not guest.result_partner:
user = self.search(
[
("login", "=", res[0]),
],
limit=1,
)
guest.result_partner = user.partner_id

return res
3 changes: 3 additions & 0 deletions tg_event_guest/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions tg_event_guest/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Eugene Molotov (https://github.com/em230418)
1 change: 1 addition & 0 deletions tg_event_guest/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Module for inviting guests to event
Loading
Loading