[NEW] event_mail_manual

This commit is contained in:
clementthomas
2024-03-01 11:22:12 +01:00
parent 3ed3a7fae4
commit 387d90fbd7
5 changed files with 133 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,22 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Event mail manual",
"version": "16.0.0.0.0",
"license": "AGPL-3",
"author": "Elabore",
"website": "https://www.elabore.coop",
'summary': 'Add manual send in event communication',
'description': """
Add manual send in event communication
----------------------------------------------------
""",
"category": "",
"depends": ["event"],
"data": [
'views/event_event_views.xml'
],
"installable": True,
}

View File

@@ -0,0 +1 @@
from . import event_mail

View File

@@ -0,0 +1,79 @@
from odoo import _, api, Command, fields, models
from lxml import etree, html
import logging
from odoo.exceptions import MissingError, ValidationError
_logger = logging.getLogger(__name__)
class EventMail(models.Model):
_inherit = "event.mail"
notification_type = fields.Selection(selection_add=[('mail_manual', 'Mail (manual)')], ondelete={'mail_manual': 'set default'})
def _selection_template_model_get_mapping(self):
return {
'mail': 'mail.template',
'mail_manual': 'mail.template'
}
@api.depends('event_id.date_begin', 'event_id.date_end', 'interval_type', 'interval_unit', 'interval_nbr','notification_type')
def _compute_scheduled_date(self):
res = super(EventMail, self)._compute_scheduled_date()
for scheduler in self:
if scheduler.notification_type == 'mail_manual':
scheduler.scheduled_date = '2148-12-31'
scheduler.interval_type = 'after_sub'
return res
def send(self):
self.execute()
return
class EventMailRegistration(models.Model):
_inherit = 'event.mail.registration'
def execute(self):
"""Inherit execute to send mail from schedulers "mail_manual"
"""
res = super(EventMailRegistration, self).execute()
todo_manual = self.filtered(lambda reg_mail:
not reg_mail.mail_sent and
reg_mail.registration_id.state in ['open', 'done'] and
reg_mail.scheduler_id.notification_type == 'mail_manual'
)
done = self.browse()
for reg_mail in todo_manual:
organizer = reg_mail.scheduler_id.event_id.organizer_id
company = self.env.company
author = self.env.ref('base.user_root').partner_id
if organizer.email:
author = organizer
elif company.email:
author = company.partner_id
elif self.env.user.email:
author = self.env.user.partner_id
email_values = {
'author_id': author.id,
}
template = None
try:
template = reg_mail.scheduler_id.template_ref.exists()
except MissingError:
pass
if not template:
_logger.warning("Cannot process ticket %s, because Mail Scheduler %s has reference to non-existent template", reg_mail.registration_id, reg_mail.scheduler_id)
continue
if not template.email_from:
email_values['email_from'] = author.email_formatted
template.send_mail(reg_mail.registration_id.id, email_values=email_values)
done |= reg_mail
done.write({'mail_sent': True})
return res

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="view_event_form_event_mail_manual">
<field name="name">event.event.form.event.mail.manual</field>
<field name="inherit_id" ref="event.view_event_form" />
<field name="model">event.event</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='event_mail_ids']/tree/field[@name='mail_state']" position="after">
<button
name="send"
type="object"
icon="fa-bullhorn"
attrs="{'invisible':[('notification_type','!=','mail_manual')]}"
confirm="Send mail to all attendees ?" />
</xpath>
<xpath expr="//field[@name='event_mail_ids']/tree/field[@name='interval_nbr']" position="attributes">
<attribute name="attrs">{'readonly':['|',('interval_unit','=','now'),('notification_type','=','mail_manual')]}</attribute>
</xpath>
<xpath expr="//field[@name='event_mail_ids']/tree/field[@name='interval_unit']" position="attributes">
<attribute name="attrs">{'readonly':[('notification_type','=','mail_manual')]}</attribute>
</xpath>
<xpath expr="//field[@name='event_mail_ids']/tree/field[@name='interval_type']" position="attributes">
<attribute name="attrs">{'readonly':[('notification_type','=','mail_manual')]}</attribute>
</xpath>
</field>
</record>
</data>
</odoo>