Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] migr mail show follower: Migration to 18.0 #1559

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[NEW] migrate mail_show_follower
Thomas Pot committed Jan 27, 2025
commit d2beb4934864f2edf310256c5a9c568cbeea6b47
2 changes: 2 additions & 0 deletions mail_show_follower/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -5,3 +5,5 @@ To configure this module, you need to:
#. 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
#. Go General settings/Discuss/Show Followers on mails/Follower message Background Color and choose desired background color
#. Go General settings/Discuss/Show Followers on mails/Follower message font Color and choose desired font color
2 changes: 2 additions & 0 deletions mail_show_follower/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
To use this module, you need to:

#. Send an email from any document of odoo.

Be aware that the extra message only is shown if there are multiple receipients for the sent message, and not all are set as Do not show in CC (for internal users)
5 changes: 5 additions & 0 deletions mail_show_follower/static/description/index.html
Original file line number Diff line number Diff line change
@@ -396,6 +396,9 @@ <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<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>
<li>Go General settings/Discuss/Show Followers on mails/Follower message Background Color and choose desired background color</li>
<li>Go General settings/Discuss/Show Followers on mails/Follower message font Color and choose desired font color</li>

</ol>
</div>
<div class="section" id="usage">
@@ -404,6 +407,8 @@ <h1><a class="toc-backref" href="#id2">Usage</a></h1>
<ol class="arabic simple">
<li>Send an email from any document of odoo.</li>
</ol>
<span>Note that the extra message will only be displayed if there are multiple recipients,
and not all are marked as "Do not show in CC" (for internal users). Also the extra display message is placed AFTER sending from Odoo. So you need to test the feature with a mail server setup, or a mailcatcher function.</span>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>

Unchanged files with check annotations Beta

@api.model
def _build_cc_text(self, partners):
if not partners:
return ""

Check warning on line 12 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L12

Added line #L12 was not covered by tests
def get_ctx_param(ctx_key, default_parm):

Check warning on line 14 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L14

Added line #L14 was not covered by tests
if ctx_key in self.env.context:
return self.env.context[ctx_key]
return default_parm

Check warning on line 17 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L16-L17

Added lines #L16 - L17 were not covered by tests
def remove_p(markup_txt):

Check warning on line 19 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L19

Added line #L19 was not covered by tests
if markup_txt.startswith("<p>") and markup_txt.endswith("</p>"):
return markup_txt[3:-4]
return markup_txt

Check warning on line 22 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L21-L22

Added lines #L21 - L22 were not covered by tests
company = self.env.company
partner_format = get_ctx_param(

Check warning on line 25 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L24-L25

Added lines #L24 - L25 were not covered by tests
"partner_format", company.show_followers_partner_format
)
msg_sent_to = get_ctx_param(

Check warning on line 28 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L28

Added line #L28 was not covered by tests
"msg_sent_to", company.show_followers_message_sent_to
)
msg_warn = get_ctx_param(

Check warning on line 31 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L31

Added line #L31 was not covered by tests
"msg_warn", company.show_followers_message_response_warning
)
msg_back_color = get_ctx_param(

Check warning on line 34 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L34

Added line #L34 was not covered by tests
"msg_back_color", company.show_followers_message_background_color
)
msg_font_color = get_ctx_param(

Check warning on line 37 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L37

Added line #L37 was not covered by tests
"msg_font_color", company.show_followers_message_font_color
)
partner_message = ", ".join(

Check warning on line 40 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L40

Added line #L40 was not covered by tests
[
partner_format
% {
for p in partners
]
)
full_text = """

Check warning on line 52 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L52

Added line #L52 was not covered by tests
<div summary='o_mail_notification' style='padding:5px;
margin:10px 0px 10px 0px;font-size:13px;border-radius:5px;
font-family:Arial;border:1px solid;color:{msg_font_color};background-color:{msg_back_color};'>
rc=msg_warn.striptags() and "<br/>" or "",
msg_warn=msg_warn.striptags() and remove_p(msg_warn) or "",
)
return full_text

Check warning on line 67 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L67

Added line #L67 was not covered by tests
def _send(self, auto_commit=False, raise_exception=False, smtp_session=None, alias_domain_id=False,
mail_server=False, post_send_callback=None):
group_portal = self.env.ref("base.group_portal")

Check warning on line 71 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L71

Added line #L71 was not covered by tests
for mail_id in self.ids:
mail = self.browse(mail_id)
message_recipients = self.search(

Check warning on line 74 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L73-L74

Added lines #L73 - L74 were not covered by tests
[
("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 and not mail.subtype_id.internal:
obj = self.env[mail.model].browse(mail.res_id)

Check warning on line 81 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L81

Added line #L81 was not covered by tests
# 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 = (

Check warning on line 86 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L86

Added line #L86 was not covered by tests
obj.message_follower_ids.mapped("partner_id")
| message_recipients
)
# internal partners
user_partner_ids = (

Check warning on line 91 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L91

Added line #L91 was not covered by tests
self.env["res.users"]
.search(
[
.mapped("partner_id")
.ids
)
partners_len = len(

Check warning on line 103 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L103

Added line #L103 was not covered by tests
partners_obj.filtered(
lambda x: x.id not in user_partner_ids
and (
)
if partners_len > 1:
# get partners
cc_internal = True

Check warning on line 114 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L114

Added line #L114 was not covered by tests
# else get company in object
if hasattr(obj, "company_id") and obj.company_id:
cc_internal = obj.company_id.show_internal_users_cc

Check warning on line 117 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L117

Added line #L117 was not covered by tests
# get company in user
elif mail.env and mail.env.user and mail.env.user.company_id:
cc_internal = (

Check warning on line 120 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L120

Added line #L120 was not covered by tests
self.env.user.company_id.show_internal_users_cc
)
if cc_internal:
partners = partners_obj.filtered(

Check warning on line 124 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L124

Added line #L124 was not covered by tests
lambda x: x.id not in user_partner_ids
and (
not x.user_ids
)
)
else:
partners = partners_obj.filtered(

Check warning on line 132 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L132

Added line #L132 was not covered by tests
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(

Check warning on line 139 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L139

Added line #L139 was not covered by tests
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(

Check warning on line 145 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L145

Added line #L145 was not covered by tests
filter(
bool,
mail.mapped("recipient_ids.lang")
)
)
# get show follower text
final_cc = mail.with_context(

Check warning on line 156 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L156

Added line #L156 was not covered by tests
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
return super()._send(

Check warning on line 162 in mail_show_follower/models/mail_mail.py

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L161-L162

Added lines #L161 - L162 were not covered by tests
auto_commit=auto_commit,
raise_exception=raise_exception,
smtp_session=smtp_session,
"show_followers_message_font_color"
)
def onchange_show_followers_message_preview(self):
self.show_followers_message_preview = (

Check warning on line 49 in mail_show_follower/models/res_config_settings.py

Codecov / codecov/patch

mail_show_follower/models/res_config_settings.py#L49

Added line #L49 was not covered by tests
self.env["mail.mail"]
.with_context(
# Use current data before