diff --git a/golem_mail/__init__.py b/golem_mail/__init__.py new file mode 100644 index 0000000..fcccd5d --- /dev/null +++ b/golem_mail/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +from . import wizard diff --git a/golem_mail/__manifest__.py b/golem_mail/__manifest__.py new file mode 100644 index 0000000..99fb8c0 --- /dev/null +++ b/golem_mail/__manifest__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +{ + 'name': 'GOLEM Mail', + 'summary': 'GOLEM Mail', + 'description': ''' GOLEM Mail ''', + 'version': '10.0.0.0.1', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'auto_install': True, + 'depends': ['mail', 'contacts'], + 'data': ['wizard/golem_mail_presend_wizard_views.xml'] +} diff --git a/golem_mail/wizard/__init__.py b/golem_mail/wizard/__init__.py new file mode 100644 index 0000000..8c7fe20 --- /dev/null +++ b/golem_mail/wizard/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from . import golem_mail_presend_wizard, golem_mail_recipient, mail_compose_message diff --git a/golem_mail/wizard/golem_mail_presend_wizard.py b/golem_mail/wizard/golem_mail_presend_wizard.py new file mode 100644 index 0000000..7ab5e3b --- /dev/null +++ b/golem_mail/wizard/golem_mail_presend_wizard.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +""" GOLEM Mail Presend Wizard """ + +import logging +from odoo import models, fields, api, _ +_LOGGER = logging.getLogger(__name__) + +class GolemMailPresendWizard(models.TransientModel): + """ GOLEM Mail Presend Wizard """ + _name = 'golem.mail.presend.wizard' + + recipient_ids = fields.One2many('golem.mail.recipient', 'presend_wizard_id') + + @api.multi + def edit_email(self): + """ Call mail_compose_message wizard """ + self.ensure_one() + wizard = self[0] + emails = wizard.recipient_ids.filtered(lambda r: not r.partner_id).mapped('email') + semails = list(set([item.strip() for item in emails])) + partners = wizard.recipient_ids.filtered(lambda r: not r.opt_out).mapped('partner_id').ids + return { + 'name' : _('Search results'), + 'type' : 'ir.actions.act_window', + 'res_model' : 'mail.compose.message', + 'context' : { + 'default_composition_mode': 'mass_mail', + 'default_partner_to': "\\", + 'default_use_template': True, + 'default_template_id': self.env.ref('mail.email_template_partner').id, + 'default_no_auto_thread': False, + 'default_from_presend_wizard': True, + 'partners_from_wizard': partners, + 'emails_from_wizard': semails}, + 'view_mode': 'form', + 'target': 'new' + } diff --git a/golem_mail/wizard/golem_mail_presend_wizard_views.xml b/golem_mail/wizard/golem_mail_presend_wizard_views.xml new file mode 100644 index 0000000..7165f00 --- /dev/null +++ b/golem_mail/wizard/golem_mail_presend_wizard_views.xml @@ -0,0 +1,45 @@ + + + + + + GOLEM Mail Presend Wizard Form + golem.mail.presend.wizard + +
+ + + + + + + + + + +
+
+
+
+
+
+
diff --git a/golem_mail/wizard/golem_mail_recipient.py b/golem_mail/wizard/golem_mail_recipient.py new file mode 100644 index 0000000..d505b94 --- /dev/null +++ b/golem_mail/wizard/golem_mail_recipient.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +""" GOLEM Mail Recipient Management """ + +import logging +from odoo import models, fields, api, _ +_LOGGER = logging.getLogger(__name__) + +class GolemMailRecipient(models.TransientModel): + """ GOLEM Mail Recipient """ + _name = 'golem.mail.recipient' + + partner_id = fields.Many2one('res.partner') + email = fields.Char() + firstname = fields.Char() + lastname = fields.Char() + phone = fields.Char() + opt_out = fields.Boolean() + presend_wizard_id = fields.Many2one('golem.mail.presend.wizard') + + @api.multi + @api.constrains('partner_id') + def fill_related_fields(self): + """ fill related fields from partner_id """ + for recipient in self: + if recipient.partner_id: + recipient.email = recipient.partner_id.email + recipient.firstname = recipient.partner_id.firstname + recipient.lastname = recipient.partner_id.lastname + recipient.phone = recipient.partner_id.phone + recipient.opt_out = recipient.partner_id.opt_out diff --git a/golem_mail/wizard/mail_compose_message.py b/golem_mail/wizard/mail_compose_message.py new file mode 100644 index 0000000..acfe106 --- /dev/null +++ b/golem_mail/wizard/mail_compose_message.py @@ -0,0 +1,144 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +""" Mail Compose Message Adaptations """ + +from odoo import _, api, fields, models, SUPERUSER_ID, tools +from odoo.tools.safe_eval import safe_eval + + + +class MailComposer(models.TransientModel): + """ Mail Compose Message Adaptations """ + _inherit = 'mail.compose.message' + + from_presend_wizard = fields.Boolean() + + @api.multi + def send_mail(self, auto_commit=False): + """ Process the wizard content and proceed with sending the related + email(s), rendering any template patterns on the fly if needed. """ + for wizard in self: + # Duplicate attachments linked to the email.template. + # Indeed, basic mail.compose.message wizard duplicates attachments in mass + # mailing mode. But in 'single post' mode, attachments of an email template + # also have to be duplicated to avoid changing their ownership. + if wizard.attachment_ids and wizard.composition_mode != 'mass_mail' and wizard.template_id: + new_attachment_ids = [] + for attachment in wizard.attachment_ids: + if attachment in wizard.template_id.attachment_ids: + new_attachment_ids.append(attachment.copy({'res_model': 'mail.compose.message', 'res_id': wizard.id}).id) + else: + new_attachment_ids.append(attachment.id) + wizard.write({'attachment_ids': [(6, 0, new_attachment_ids)]}) + + # Mass Mailing + mass_mode = wizard.composition_mode in ('mass_mail', 'mass_post') + + Mail = self.env['mail.mail'] + ActiveModel = self.env[wizard.model if wizard.model else 'mail.thread'] + if wizard.template_id: + # template user_signature is added when generating body_html + # mass mailing: use template auto_delete value -> note, for emails mass mailing only + Mail = Mail.with_context(mail_notify_user_signature=False) + ActiveModel = ActiveModel.with_context(mail_notify_user_signature=False, mail_auto_delete=wizard.template_id.auto_delete) + if not hasattr(ActiveModel, 'message_post'): + ActiveModel = self.env['mail.thread'].with_context(thread_model=wizard.model) + if wizard.composition_mode == 'mass_post': + # do not send emails directly but use the queue instead + # add context key to avoid subscribing the author + ActiveModel = ActiveModel.with_context(mail_notify_force_send=False, mail_create_nosubscribe=True) + # wizard works in batch mode: [res_id] or active_ids or active_domain + if mass_mode and wizard.use_active_domain and wizard.model: + res_ids = self.env[wizard.model].search(safe_eval(wizard.active_domain)).ids + elif mass_mode and wizard.model and self._context.get('active_ids'): + if wizard.from_presend_wizard: + res_ids = self._context['partners_from_wizard'] + else: + res_ids = self._context['active_ids'] + else: + res_ids = [wizard.res_id] + + batch_size = int(self.env['ir.config_parameter'].sudo().get_param('mail.batch_size')) or self._batch_size + sliced_res_ids = [res_ids[i:i + batch_size] for i in range(0, len(res_ids), batch_size)] + + if wizard.composition_mode == 'mass_mail' or wizard.is_log or (wizard.composition_mode == 'mass_post' and not wizard.notify): # log a note: subtype is False + subtype_id = False + elif wizard.subtype_id: + subtype_id = wizard.subtype_id.id + else: + subtype_id = self.sudo().env.ref('mail.mt_comment', raise_if_not_found=False).id + batch_mails = Mail + for res_ids in sliced_res_ids: + all_mail_values = wizard.get_mail_values(res_ids) + for res_id, mail_values in all_mail_values.iteritems(): + if wizard.composition_mode == 'mass_mail': + batch_mails |= Mail.create(mail_values) + else: + ActiveModel.browse(res_id).message_post( + message_type=wizard.message_type, + subtype_id=subtype_id, + **mail_values) + if self.env.context.get('emails_from_wizard', False): + mails = self._context['emails_from_wizard'] + emails_values = wizard.get_mail_values_from_mails(mails) + for email_val in emails_values: + batch_mails |= Mail.create(email_val) + + if wizard.composition_mode == 'mass_mail': + batch_mails.send(auto_commit=auto_commit) + + return {'type': 'ir.actions.act_window_close'} + + @api.multi + def get_mail_values_from_mails(self, mails): + self.ensure_one() + mail_values = { + 'subject': self.subject, + 'body': self.body or '', + 'parent_id': self.parent_id and self.parent_id.id, + 'partner_ids': [partner.id for partner in self.partner_ids], + 'attachment_ids': [attach.id for attach in self.attachment_ids], + 'author_id': self.author_id.id, + 'email_from': self.email_from, + 'record_name': self.record_name, + 'no_auto_thread': self.no_auto_thread, + 'mail_server_id': self.mail_server_id.id, + } + mail_values.update(notification=not self.auto_delete_message, + model=self.model, + record_name=False) + # auto deletion of mail_mail + if self.auto_delete or self.template_id.auto_delete: + mail_values['auto_delete'] = True + mail_values['reply_to'] = mail_values['email_from'] + mail_values['body_html'] = mail_values.get('body', '') + attachment_ids = [] + for attach_id in mail_values.pop('attachment_ids'): + new_attach_id = self.env['ir.attachment'].browse(attach_id).copy({ + 'res_model': self._name, + 'res_id': self.id + }) + attachment_ids.append(new_attach_id.id) + mail_values['attachment_ids'] = self.env['mail.thread']._message_preprocess_attachments( + mail_values.pop('attachments', []), + attachment_ids, 'mail.message', 0) + emails_result = [] + for email in mails: + mail_values['email_to'] = email + emails_result.append(dict(mail_values)) + return emails_result diff --git a/golem_mail_activity_registration/__init__.py b/golem_mail_activity_registration/__init__.py new file mode 100644 index 0000000..f96696e --- /dev/null +++ b/golem_mail_activity_registration/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +from . import models diff --git a/golem_mail_activity_registration/__manifest__.py b/golem_mail_activity_registration/__manifest__.py new file mode 100644 index 0000000..c6b3782 --- /dev/null +++ b/golem_mail_activity_registration/__manifest__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +{ + 'name': 'GOLEM Mail Activity Registration', + 'summary': 'GOLEM Mail Activity Registration', + 'description': ''' GOLEM Mail Activity Registration ''', + 'version': '10.0.0.0.1', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'auto_install': True, + 'depends': ['golem_activity_registration'], + 'data': ['views/golem_mail_activity_views.xml'] +} diff --git a/golem_mail_activity_registration/models/__init__.py b/golem_mail_activity_registration/models/__init__.py new file mode 100644 index 0000000..3076124 --- /dev/null +++ b/golem_mail_activity_registration/models/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from . import golem_activity diff --git a/golem_mail_activity_registration/models/golem_activity.py b/golem_mail_activity_registration/models/golem_activity.py new file mode 100644 index 0000000..7c00b24 --- /dev/null +++ b/golem_mail_activity_registration/models/golem_activity.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" GOLEM Activity adaptations """ + +from odoo import models, fields, api + +class GolemActivity(models.Model): + """ GOLEM Activity adaptations """ + _inherit = 'golem.activity' + + @api.multi + def activity_members_mass_mailing(self): + return self.get_mass_mailing_action('members') + + + @api.multi + def get_mass_mailing_action(self, action_type): + """ Call activity mass mailing presend wizard """ + presend_wizard = self.env['golem.mail.presend.wizard'].create({}) + if action_type == 'animators': + partners = self.mapped('animator_id').ids + for partner in partners: + self.env['golem.mail.recipient'].create({'partner_id': partner, + 'presend_wizard_id': presend_wizard.id}) + act_name = 'Activity animators mass mailing' + elif action_type == 'members': + partner_ids = self.mapped('activity_registration_ids').mapped( + 'member_id').mapped('partner_id').ids + for partner in partner_ids: + self.env['golem.mail.recipient'].create({'partner_id': partner, + 'presend_wizard_id': presend_wizard.id}) + act_name = 'Activity members mass mailing' + return { + 'type': 'ir.actions.act_window', + 'name': act_name, + 'res_model': 'golem.mail.presend.wizard', + 'res_id': presend_wizard.id, + 'view_mode': 'form', + 'view_type': 'form', + 'target': 'new' + } diff --git a/golem_mail_activity_registration/views/golem_mail_activity_views.xml b/golem_mail_activity_registration/views/golem_mail_activity_views.xml new file mode 100644 index 0000000..2e9cb86 --- /dev/null +++ b/golem_mail_activity_registration/views/golem_mail_activity_views.xml @@ -0,0 +1,70 @@ + + + + + + + Golem Activity form adaptations golem mail activity registration + golem.activity + + + +
+
+
+
+
+ + + Activity members mass mailing + + code + +action = records.get_mass_mailing_action('members') + + + + + + Family Members mass mailing + + + + + + Activity animators mass mailing + + code + +action = records.get_mass_mailing_action('animators') + + + + + + Activity animators mass mailing + + +
+
diff --git a/golem_mail_family/__init__.py b/golem_mail_family/__init__.py new file mode 100644 index 0000000..f96696e --- /dev/null +++ b/golem_mail_family/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +from . import models diff --git a/golem_mail_family/__manifest__.py b/golem_mail_family/__manifest__.py new file mode 100644 index 0000000..8751e6e --- /dev/null +++ b/golem_mail_family/__manifest__.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +{ + 'name': 'GOLEM Mail Family', + 'summary': 'GOLEM Mail Family', + 'description': ''' GOLEM Mail Family ''', + 'version': '10.0.0.0.1', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'depends': ['golem_family'], + 'data': ['views/golem_mail_family_views.xml'] +} diff --git a/golem_mail_family/models/__init__.py b/golem_mail_family/models/__init__.py new file mode 100644 index 0000000..49bfba1 --- /dev/null +++ b/golem_mail_family/models/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from . import golem_family diff --git a/golem_mail_family/models/golem_family.py b/golem_mail_family/models/golem_family.py new file mode 100644 index 0000000..5a04188 --- /dev/null +++ b/golem_mail_family/models/golem_family.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" GOLEM Family adaptations """ + +from odoo import models, fields, api + +class GolemFamily(models.Model): + """ GOLEM Family adaptations """ + _inherit = 'golem.family' + + @api.multi + def family_members_mass_mailing(self): + return self.get_mass_mailing_action('members') + + @api.multi + def get_mass_mailing_action(self, action_type): + """ Call family mass mailing presend wizard """ + presend_wizard = self.env['golem.mail.presend.wizard'].create({}) + if action_type == 'family': + emails = self.mapped('email') + for email in emails: + self.env['golem.mail.recipient'].create({'email': email, + 'presend_wizard_id': presend_wizard.id}) + act_name = 'Family mass mailing' + elif action_type == 'members': + partner_ids = self.mapped('member_ids').ids + for partner in partner_ids: + self.env['golem.mail.recipient'].create({'partner_id': partner, + 'presend_wizard_id': presend_wizard.id}) + act_name = 'Family members mass mailing' + return { + 'type': 'ir.actions.act_window', + 'name': act_name, + 'res_model': 'golem.mail.presend.wizard', + 'res_id': presend_wizard.id, + 'view_mode': 'form', + 'view_type': 'form', + 'target': 'new' + } diff --git a/golem_mail_family/views/golem_mail_family_views.xml b/golem_mail_family/views/golem_mail_family_views.xml new file mode 100644 index 0000000..811fa91 --- /dev/null +++ b/golem_mail_family/views/golem_mail_family_views.xml @@ -0,0 +1,71 @@ + + + + + + + Golem Family form adaptations golem mail family + golem.family + + + +
+
+
+
+
+ + + Family members mass mailing + + code + +action = records.get_mass_mailing_action('members') + + + + + + Family Members mass mailing + + + + + + Family mass mailing + + code + +action = records.get_mass_mailing_action('family') + + + + + + Family mass mailing + + +
+
diff --git a/golem_mail_member/__init__.py b/golem_mail_member/__init__.py new file mode 100644 index 0000000..f96696e --- /dev/null +++ b/golem_mail_member/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +from . import models diff --git a/golem_mail_member/__manifest__.py b/golem_mail_member/__manifest__.py new file mode 100644 index 0000000..0e0abe7 --- /dev/null +++ b/golem_mail_member/__manifest__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +{ + 'name': 'GOLEM Mail Member', + 'summary': 'GOLEM Mail Member', + 'description': ''' GOLEM Mail Member ''', + 'version': '10.0.0.0.1', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'depends': ['golem_member'], + 'data': ['views/golem_mail_member_views.xml', + 'views/golem_mail_res_partner_views.xml', + 'data/res_partner_data.xml'] +} diff --git a/golem_mail_member/data/res_partner_data.xml b/golem_mail_member/data/res_partner_data.xml new file mode 100644 index 0000000..89b9d26 --- /dev/null +++ b/golem_mail_member/data/res_partner_data.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + diff --git a/golem_mail_member/models/__init__.py b/golem_mail_member/models/__init__.py new file mode 100644 index 0000000..e7b52f4 --- /dev/null +++ b/golem_mail_member/models/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from . import golem_member, golem_res_partner_config diff --git a/golem_mail_member/models/golem_member.py b/golem_mail_member/models/golem_member.py new file mode 100644 index 0000000..ca50f62 --- /dev/null +++ b/golem_mail_member/models/golem_member.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" GOLEM Member adaptations """ + +from odoo import models, fields, api + +class GolemMember(models.Model): + """ GOLEM Member adaptations """ + _inherit = 'golem.member' + + @api.multi + def get_mass_mailing_action(self): + """ Call member mass mailing presend wizard """ + partners = self.mapped('partner_id').ids + presend_wizard = self.env['golem.mail.presend.wizard'].create( + {'partner_ids': [(6, 0, partners)]}) + for partner in partners: + self.env['golem.mail.recipient'].create({'partner_id': partner, + 'presend_wizard_id': presend_wizard.id}) + return { + 'type': 'ir.actions.act_window', + 'name': 'Member mass mailing', + 'res_model': 'golem.mail.presend.wizard', + 'res_id': presend_wizard.id, + 'view_mode': 'form', + 'view_type': 'form', + 'target': 'new' + } + +class ResPartner(models.Model): + """ Res Partner adaptations """ + _inherit = 'res.partner' + + @api.multi + def get_mass_mailing_action(self): + """ Call res partner mass mailing presend wizard """ + partners = self.ids + presend_wizard = self.env['golem.mail.presend.wizard'].create( + {'partner_ids': [(6, 0, partners)]}) + for partner in partners: + self.env['golem.mail.recipient'].create({'partner_id': partner, + 'presend_wizard_id': presend_wizard.id}) + return { + 'type': 'ir.actions.act_window', + 'name': 'Member mass mailing', + 'res_model': 'golem.mail.presend.wizard', + 'res_id': presend_wizard.id, + 'view_mode': 'form', + 'view_type': 'form', + 'target': 'new' + } diff --git a/golem_mail_member/models/golem_res_partner_config.py b/golem_mail_member/models/golem_res_partner_config.py new file mode 100644 index 0000000..5350448 --- /dev/null +++ b/golem_mail_member/models/golem_res_partner_config.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" GOLEM Res Partner Configuration """ + +from odoo import models, api, _ + + +class ResPartnerConfig(models.AbstractModel): + """ GOLEM Res Partner Configuration """ + _name = 'golem.res.partner.config' + _description = 'GOLEM Res Partner Configuration' + + @api.model + def res_partner_settings(self): + """ Res partner mas mailing remove """ + if self.env.ref('base.action_partner_mass_mail'): + self.env.ref('base.action_partner_mass_mail').unlink() diff --git a/golem_mail_member/views/golem_mail_member_views.xml b/golem_mail_member/views/golem_mail_member_views.xml new file mode 100644 index 0000000..b9a1174 --- /dev/null +++ b/golem_mail_member/views/golem_mail_member_views.xml @@ -0,0 +1,38 @@ + + + + + + + Member mass mailing + + code + +action = records.get_mass_mailing_action() + + + + + + Member mass mailing + + + + diff --git a/golem_mail_member/views/golem_mail_res_partner_views.xml b/golem_mail_member/views/golem_mail_res_partner_views.xml new file mode 100644 index 0000000..7ef13ef --- /dev/null +++ b/golem_mail_member/views/golem_mail_res_partner_views.xml @@ -0,0 +1,38 @@ + + + + + + + Partner mass mailing + + code + +action = records.get_mass_mailing_action() + + + + + + Partner mass mailing + + + +