summaryrefslogtreecommitdiff
path: root/addons/sms/models/ir_actions.py
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/sms/models/ir_actions.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/sms/models/ir_actions.py')
-rw-r--r--addons/sms/models/ir_actions.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/addons/sms/models/ir_actions.py b/addons/sms/models/ir_actions.py
new file mode 100644
index 00000000..48c71a9d
--- /dev/null
+++ b/addons/sms/models/ir_actions.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import _, api, fields, models
+from odoo.exceptions import ValidationError
+
+
+class ServerActions(models.Model):
+ """ Add SMS option in server actions. """
+ _name = 'ir.actions.server'
+ _inherit = ['ir.actions.server']
+
+ state = fields.Selection(selection_add=[
+ ('sms', 'Send SMS Text Message'),
+ ], ondelete={'sms': 'cascade'})
+ # SMS
+ sms_template_id = fields.Many2one(
+ 'sms.template', 'SMS Template', ondelete='set null',
+ domain="[('model_id', '=', model_id)]",
+ )
+ sms_mass_keep_log = fields.Boolean('Log as Note', default=True)
+
+ @api.constrains('state', 'model_id')
+ def _check_sms_capability(self):
+ for action in self:
+ if action.state == 'sms' and not action.model_id.is_mail_thread:
+ raise ValidationError(_("Sending SMS can only be done on a mail.thread model"))
+
+ def _run_action_sms_multi(self, eval_context=None):
+ # TDE CLEANME: when going to new api with server action, remove action
+ if not self.sms_template_id or self._is_recompute():
+ return False
+
+ records = eval_context.get('records') or eval_context.get('record')
+ if not records:
+ return False
+
+ composer = self.env['sms.composer'].with_context(
+ default_res_model=records._name,
+ default_res_ids=records.ids,
+ default_composition_mode='mass',
+ default_template_id=self.sms_template_id.id,
+ default_mass_keep_log=self.sms_mass_keep_log,
+ ).create({})
+ composer.action_send_sms()
+ return False