diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/sms/models/sms_template.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/sms/models/sms_template.py')
| -rw-r--r-- | addons/sms/models/sms_template.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/addons/sms/models/sms_template.py b/addons/sms/models/sms_template.py new file mode 100644 index 00000000..be402f02 --- /dev/null +++ b/addons/sms/models/sms_template.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _ + + +class SMSTemplate(models.Model): + "Templates for sending SMS" + _name = "sms.template" + _inherit = ['mail.render.mixin'] + _description = 'SMS Templates' + + @api.model + def default_get(self, fields): + res = super(SMSTemplate, self).default_get(fields) + if not fields or 'model_id' in fields and not res.get('model_id') and res.get('model'): + res['model_id'] = self.env['ir.model']._get(res['model']).id + return res + + name = fields.Char('Name', translate=True) + model_id = fields.Many2one( + 'ir.model', string='Applies to', required=True, + domain=['&', ('is_mail_thread_sms', '=', True), ('transient', '=', False)], + help="The type of document this template can be used with", ondelete='cascade') + model = fields.Char('Related Document Model', related='model_id.model', index=True, store=True, readonly=True) + body = fields.Char('Body', translate=True, required=True) + # Use to create contextual action (same as for email template) + sidebar_action_id = fields.Many2one('ir.actions.act_window', 'Sidebar action', readonly=True, copy=False, + help="Sidebar action to make this template available on records " + "of the related document model") + + @api.returns('self', lambda value: value.id) + def copy(self, default=None): + default = dict(default or {}, + name=_("%s (copy)", self.name)) + return super(SMSTemplate, self).copy(default=default) + + def unlink(self): + self.sudo().mapped('sidebar_action_id').unlink() + return super(SMSTemplate, self).unlink() + + def action_create_sidebar_action(self): + ActWindow = self.env['ir.actions.act_window'] + view = self.env.ref('sms.sms_composer_view_form') + + for template in self: + button_name = _('Send SMS (%s)', template.name) + action = ActWindow.create({ + 'name': button_name, + 'type': 'ir.actions.act_window', + 'res_model': 'sms.composer', + # Add default_composition_mode to guess to determine if need to use mass or comment composer + 'context': "{'default_template_id' : %d, 'sms_composition_mode': 'guess', 'default_res_ids': active_ids, 'default_res_id': active_id}" % (template.id), + 'view_mode': 'form', + 'view_id': view.id, + 'target': 'new', + 'binding_model_id': template.model_id.id, + }) + template.write({'sidebar_action_id': action.id}) + return True + + def action_unlink_sidebar_action(self): + for template in self: + if template.sidebar_action_id: + template.sidebar_action_id.unlink() + return True |
