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

Mail on canceled registration #13

Open
wants to merge 4 commits into
base: 17.0
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions event_elearning/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
""",
'depends': ['event','website_slides'],
'data': [
'data/event_cancled_obligatory_mail_templet.xml',
'data/event_reminder_mail_templet.xml',
'data/event_subscription_mail_templet.xml',
'views/event_event.xml',
Expand Down
358 changes: 358 additions & 0 deletions event_elearning/data/event_cancled_obligatory_mail_templet.xml

Large diffs are not rendered by default.

20 changes: 5 additions & 15 deletions event_elearning/data/event_reminder_mail_templet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@
<odoo>
<data>
<record id="event_elearning.event_reminder_with_slide_link" model="mail.template">
<field name="name">
Event: Reminder With Course Link
</field>
<field name="name">Event: Reminder With Course Link</field>
<field name="model_id" ref="event.model_event_registration" />
<field name="subject">
{{ object.event_id.name }}: {{ object.get_date_range_str() }}
</field>
<field name="email_from">
{{ (object.event_id.organizer_id.email_formatted or object.event_id.user_id.email_formatted or '') }}
</field>
<field name="email_to">
{{ (object.email and '"%s" &lt;%s&gt;' % (object.name, object.email) or object.partner_id.email_formatted or '') }}
</field>
<field name="description">
Sent automatically to attendees if there is a reminder defined on the event
</field>
<field name="subject">{{ object.event_id.name }}: {{ object.get_date_range_str() }}</field>
<field name="email_from">{{ (object.event_id.organizer_id.email_formatted or object.event_id.user_id.email_formatted or '') }}</field>
<field name="email_to">{{ (object.email and '"%s" &lt;%s&gt;' % (object.name, object.email) or object.partner_id.email_formatted or '') }}</field>
<field name="description">Sent automatically to attendees if there is a reminder defined on the event</field>
<field name="body_html" type="html">
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;">
<tr>
Expand Down
42 changes: 17 additions & 25 deletions event_elearning/data/event_subscription_mail_templet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@
<odoo>
<data>
<record id="event_subscription_with_slide_link" model="mail.template">
<field name="name">
Event: Registration Confirmation With Course Link
</field>
<field name="name">Event: Registration Confirmation With Course Link</field>
<field name="model_id" ref="event.model_event_registration" />
<field name="subject">
Your registration at {{ object.event_id.name }}
</field>
<field name="email_from">
{{ (object.event_id.organizer_id.email_formatted or object.event_id.user_id.email_formatted or '') }}
</field>
<field name="email_to">
{{ (object.email and '"%s" &lt;%s&gt;' % (object.name, object.email) or object.partner_id.email_formatted or '') }}
</field>
<field name="description">
Sent to attendees after registering to an event
</field>
<field name="subject">Your registration at {{ object.event_id.name }}</field>
<field name="email_from">{{ (object.event_id.organizer_id.email_formatted or object.event_id.user_id.email_formatted or '') }}</field>
<field name="email_to">{{ (object.email and '"%s" &lt;%s&gt;' % (object.name, object.email) or object.partner_id.email_formatted or '') }}</field>
<field name="description">Sent to attendees after registering to an event</field>
<field name="body_html" type="html">
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;">
<tr>
Expand Down Expand Up @@ -76,7 +66,8 @@
<td valign="top" style="font-size: 14px;">
<div>
Hello
<t t-out="object.name or 'Guest'" />,
<t t-out="object.name or 'Guest'" />
,
<br />
We are happy to confirm your registration to the event.
<t t-if="is_online">
Expand All @@ -89,20 +80,21 @@
OpenWood Collection Online Reveal.
</strong>
</t>
<br/>
<br />
<t t-if="object.partner_id and object.partner_id.name and object.partner_id.name != object.name">
This ticket was registered by
<t t-out="object.partner_id.name"/>.
<t t-out="object.partner_id.name" />
.
</t>
<br/>
<br/>
<t t-if="object.slide_channel_partner_id and object.slide_channel_partner_id.invitation_link">
<br />
<br />
<t t-if="object.slide_channel_partner_id and object.slide_channel_partner_id.invitation_link">
Please click this link to be taken to your registered course.
<br/>
<a t-att-href="object.slide_channel_partner_id.invitation_link">
<t t-out="object.slide_channel_partner_id.invitation_link"/>
<br />
<a t-att-href="object.slide_channel_partner_id.invitation_link">
<t t-out="object.slide_channel_partner_id.invitation_link" />
</a>
</t>
</t>
</div>
<div t-if="is_sale">
<br />
Expand Down
2 changes: 2 additions & 0 deletions event_elearning/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from . import event_event
from . import event_type
from . import event_type_mail
from . import event_mail
from . import event_registration
from . import slide_channel
from . import slide_channel_partner
2 changes: 1 addition & 1 deletion event_elearning/models/event_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EventEvent(models.Model):
@api.depends('event_type_id')
def _compute_slide_channel(self):
for event in self:
if event.event_type_id.slide_channel_id:
if event.event_type_id and event.event_type_id.slide_channel_id:
event.slide_channel_id = event.event_type_id.slide_channel_id


87 changes: 87 additions & 0 deletions event_elearning/models/event_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import logging
from odoo import models, fields, api
from dateutil.relativedelta import relativedelta

_logger = logging.getLogger(__name__)

_INTERVALS = {
'hours': lambda interval: relativedelta(hours=interval),
'days': lambda interval: relativedelta(days=interval),
'weeks': lambda interval: relativedelta(days=7*interval),
'months': lambda interval: relativedelta(months=interval),
'now': lambda interval: relativedelta(hours=0),
}

class EventMailScheduler(models.Model):

_inherit = "event.mail"

interval_type = fields.Selection(
selection_add=[('after_cancel','If the registration is cancelled')],
ondelete={'after_cancel': 'set default'})


@api.depends('event_id.date_begin', 'event_id.date_end', 'interval_type', 'interval_unit', 'interval_nbr')
def _compute_scheduled_date(self):

res = super()._compute_scheduled_date()

for scheduler in self:
if scheduler.interval_type == 'after_cancel':
date, sign = scheduler.event_id.create_date, 1

scheduler.scheduled_date = date.replace(microsecond=0) + _INTERVALS[scheduler.interval_unit](sign * scheduler.interval_nbr) if date else False

return res


@api.depends('interval_type', 'scheduled_date', 'mail_done')
def _compute_mail_state(self):

res = super()._compute_mail_state()

for scheduler in self:
# registrations based
if scheduler.interval_type == 'after_cancel':
scheduler.mail_state = 'running'

return res


def _filter_schedulers(self,scheduler):

if scheduler.interval_type == 'after_cancel':

return scheduler


def execute(self):

for scheduler in self:

if scheduler.interval_type == 'after_cancel':

_logger.error(100*"cancel mail!!!!")

for mail_registration in scheduler.mail_registration_ids:

registration = mail_registration.registration_id

if mail_registration.mail_sent == False:

if registration.hr_employee_manager_id:

self.env['mail.template'].browse(scheduler.template_ref.id).send_mail(registration.id, force_send=True)

mail_registration.mail_sent = True

all_mail_done = all(mail_registration.mail_sent == True for mail_registration in scheduler.mail_registration_ids)
total_sent = len(scheduler.mail_registration_ids.filtered(lambda reg: reg.mail_sent))

scheduler.update({
'mail_done': all_mail_done,
'mail_count_done': total_sent
})

schedulers = scheduler.filtered(lambda s: s.interval_type != 'after_cancel')
return super(EventMailScheduler, schedulers).execute()
55 changes: 54 additions & 1 deletion event_elearning/models/event_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,60 @@ class EventRegistration(models.Model):
string="Event Registration", comodel_name="slide.channel.partner",
)

hr_employee_manager_id = fields.Many2one(
string="Employee", comodel_name="hr.employee", compute='_compute_hr_employee_manager_id', readonly=False, store=True)

@api.depends('hr_employee_manager_id')
def _compute_hr_employee_manager_id(self):

for registration in self:

registration.hr_employee_manager_id = False

hr_employee_domain = [('name', '=', registration.name),('work_phone', '=', registration.phone),('work_email', '=', registration.email)]

hr_employee_id = self.env['hr.employee'].search(hr_employee_domain)

if hr_employee_id:

registration.hr_employee_manager_id = hr_employee_id.parent_id


def action_cancel(self):

res = super().action_cancel()

## Hitta rätt mail scedular och lägga in event.mail.registration classen på den.
mail_schedulers = self.env['event.mail'].search([('event_id','=',self.event_id.id),('interval_type','=','after_cancel')])

for mail_scheduler in mail_schedulers:

registrations_not_yet_in_scheduler_domain = [('id', 'in', self.ids),('event_id', '=', mail_scheduler.event_id.id)]

registrations_not_yet_in_scheduler = self.env['event.registration'].search(registrations_not_yet_in_scheduler_domain)

for mail_registration in mail_scheduler.mail_registration_ids:

if mail_registration.registration_id in registrations_not_yet_in_scheduler:

mail_registration.mail_sent = False

new_canceled_registrations = registrations_not_yet_in_scheduler - mail_scheduler.mail_registration_ids.registration_id

mail_scheduler._create_missing_mail_registrations(new_canceled_registrations)

all_mail_done = all(mail_registration.mail_sent == True for mail_registration in mail_scheduler.mail_registration_ids)
total_sent = len(mail_scheduler.mail_registration_ids.filtered(lambda reg: reg.mail_sent))

mail_scheduler.update({
'mail_done': all_mail_done,
'mail_count_done': total_sent
})

_logger.warning("cancel was invoked!!!!!"*100)

return res

def writeSlideChannelPartner(self):
for record in self:
if record.state == "open" and record.event_id.slide_channel_id and not record.slide_channel_partner_id:
Expand Down Expand Up @@ -77,7 +131,6 @@ def createSlideChannelPartner(self, vals_list):
return vals_list

def write(self, vals):
logging.warning("event write"*100)
res = super(EventRegistration, self).write(vals)
if 'state' in vals and vals['state'] == "open":
logging.warning(f'{vals=}')
Expand Down
9 changes: 9 additions & 0 deletions event_elearning/models/event_type_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import models, fields, api, _

class EventTypeMail(models.Model):

_inherit = 'event.type.mail'

interval_type = fields.Selection(
selection_add=[('after_cancel','If the registration is cancelled')],
ondelete={'after_cancel': 'set default'})
26 changes: 9 additions & 17 deletions event_waitlist_website/data/event_open_slot_templet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@
<odoo>
<data>
<record id="event_open_slot" model="mail.template">
<field name="name">
Event: New open event slot
</field>
<field name="name">Event: New open event slot</field>
<field name="model_id" ref="event_waitlist_website.model_event_waiting_list" />
<field name="subject">
The event {{object.event_id.name or 'you have waited for'}} has a new open slot.
</field>
<field name="email_from">
{{ (object.event_id.organizer_id.email_formatted or object.event_id.user_id.email_formatted or '') }}
</field>
<field name="email_to">
{{ (object.email and '"%s" &lt;%s&gt;' % (object.name, object.email) or '') }}
</field>
<field name="description">
Sent to possible attendee that has registered on the waitlist when there is a open slot.
</field>
<field name="subject">The event {{object.event_id.name or 'you have waited for'}} has a new open slot.</field>
<field name="email_from">{{ (object.event_id.organizer_id.email_formatted or object.event_id.user_id.email_formatted or '') }}</field>
<field name="email_to">{{ (object.email and '"%s" &lt;%s&gt;' % (object.name, object.email) or '') }}</field>
<field name="description">Sent to possible attendee that has registered on the waitlist when there is a open slot.</field>
<field name="body_html" type="html">
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;">
<tr>
Expand Down Expand Up @@ -87,6 +77,7 @@
is starting
<br />
<br />
<br />
<t t-if="object.event_id.full_website_url">
Click this link to go to the page where you can sign up for the course.
<br />
Expand All @@ -98,9 +89,10 @@
<div>
<br />
<br />
You received this mail because of the waiting list you signed up for,
You received this mail because of the waiting list you signed up for.
<br />
<br />
if you want to stop receiving these emails.
If you want to stop receiving these emails.
<br/>
Click the link below to unsubscribe from the mailing list.
<a t-att-href="object.removal_link">
Expand Down
1 change: 1 addition & 0 deletions event_waitlist_website/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import event_type
from . import event_type_mail
from . import event_event
from . import event_mail
from . import website
Expand Down
10 changes: 6 additions & 4 deletions event_waitlist_website/models/event_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EventEvent(models.Model):

@api.depends("full_website_url")
def _compute_full_website_url_field(self):

base_url = self.env['ir.config_parameter'].get_param('web.base.url')

for event in self:
Expand Down Expand Up @@ -41,7 +41,9 @@ def create(self, vals_list):
_logger.warning(f"event {event=}")
onsubscribe_schedulers = event.event_mail_ids.filtered(lambda event_mail: event_mail.interval_type == 'open_event_slot')

_logger.warning(f"onsubscribe_schedulers {onsubscribe_schedulers=}")
onsubscribe_schedulers.with_user(SUPERUSER_ID).execute()
if onsubscribe_schedulers:

_logger.warning(f"onsubscribe_schedulers {onsubscribe_schedulers=}")
onsubscribe_schedulers.with_user(SUPERUSER_ID).execute()

return events
return events
Loading