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/mail_thread.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/mail_thread.py')
| -rw-r--r-- | addons/sms/models/mail_thread.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/addons/sms/models/mail_thread.py b/addons/sms/models/mail_thread.py index f15ed6a3cad..1bbf9f20f40 100644 --- a/addons/sms/models/mail_thread.py +++ b/addons/sms/models/mail_thread.py @@ -35,15 +35,25 @@ class MailThread(models.AbstractModel): def _search_message_has_sms_error(self, operator, operand): return ['&', ('message_ids.has_sms_error', operator, operand), ('message_ids.author_id', '=', self.env.user.partner_id.id)] + def _sms_get_partner_fields(self): + """ This method returns the fields to use to find the contact to link + whensending an SMS. Having partner is not necessary, having only phone + number fields is possible. However it gives more flexibility to + notifications management when having partners. """ + fields = [] + if hasattr(self, 'partner_id'): + fields.append('partner_id') + if hasattr(self, 'partner_ids'): + fields.append('partner_ids') + return fields + def _sms_get_default_partners(self): """ This method will likely need to be overridden by inherited models. :returns partners: recordset of res.partner """ partners = self.env['res.partner'] - if hasattr(self, 'partner_id'): - partners |= self.mapped('partner_id') - if hasattr(self, 'partner_ids'): - partners |= self.mapped('partner_ids') + for fname in self._sms_get_partner_fields(): + partners |= self.mapped(fname) return partners def _sms_get_number_fields(self): |
