Skip to content

Commit

Permalink
Merge PR #779 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Feb 19, 2025
2 parents da7f44c + 715d727 commit ea27fb8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mail_multicompany/models/mail_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ class MailMessage(models.Model):

@api.model_create_multi
def create(self, values_list):
context = self.env.context
for vals in values_list:
# When using mail.message.composer model and res_id are not defined but
# they are in the context.
if not vals.get("model") and context.get("active_model"):
vals["model"] = context.get("active_model")
if not vals.get("res_id") and context.get("active_id"):
vals["res_id"] = context.get("active_id")
if vals.get("model") and vals.get("res_id"):
current_object = self.env[vals["model"]].browse(vals["res_id"])
if hasattr(current_object, "company_id") and current_object.company_id:
vals["company_id"] = current_object.company_id.id
# when the object has no company, we try with the user,
# e.g. portal.wizard.user
elif (hasattr(current_object, "user_id") and
current_object.user_id.company_id):
vals["company_id"] = current_object.user_id.company_id.id
if not vals.get("company_id"):
vals["company_id"] = self.env.user.company_id.id
# Search SMTP server with company_id or shared SMTP server
Expand All @@ -31,4 +43,4 @@ def create(self, values_list):
)
.id
)
return super(MailMessage, self).create(vals)
return super(MailMessage, self).create(values_list)

0 comments on commit ea27fb8

Please sign in to comment.