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/test_mail_full/models | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/test_mail_full/models')
| -rw-r--r-- | addons/test_mail_full/models/__init__.py | 4 | ||||
| -rw-r--r-- | addons/test_mail_full/models/mailing_mailing.py | 29 | ||||
| -rw-r--r-- | addons/test_mail_full/models/test_mail_models.py | 109 |
3 files changed, 142 insertions, 0 deletions
diff --git a/addons/test_mail_full/models/__init__.py b/addons/test_mail_full/models/__init__.py new file mode 100644 index 00000000..0fe839f2 --- /dev/null +++ b/addons/test_mail_full/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import test_mail_models +from . import mailing_mailing diff --git a/addons/test_mail_full/models/mailing_mailing.py b/addons/test_mail_full/models/mailing_mailing.py new file mode 100644 index 00000000..8d8a49a1 --- /dev/null +++ b/addons/test_mail_full/models/mailing_mailing.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import logging + +from odoo import models + +_logger = logging.getLogger(__name__) + + +class Mailing(models.Model): + _inherit = 'mailing.mailing' + + def _get_opt_out_list_sms(self): + """Returns a set of emails opted-out in target model""" + self.ensure_one() + if self.mailing_model_real in ('mail.test.sms.bl.optout', + 'mail.test.sms.partner', + 'mail.test.sms.partner.2many'): + res_ids = self._get_recipients() + opt_out_contacts = set(self.env[self.mailing_model_real].search([ + ('id', 'in', res_ids), + ('opt_out', '=', True) + ]).ids) + _logger.info( + "Mass-mailing %s targets %s, optout: %s emails", + self, self.mailing_model_real, len(opt_out_contacts)) + return opt_out_contacts + return super(Mailing, self)._get_opt_out_list_sms() diff --git a/addons/test_mail_full/models/test_mail_models.py b/addons/test_mail_full/models/test_mail_models.py new file mode 100644 index 00000000..a3b5eb8d --- /dev/null +++ b/addons/test_mail_full/models/test_mail_models.py @@ -0,0 +1,109 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class MailTestSMS(models.Model): + """ A model inheriting from mail.thread with some fields used for SMS + gateway, like a partner, a specific mobile phone, ... """ + _description = 'Chatter Model for SMS Gateway' + _name = 'mail.test.sms' + _inherit = ['mail.thread'] + _order = 'name asc, id asc' + + name = fields.Char() + subject = fields.Char() + email_from = fields.Char() + phone_nbr = fields.Char() + mobile_nbr = fields.Char() + customer_id = fields.Many2one('res.partner', 'Customer') + + def _sms_get_partner_fields(self): + return ['customer_id'] + + def _sms_get_number_fields(self): + return ['phone_nbr', 'mobile_nbr'] + + +class MailTestSMSBL(models.Model): + """ A model inheriting from mail.thread.phone allowing to test auto formatting + of phone numbers, blacklist, ... """ + _description = 'SMS Mailing Blacklist Enabled' + _name = 'mail.test.sms.bl' + _inherit = ['mail.thread.phone'] + _order = 'name asc, id asc' + + name = fields.Char() + subject = fields.Char() + email_from = fields.Char() + phone_nbr = fields.Char() + mobile_nbr = fields.Char() + customer_id = fields.Many2one('res.partner', 'Customer') + + def _sms_get_partner_fields(self): + return ['customer_id'] + + def _sms_get_number_fields(self): + # TDE note: should override _phone_get_number_fields but ok as sms in dependencies + return ['phone_nbr', 'mobile_nbr'] + + +class MailTestSMSOptout(models.Model): + """ Model using blacklist mechanism and a hijacked opt-out mechanism for + mass mailing features. """ + _description = 'SMS Mailing Blacklist / Optout Enabled' + _name = 'mail.test.sms.bl.optout' + _inherit = ['mail.thread.phone'] + _order = 'name asc, id asc' + + name = fields.Char() + subject = fields.Char() + email_from = fields.Char() + phone_nbr = fields.Char() + mobile_nbr = fields.Char() + customer_id = fields.Many2one('res.partner', 'Customer') + opt_out = fields.Boolean() + + def _sms_get_partner_fields(self): + return ['customer_id'] + + def _sms_get_number_fields(self): + # TDE note: should override _phone_get_number_fields but ok as sms in dependencies + return ['phone_nbr', 'mobile_nbr'] + + +class MailTestSMSPartner(models.Model): + """ A model like sale order having only a customer, not specific phone + or mobile fields. """ + _description = 'Chatter Model for SMS Gateway (Partner only)' + _name = 'mail.test.sms.partner' + _inherit = ['mail.thread'] + + name = fields.Char() + customer_id = fields.Many2one('res.partner', 'Customer') + opt_out = fields.Boolean() + + def _sms_get_partner_fields(self): + return ['customer_id'] + + def _sms_get_number_fields(self): + return [] + + +class MailTestSMSPartner2Many(models.Model): + """ A model like sale order having only a customer, not specific phone + or mobile fields. """ + _description = 'Chatter Model for SMS Gateway (M2M Partners only)' + _name = 'mail.test.sms.partner.2many' + _inherit = ['mail.thread'] + + name = fields.Char() + customer_ids = fields.Many2many('res.partner', string='Customers') + opt_out = fields.Boolean() + + def _sms_get_partner_fields(self): + return ['customer_ids'] + + def _sms_get_number_fields(self): + return [] |
