Files
odoo_source/addons/mail/populate/discuss/mail_message.py
T
Sébastien Theys 673c926f58 [REF] mail: move channel populate to discuss folder
Part of task-3265211

closes odoo/odoo#120065

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2023-04-28 13:33:33 +02:00

27 lines
1.1 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from odoo.addons.mail.populate.mail_message import Message as MailMessage
from odoo.tools import populate
class Message(models.Model):
_inherit = "mail.message"
_populate_dependencies = ["discuss.channel", "discuss.channel.member"] + MailMessage._populate_dependencies
def _populate_factories(self):
channel_ids = self.env.registry.populated_models["discuss.channel"]
def get_author_id(values, counter, random):
channel = self.env[values["model"]].browse(values["res_id"])
channel_member_ids = [channel["id"] for channel in channel.channel_member_ids.read(["id"])]
return random.choice(channel_member_ids)
return [
("body", populate.constant("message_body_{counter}")),
("message_type", populate.constant("comment")),
("model", populate.constant("discuss.channel")),
("res_id", populate.randomize(channel_ids)),
("author_id", populate.compute(get_author_id)),
]