summaryrefslogtreecommitdiff
path: root/addons/sms/models
diff options
context:
space:
mode:
authorlaa <laa@odoo.com>2019-09-11 15:04:40 +0000
committerThibault Delavallée <tde@odoo.com>2019-11-07 16:19:37 +0000
commit72aa04984463db0b15770cbf26fd15dd9c2ccaee (patch)
tree1cbd3b140dd9338a4a2f3e460cb552dd148487d8 /addons/sms/models
parentdc70fb35a104e260b40425fce23cba84b9770994 (diff)
[IMP] mail, mass_mailing: add dynamic placeholder mixin and use it in mailing and templates
PURPOSE Upgrade the "mass_mailing" and "mass_mailing_sms" modules with a dynamic placeholder generator as it already exists in "mail module" as depicted in https://www.screencast.com/t/cnFA0gIY. SPECIFICATIONS As duplicated code already exists for that and that a third version of this code has to be added, instead create a mixin for this dynamic placeholder generator to avoid code duplication. Thereby * a mail.render mixin for the dynamic placeholder generator must be created in mail; * dynamic placeholder generator code present in mail.template.py must be moved to that mixin and replaced by a simple inherit; * use the mixin in * mail templates: mail.template.py (mail module); * mass mailings: mailing.py (mass_mailing module); * sms templates: sms.template (mass_mailing_sms module); In a near future, some code will be added in this mixin, notably the template rendering that could be moved outside of mail.template core model and moved in that rendering mixin. LINKS Task ID 2070612 PR #36722 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/sms/models')
-rw-r--r--addons/sms/models/sms_template.py56
1 files changed, 1 insertions, 55 deletions
diff --git a/addons/sms/models/sms_template.py b/addons/sms/models/sms_template.py
index cf2120c8a5e..f106c21139f 100644
--- a/addons/sms/models/sms_template.py
+++ b/addons/sms/models/sms_template.py
@@ -7,6 +7,7 @@ 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
@@ -30,61 +31,6 @@ class SMSTemplate(models.Model):
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")
- # Fake fields used to implement the placeholder assistant
- model_object_field = fields.Many2one('ir.model.fields', string="Field", store=False,
- help="Select target field from the related document model.\n"
- "If it is a relationship field you will be able to select "
- "a target field at the destination of the relationship.")
- sub_object = fields.Many2one('ir.model', 'Sub-model', readonly=True, store=False,
- help="When a relationship field is selected as first field, "
- "this field shows the document model the relationship goes to.")
- sub_model_object_field = fields.Many2one('ir.model.fields', 'Sub-field', store=False,
- help="When a relationship field is selected as first field, "
- "this field lets you select the target field within the "
- "destination document model (sub-model).")
- null_value = fields.Char('Default Value', store=False, help="Optional value to use if the target field is empty")
- copyvalue = fields.Char('Placeholder Expression', store=False,
- help="Final placeholder expression, to be copy-pasted in the desired template field.")
-
- @api.onchange('model_object_field', 'sub_model_object_field', 'null_value')
- def _onchange_dynamic_placeholder(self):
- """ Generate the dynamic placeholder """
- if self.model_object_field:
- if self.model_object_field.ttype in ['many2one', 'one2many', 'many2many']:
- model = self.env['ir.model']._get(self.model_object_field.relation)
- if model:
- self.sub_object = model.id
- sub_field_name = self.sub_model_object_field.name
- self.copyvalue = self._build_expression(self.model_object_field.name,
- sub_field_name, self.null_value or False)
- else:
- self.sub_object = False
- self.sub_model_object_field = False
- self.copyvalue = self._build_expression(self.model_object_field.name, False, self.null_value or False)
- else:
- self.sub_object = False
- self.copyvalue = False
- self.sub_model_object_field = False
- self.null_value = False
-
- @api.model
- def _build_expression(self, field_name, sub_field_name, null_value):
- """Returns a placeholder expression for use in a template field,
- based on the values provided in the placeholder assistant.
-
- :param field_name: main field name
- :param sub_field_name: sub field name (M2O)
- :param null_value: default value if the target value is empty
- :return: final placeholder expression """
- expression = ''
- if field_name:
- expression = "${object." + field_name
- if sub_field_name:
- expression += "." + sub_field_name
- if null_value:
- expression += " or '''%s'''" % null_value
- expression += "}"
- return expression
@api.returns('self', lambda value: value.id)
def copy(self, default=None):