summaryrefslogtreecommitdiff
path: root/addons/event_sms/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/event_sms/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/event_sms/models')
-rw-r--r--addons/event_sms/models/__init__.py5
-rw-r--r--addons/event_sms/models/event_mail.py69
-rw-r--r--addons/event_sms/models/event_registration.py13
3 files changed, 87 insertions, 0 deletions
diff --git a/addons/event_sms/models/__init__.py b/addons/event_sms/models/__init__.py
new file mode 100644
index 00000000..95c3bd06
--- /dev/null
+++ b/addons/event_sms/models/__init__.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import event_mail
+from . import event_registration
diff --git a/addons/event_sms/models/event_mail.py b/addons/event_sms/models/event_mail.py
new file mode 100644
index 00000000..3e56a055
--- /dev/null
+++ b/addons/event_sms/models/event_mail.py
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models
+
+
+class EventTypeMail(models.Model):
+ _inherit = 'event.type.mail'
+
+ notification_type = fields.Selection(selection_add=[
+ ('sms', 'SMS')
+ ], ondelete={'sms': 'set default'})
+ sms_template_id = fields.Many2one(
+ 'sms.template', string='SMS Template',
+ domain=[('model', '=', 'event.registration')], ondelete='restrict',
+ help='This field contains the template of the SMS that will be automatically sent')
+
+ @api.model
+ def _get_event_mail_fields_whitelist(self):
+ return super(EventTypeMail, self)._get_event_mail_fields_whitelist() + ['sms_template_id']
+
+
+class EventMailScheduler(models.Model):
+ _inherit = 'event.mail'
+
+ notification_type = fields.Selection(selection_add=[
+ ('sms', 'SMS')
+ ], ondelete={'sms': 'set default'})
+ sms_template_id = fields.Many2one(
+ 'sms.template', string='SMS Template',
+ domain=[('model', '=', 'event.registration')], ondelete='restrict',
+ help='This field contains the template of the SMS that will be automatically sent')
+
+ def execute(self):
+ for mail in self:
+ now = fields.Datetime.now()
+ if mail.interval_type != 'after_sub':
+ # Do not send SMS if the communication was scheduled before the event but the event is over
+ if not mail.mail_sent and mail.scheduled_date <= now and mail.notification_type == 'sms' and \
+ (mail.interval_type != 'before_event' or mail.event_id.date_end > now) and \
+ mail.sms_template_id:
+ self.env['event.registration']._message_sms_schedule_mass(
+ template=mail.sms_template_id,
+ active_domain=[('event_id', '=', mail.event_id.id), ('state', '!=', 'cancel')],
+ mass_keep_log=True
+ )
+ mail.write({'mail_sent': True})
+ return super(EventMailScheduler, self).execute()
+
+
+class EventMailRegistration(models.Model):
+ _inherit = 'event.mail.registration'
+
+ def execute(self):
+ now = fields.Datetime.now()
+ todo = self.filtered(lambda reg_mail:
+ not reg_mail.mail_sent and \
+ reg_mail.registration_id.state in ['open', 'done'] and \
+ (reg_mail.scheduled_date and reg_mail.scheduled_date <= now) and \
+ reg_mail.scheduler_id.notification_type == 'sms'
+ )
+ for reg_mail in todo:
+ reg_mail.registration_id._message_sms_schedule_mass(
+ template=reg_mail.scheduler_id.sms_template_id,
+ mass_keep_log=True
+ )
+ todo.write({'mail_sent': True})
+
+ return super(EventMailRegistration, self).execute()
diff --git a/addons/event_sms/models/event_registration.py b/addons/event_sms/models/event_registration.py
new file mode 100644
index 00000000..d8be5a53
--- /dev/null
+++ b/addons/event_sms/models/event_registration.py
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models
+
+
+class Registration(models.Model):
+ _inherit = 'event.registration'
+
+ def _sms_get_number_fields(self):
+ """ This method returns the fields to use to find the number to use to
+ send an SMS on a record. """
+ return ['mobile', 'phone']