diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-08-09 14:04:18 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-08-12 12:00:22 +0000 |
| commit | e7cd604afa7f2cd4a4073d8e24ec0da9384c8d03 (patch) | |
| tree | 376093fe748ef51b15aa9117497e24ba8de5cc69 /addons/sms/models/ir_model.py | |
| parent | 5450415354233671fe42f62c3b095d03c1389317 (diff) | |
[IMP] sms: add a is_mail_thread_sms field allowing to filter models
PURPOSE
SMS are a powerful marketing tool. For instance it is perfect to announce a
sale or to communicate a coupon code, to welcome a new customer in a fidelity
program, ...
Purpose of this task is to integrate SMS sending in batch in mass mailing. It
will use same mailing objects but sending SMS instead of emails. Some metrics
and flows will have to be slightly updated at the same time.
SPECIFICATIONS
Limit use of templates to models that are really capable of sending
SMS. Templates are now available on models that inherit from mail.thread
and effectively have fields used in SMS sending.
Technically this is done through a not stored field on ir.model that is
searchable. SMS sending capabilities is based on
* having fields holding phone numbers, as defined on mail.thread in SMS;
* having fields holding partners, as defined on mail.thread in SMS;
This implied some code rewriting notably about finding default SMS
recipients on a given model, in order to have fields instead of directly
returning partners.
LINKS
Task 1997464
PR #34424
Original SMS addition: Task 1922163 (4287481)
Diffstat (limited to 'addons/sms/models/ir_model.py')
| -rw-r--r-- | addons/sms/models/ir_model.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/addons/sms/models/ir_model.py b/addons/sms/models/ir_model.py new file mode 100644 index 00000000000..58d24897640 --- /dev/null +++ b/addons/sms/models/ir_model.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class IrModel(models.Model): + _inherit = 'ir.model' + + is_mail_thread_sms = fields.Boolean( + string="Mail Thread SMS", default=False, + store=False, compute='_compute_is_mail_thread_sms', search='_search_is_mail_thread_sms', + help="Whether this model supports messages and notifications through SMS", + ) + + @api.depends('is_mail_thread') + def _compute_is_mail_thread_sms(self): + for model in self: + if model.is_mail_thread: + ModelObject = self.env[model.model] + potential_fields = ModelObject._sms_get_number_fields() + ModelObject._sms_get_partner_fields() + if any(fname in ModelObject._fields for fname in potential_fields): + model.is_mail_thread_sms = True + continue + model.is_mail_thread_sms = False + + def _search_is_mail_thread_sms(self, operator, value): + thread_models = self.search([('is_mail_thread', '=', True)]) + valid_models = self.env['ir.model'] + for model in thread_models: + ModelObject = self.env[model.model] + potential_fields = ModelObject._sms_get_number_fields() + ModelObject._sms_get_partner_fields() + if any(fname in ModelObject._fields for fname in potential_fields): + valid_models |= model + + search_sms = (operator == '=' and value) or (operator == '!=' and not value) + if search_sms: + return [('id', 'in', valid_models.ids)] + return [('id', 'not in', valid_models.ids)] |
