diff --git a/mail_show_follower/README.rst b/mail_show_follower/README.rst new file mode 100644 index 0000000..29a6ff3 --- /dev/null +++ b/mail_show_follower/README.rst @@ -0,0 +1,93 @@ +================== +Mail Show Follower +================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/15.0/mail_show_follower + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-15-0/social-15-0-mail_show_follower + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/205/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of mailing to show the document followers in head of the mails. +In the cc, only appear when: + +#. The followers only count if are contacts or external users (Inner Followers will be discriminated) +#. The number of followers are more than 1. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +#. Go General settings/Discuss/Show Internal Users CC and set if want to show or not internal users in cc details. +#. Go Settings/Users & Company salect any user in 'Preferences' check or not the 'Show in CC' field if this user need to appear in the cc note. + +Usage +===== + +To use this module, you need to: + +#. Send an email from any document of odoo. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Sygel + +Contributors +~~~~~~~~~~~~ + +* Valentin Vinagre +* Lorenzo Battistini + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_show_follower/__init__.py b/mail_show_follower/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/mail_show_follower/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_show_follower/__manifest__.py b/mail_show_follower/__manifest__.py new file mode 100644 index 0000000..b816bd0 --- /dev/null +++ b/mail_show_follower/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2020 Valentin Vinagre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Mail Show Follower", + "summary": "Show CC document followers in mails.", + "version": "15.0.1.0.0", + "category": "Mail", + "website": "https://github.com/OCA/social", + "author": "Sygel, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["base", "mail"], + "data": [ + "views/res_config_settings.xml", + "views/res_users.xml", + ], +} diff --git a/mail_show_follower/i18n/fr.po b/mail_show_follower/i18n/fr.po new file mode 100644 index 0000000..b70c373 --- /dev/null +++ b/mail_show_follower/i18n/fr.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_show_follower +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-01-19 15:32+0000\n" +"Last-Translator: Yann Papouin \n" +"Language-Team: none\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: mail_show_follower +#: model_terms:ir.ui.view,arch_db:mail_show_follower.res_config_settings_view_form +msgid "Add internal users in cc mails details" +msgstr "" +"Ajouter les utilisateurs internes dans l'entête « Copie à (CC) » des e-mails" + +#. module: mail_show_follower +#: model:ir.model,name:mail_show_follower.model_res_company +msgid "Companies" +msgstr "Sociétés" + +#. module: mail_show_follower +#: model:ir.model,name:mail_show_follower.model_res_config_settings +msgid "Config Settings" +msgstr "Paramétrage" + +#. module: mail_show_follower +#: model:ir.model,name:mail_show_follower.model_mail_mail +msgid "Outgoing Mails" +msgstr "Courriels à envoyer" + +#. module: mail_show_follower +#: model:ir.model.fields,field_description:mail_show_follower.field_res_company__show_internal_users_cc +#: model:ir.model.fields,field_description:mail_show_follower.field_res_config_settings__show_internal_users_cc +msgid "Show Internal Users CC" +msgstr "Afficher les utilisateurs internes en « Copie à (CC) »" + +#. module: mail_show_follower +#: model:ir.model.fields,field_description:mail_show_follower.field_res_users__show_in_cc +msgid "Show in CC" +msgstr "Afficher dans « Copie à (CC) »" + +#. module: mail_show_follower +#: model:ir.model,name:mail_show_follower.model_res_users +msgid "Users" +msgstr "Utilisateurs" diff --git a/mail_show_follower/i18n/mail_show_follower.pot b/mail_show_follower/i18n/mail_show_follower.pot new file mode 100644 index 0000000..5da0e0e --- /dev/null +++ b/mail_show_follower/i18n/mail_show_follower.pot @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_show_follower +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_show_follower +#: model_terms:ir.ui.view,arch_db:mail_show_follower.res_config_settings_view_form +msgid "Add internal users in cc mails details" +msgstr "" + +#. module: mail_show_follower +#: model:ir.model,name:mail_show_follower.model_res_company +msgid "Companies" +msgstr "" + +#. module: mail_show_follower +#: model:ir.model,name:mail_show_follower.model_res_config_settings +msgid "Config Settings" +msgstr "" + +#. module: mail_show_follower +#: model:ir.model,name:mail_show_follower.model_mail_mail +msgid "Outgoing Mails" +msgstr "" + +#. module: mail_show_follower +#: model:ir.model.fields,field_description:mail_show_follower.field_res_company__show_internal_users_cc +#: model:ir.model.fields,field_description:mail_show_follower.field_res_config_settings__show_internal_users_cc +msgid "Show Internal Users CC" +msgstr "" + +#. module: mail_show_follower +#: model:ir.model.fields,field_description:mail_show_follower.field_res_users__show_in_cc +msgid "Show in CC" +msgstr "" + +#. module: mail_show_follower +#: model:ir.model,name:mail_show_follower.model_res_users +msgid "Users" +msgstr "" diff --git a/mail_show_follower/models/__init__.py b/mail_show_follower/models/__init__.py new file mode 100644 index 0000000..9b936c4 --- /dev/null +++ b/mail_show_follower/models/__init__.py @@ -0,0 +1,4 @@ +from . import mail_mail +from . import res_company +from . import res_config_settings +from . import res_users diff --git a/mail_show_follower/models/mail_mail.py b/mail_show_follower/models/mail_mail.py new file mode 100644 index 0000000..5c9f6ad --- /dev/null +++ b/mail_show_follower/models/mail_mail.py @@ -0,0 +1,90 @@ +from odoo import models + + +class MailMail(models.Model): + _inherit = "mail.mail" + + def _send(self, auto_commit=False, raise_exception=False, smtp_session=None): + plain_text = ( + '
CC: %s
' + ) + group_portal = self.env.ref("base.group_portal") + for mail_id in self.ids: + mail = self.browse(mail_id) + # if the email has a model, id and it belongs to the portal group + if mail.model and mail.res_id and group_portal: + obj = self.env[mail.model].browse(mail.res_id) + # those partners are obtained, who do not have a user and + # if they do it must be a portal, we exclude internal + # users of the system. + if hasattr(obj, "message_follower_ids"): + partners_obj = obj.message_follower_ids.mapped("partner_id") + # internal partners + user_partner_ids = ( + self.env["res.users"] + .search( + [ + ("active", "in", (True, False)), + ("show_in_cc", "=", False), + ] + ) + .filtered(lambda x: group_portal not in x.groups_id) + .mapped("partner_id") + .ids + ) + partners_len = len( + partners_obj.filtered( + lambda x: x.id not in user_partner_ids + and ( + not x.user_ids + or group_portal in x.user_ids.mapped("groups_id") + ) + ) + ) + if partners_len > 1: + # get partners + cc_internal = True + # else get company in object + if hasattr(obj, "company_id") and obj.company_id: + cc_internal = obj.company_id.show_internal_users_cc + # get company in user + elif mail.env and mail.env.user and mail.env.user.company_id: + cc_internal = ( + self.env.user.company_id.show_internal_users_cc + ) + if cc_internal: + partners = partners_obj.filtered( + lambda x: x.id not in user_partner_ids + and (not x.user_ids or x.user_ids.show_in_cc) + ) + else: + partners = partners_obj.filtered( + lambda x: x.id not in user_partner_ids + and ( + not x.user_ids + or group_portal in x.user_ids.mapped("groups_id") + ) + ) + partners = partners.filtered( + lambda x: not x.user_ids + or x.user_ids # otherwise, email is not sent + and "email" in x.user_ids.mapped("notification_type") + ) + # get names and emails + final_cc = None + mails = "" + for p in partners: + mails += "%s <%s>, " % (p.name, p.email) + # join texts + final_cc = plain_text % (mails[:-2]) + # it is saved in the body_html field so that it does + # not appear in the odoo log + mail.body_html = final_cc + mail.body_html + return super()._send( + auto_commit=auto_commit, + raise_exception=raise_exception, + smtp_session=smtp_session, + ) diff --git a/mail_show_follower/models/res_company.py b/mail_show_follower/models/res_company.py new file mode 100644 index 0000000..fdbc33e --- /dev/null +++ b/mail_show_follower/models/res_company.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + show_internal_users_cc = fields.Boolean( + string="Show Internal Users CC", default=True + ) diff --git a/mail_show_follower/models/res_config_settings.py b/mail_show_follower/models/res_config_settings.py new file mode 100644 index 0000000..5b46dde --- /dev/null +++ b/mail_show_follower/models/res_config_settings.py @@ -0,0 +1,11 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + show_internal_users_cc = fields.Boolean( + string="Show Internal Users CC", + related="company_id.show_internal_users_cc", + readonly=False, + ) diff --git a/mail_show_follower/models/res_users.py b/mail_show_follower/models/res_users.py new file mode 100644 index 0000000..4f9d71f --- /dev/null +++ b/mail_show_follower/models/res_users.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class ResUser(models.Model): + _inherit = "res.users" + + show_in_cc = fields.Boolean(string="Show in CC", default=True) diff --git a/mail_show_follower/readme/CONFIGURE.rst b/mail_show_follower/readme/CONFIGURE.rst new file mode 100644 index 0000000..02a169a --- /dev/null +++ b/mail_show_follower/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +To configure this module, you need to: + +#. Go General settings/Discuss/Show Internal Users CC and set if want to show or not internal users in cc details. +#. Go Settings/Users & Company salect any user in 'Preferences' check or not the 'Show in CC' field if this user need to appear in the cc note. diff --git a/mail_show_follower/readme/CONTRIBUTORS.rst b/mail_show_follower/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..40630f3 --- /dev/null +++ b/mail_show_follower/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Valentin Vinagre +* Lorenzo Battistini diff --git a/mail_show_follower/readme/DESCRIPTION.rst b/mail_show_follower/readme/DESCRIPTION.rst new file mode 100644 index 0000000..19d4701 --- /dev/null +++ b/mail_show_follower/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module extends the functionality of mailing to show the document followers in head of the mails. +In the cc, only appear when: + +#. The followers only count if are contacts or external users (Inner Followers will be discriminated) +#. The number of followers are more than 1. diff --git a/mail_show_follower/readme/USAGE.rst b/mail_show_follower/readme/USAGE.rst new file mode 100644 index 0000000..9c3f9bf --- /dev/null +++ b/mail_show_follower/readme/USAGE.rst @@ -0,0 +1,3 @@ +To use this module, you need to: + +#. Send an email from any document of odoo. diff --git a/mail_show_follower/static/description/icon.png b/mail_show_follower/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/mail_show_follower/static/description/icon.png differ diff --git a/mail_show_follower/static/description/index.html b/mail_show_follower/static/description/index.html new file mode 100644 index 0000000..be30241 --- /dev/null +++ b/mail_show_follower/static/description/index.html @@ -0,0 +1,442 @@ + + + + + + +Mail Show Follower + + + +
+

Mail Show Follower

+ + +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runbot

+

This module extends the functionality of mailing to show the document followers in head of the mails. +In the cc, only appear when:

+
    +
  1. The followers only count if are contacts or external users (Inner Followers will be discriminated)
  2. +
  3. The number of followers are more than 1.
  4. +
+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Go General settings/Discuss/Show Internal Users CC and set if want to show or not internal users in cc details.
  2. +
  3. Go Settings/Users & Company salect any user in ‘Preferences’ check or not the ‘Show in CC’ field if this user need to appear in the cc note.
  4. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Send an email from any document of odoo.
  2. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Sygel
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_show_follower/views/res_config_settings.xml b/mail_show_follower/views/res_config_settings.xml new file mode 100644 index 0000000..7248903 --- /dev/null +++ b/mail_show_follower/views/res_config_settings.xml @@ -0,0 +1,25 @@ + + + + res.config.settings.view.form.inherit.mail.show.follower + res.config.settings + + +
+
+
+ +
+
+
+
+
+
+
+
diff --git a/mail_show_follower/views/res_users.xml b/mail_show_follower/views/res_users.xml new file mode 100644 index 0000000..a05a6eb --- /dev/null +++ b/mail_show_follower/views/res_users.xml @@ -0,0 +1,13 @@ + + + + view.users.form.mail.show.follower + res.users + + + + + + + + diff --git a/setup/mail_show_follower/odoo/addons/mail_show_follower b/setup/mail_show_follower/odoo/addons/mail_show_follower new file mode 120000 index 0000000..64a2d5f --- /dev/null +++ b/setup/mail_show_follower/odoo/addons/mail_show_follower @@ -0,0 +1 @@ +../../../../mail_show_follower \ No newline at end of file diff --git a/setup/mail_show_follower/setup.py b/setup/mail_show_follower/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/mail_show_follower/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)