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/mass_mailing/wizard/mailing_list_merge.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/mass_mailing/wizard/mailing_list_merge.py')
| -rw-r--r-- | addons/mass_mailing/wizard/mailing_list_merge.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/addons/mass_mailing/wizard/mailing_list_merge.py b/addons/mass_mailing/wizard/mailing_list_merge.py new file mode 100644 index 00000000..21310778 --- /dev/null +++ b/addons/mass_mailing/wizard/mailing_list_merge.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _ +from odoo.exceptions import UserError + + +class MassMailingListMerge(models.TransientModel): + _name = 'mailing.list.merge' + _description = 'Merge Mass Mailing List' + + @api.model + def default_get(self, fields): + res = super(MassMailingListMerge, self).default_get(fields) + + if not res.get('src_list_ids') and 'src_list_ids' in fields: + if self.env.context.get('active_model') != 'mailing.list': + raise UserError(_('You can only apply this action from Mailing Lists.')) + src_list_ids = self.env.context.get('active_ids') + res.update({ + 'src_list_ids': [(6, 0, src_list_ids)], + }) + if not res.get('dest_list_id') and 'dest_list_id' in fields: + src_list_ids = res.get('src_list_ids') or self.env.context.get('active_ids') + res.update({ + 'dest_list_id': src_list_ids and src_list_ids[0] or False, + }) + return res + + src_list_ids = fields.Many2many('mailing.list', string='Mailing Lists') + dest_list_id = fields.Many2one('mailing.list', string='Destination Mailing List') + merge_options = fields.Selection([ + ('new', 'Merge into a new mailing list'), + ('existing', 'Merge into an existing mailing list'), + ], 'Merge Option', required=True, default='new') + new_list_name = fields.Char('New Mailing List Name') + archive_src_lists = fields.Boolean('Archive source mailing lists', default=True) + + def action_mailing_lists_merge(self): + if self.merge_options == 'new': + self.dest_list_id = self.env['mailing.list'].create({ + 'name': self.new_list_name, + }).id + self.dest_list_id.action_merge(self.src_list_ids, self.archive_src_lists) + return self.dest_list_id |
