Skip to content

Commit

Permalink
Merge PR #1464 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by yajo
  • Loading branch information
OCA-git-bot committed Oct 15, 2024
2 parents 89e0d29 + 1de314a commit d68c9f1
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 95 deletions.
3 changes: 2 additions & 1 deletion mail_show_follower/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Configuration
To configure this module, you need to:

#. Go General settings/Discuss/Show Followers on mails/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.
#. Go Settings/Users & Company select any user in 'Preferences' check or not the 'Show in CC' field if this user need to appear in the cc note.
#. Go General settings/Discuss/Show Followers on mails/Text 'Sent to' and set the initial part of the message.
#. Go General settings/Discuss/Show Followers on mails/Partner format and choose desired fields to show on CC recipients.
#. Go General settings/Discuss/Show Followers on mails/Text 'Replies' and choose desired warn message
Expand Down Expand Up @@ -82,6 +82,7 @@ Contributors
* Valentin Vinagre <valentin.vinagre@sygel.es>
* Lorenzo Battistini
* Eduardo de Miguel <edu@moduon.team>
* Vincent Van Rossem <vincent.vanrossem@camptocamp.com>

Maintainers
~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions mail_show_follower/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import mail_mail
from . import res_company
from . import res_config_settings
from . import res_partner
from . import res_users
116 changes: 25 additions & 91 deletions mail_show_follower/models/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,97 +59,31 @@ def remove_p(markup_txt):
return full_text

def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
group_portal = self.env.ref("base.group_portal")
for mail_id in self.ids:
mail = self.browse(mail_id)
message_recipients = self.search(
[
("message_id", "=", mail.message_id),
]
).mapped("recipient_ids")
# 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")
| message_recipients
)
# 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 any(x.mapped("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")
)
# set proper lang for recipients
langs = list(
filter(
bool,
mail.mapped("recipient_ids.lang")
+ [
mail.author_id.lang,
self.env.company.partner_id.lang,
],
)
)
# get show follower text
final_cc = mail.with_context(
lang=langs and langs[0]
)._build_cc_text(partners)
# 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
group_user = self.env.ref("base.group_user")

for mail in self:
if not (mail.model and mail.res_id and group_user):
continue
# recipients from any Notification Type (i.e. email, inbox, etc.)
recipients = mail.notification_ids.res_partner_id
record = self.env[mail.model].browse(mail.res_id)
company = getattr(record, "company_id", self.env.company)
show_internal_users = company and company.show_internal_users_cc
show_in_cc_recipients = recipients._filter_shown_in_cc(show_internal_users)
if len(show_in_cc_recipients) <= 1:
continue
lang = (
mail.notification_ids.res_partner_id[:1].lang
or mail.author_id.lang
or company.partner_id.lang
or "en_US"
)
final_cc = (
mail.with_context(lang=lang)
.with_company(company)
._build_cc_text(show_in_cc_recipients)
)
mail.body_html = final_cc + mail.body_html
return super()._send(
auto_commit=auto_commit,
raise_exception=raise_exception,
Expand Down
26 changes: 26 additions & 0 deletions mail_show_follower/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from odoo import models


class ResPartner(models.Model):
_inherit = "res.partner"

def _filter_shown_in_cc(self, show_internal_users):
"""Get partners that should be displayed as CC on mails."""
# Never display hidden users
result = self.filtered_domain(
[
"|",
("user_ids", "=", False),
("user_ids.show_in_cc", "=", True),
]
)
# Remove internal users from result if needed
if not show_internal_users:
internal_users = result.filtered_domain(
[
("user_ids.active", "=", True),
("user_ids.groups_id", "in", self.env.ref("base.group_user").ids),
]
)
result -= internal_users
return result
2 changes: 1 addition & 1 deletion mail_show_follower/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
To configure this module, you need to:

#. Go General settings/Discuss/Show Followers on mails/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.
#. Go Settings/Users & Company select any user in 'Preferences' check or not the 'Show in CC' field if this user need to appear in the cc note.
#. Go General settings/Discuss/Show Followers on mails/Text 'Sent to' and set the initial part of the message.
#. Go General settings/Discuss/Show Followers on mails/Partner format and choose desired fields to show on CC recipients.
#. Go General settings/Discuss/Show Followers on mails/Text 'Replies' and choose desired warn message
1 change: 1 addition & 0 deletions mail_show_follower/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Valentin Vinagre <valentin.vinagre@sygel.es>
* Lorenzo Battistini
* Eduardo de Miguel <edu@moduon.team>
* Vincent Van Rossem <vincent.vanrossem@camptocamp.com>
4 changes: 2 additions & 2 deletions mail_show_follower/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -395,7 +394,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To configure this module, you need to:</p>
<ol class="arabic simple">
<li>Go General settings/Discuss/Show Followers on mails/Show Internal Users CC and set if want to show or not internal users in cc details.</li>
<li>Go Settings/Users &amp; Company salect any user in ‘Preferences’ check or not the ‘Show in CC’ field if this user need to appear in the cc note.</li>
<li>Go Settings/Users &amp; Company select any user in ‘Preferences’ check or not the ‘Show in CC’ field if this user need to appear in the cc note.</li>
<li>Go General settings/Discuss/Show Followers on mails/Text ‘Sent to’ and set the initial part of the message.</li>
<li>Go General settings/Discuss/Show Followers on mails/Partner format and choose desired fields to show on CC recipients.</li>
<li>Go General settings/Discuss/Show Followers on mails/Text ‘Replies’ and choose desired warn message</li>
Expand Down Expand Up @@ -431,6 +430,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Valentin Vinagre &lt;<a class="reference external" href="mailto:valentin.vinagre&#64;sygel.es">valentin.vinagre&#64;sygel.es</a>&gt;</li>
<li>Lorenzo Battistini</li>
<li>Eduardo de Miguel &lt;<a class="reference external" href="mailto:edu&#64;moduon.team">edu&#64;moduon.team</a>&gt;</li>
<li>Vincent Van Rossem &lt;<a class="reference external" href="mailto:vincent.vanrossem&#64;camptocamp.com">vincent.vanrossem&#64;camptocamp.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down

0 comments on commit d68c9f1

Please sign in to comment.