While creating contextual action for an sms template, the composition mode may be decided on the fly, based on number of records and on context the key `default_composition_mode`, which is set to 'guess'. It used to work before a recent refactoring[1], because the composition mode was changed in the default_get, and was being set to appropriate value instead of 'guess'. After this refactoring, the composition mode is not being set in the default_get but is being computed, so the key `default_composition_mode` tries to set the composition_mode selection field to 'guess', which is not available in the selection values, resulting into traceback. This commit fixes the issue by renaming the context key(removing 'default' prefix) to avoid setting the mode directly and instead let the compute method decide the composition mode based on context key and number of records. [1] - https://github.com/odoo/odoo/commit/e02137c48562d824e3e01054e31dae383e5843e2 TaskID - 2286959 closes odoo/odoo#54938 X-original-commit: 2b9ea3d93445e05cb0440aab33f2bf9e066b0fa5 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
67 lines
2.9 KiB
Python
67 lines
2.9 KiB
Python
# -*- 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
|