[NEW] event_mail_manual
This commit is contained in:
1
event_mail_manual/__init__.py
Normal file
1
event_mail_manual/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
22
event_mail_manual/__manifest__.py
Normal file
22
event_mail_manual/__manifest__.py
Normal 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,
|
||||
|
||||
}
|
1
event_mail_manual/models/__init__.py
Normal file
1
event_mail_manual/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import event_mail
|
79
event_mail_manual/models/event_mail.py
Normal file
79
event_mail_manual/models/event_mail.py
Normal 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
|
30
event_mail_manual/views/event_event_views.xml
Normal file
30
event_mail_manual/views/event_event_views.xml
Normal 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>
|
Reference in New Issue
Block a user