Skip to content

Commit

Permalink
[FIX] mail_show_follower: Use company from the document to render mes…
Browse files Browse the repository at this point in the history
…sages correctly

In a multi-company environment, if one company uses the show_followers_partner_format by partner_name and another company uses partner_email, a user with permissions in both companies may experience issues. If a document belongs to Company A, but the current company is set to Company B, the message format is taken from the current company (Company B) instead of the document’s company (Company A). This fix ensures that the message format is rendered based on the document's company.
  • Loading branch information
carlos-lopez-tecnativa committed Oct 10, 2024
1 parent 89e0d29 commit 666a2f5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mail_show_follower/models/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
# get partners
cc_internal = True
# else get company in object
company = self.env.company
if hasattr(obj, "company_id") and obj.company_id:
cc_internal = obj.company_id.show_internal_users_cc
company = obj.company_id

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

View check run for this annotation

Codecov / codecov/patch

mail_show_follower/models/mail_mail.py#L110

Added line #L110 was not covered by tests
# get company in user
elif mail.env and mail.env.user and mail.env.user.company_id:
cc_internal = (
Expand Down Expand Up @@ -139,14 +141,16 @@ def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
mail.mapped("recipient_ids.lang")
+ [
mail.author_id.lang,
self.env.company.partner_id.lang,
company.partner_id.lang,
],
)
)
# get show follower text
final_cc = mail.with_context(
lang=langs and langs[0]
)._build_cc_text(partners)
final_cc = (
mail.with_context(lang=langs and langs[0])
.with_company(company)
._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
Expand Down

0 comments on commit 666a2f5

Please sign in to comment.