2020-10-01 09:50:51 +02:00
|
|
|
# Copyright 2016-17 ForgeFlow S.L.
|
|
|
|
# (http://www.forgeflow.com)
|
2018-06-11 18:12:03 +02:00
|
|
|
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
|
|
|
# (<http://www.serpentcs.com>)
|
2017-01-10 10:20:26 +01:00
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
from lxml import etree
|
2020-07-09 22:13:40 +02:00
|
|
|
|
|
|
|
from odoo import _, api, fields, models
|
2017-07-10 13:28:35 +02:00
|
|
|
from odoo.osv import expression
|
2017-01-10 10:20:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MailThread(models.AbstractModel):
|
2020-07-09 22:13:40 +02:00
|
|
|
_inherit = "mail.thread"
|
2017-01-10 10:20:26 +01:00
|
|
|
|
|
|
|
def _search_message_content(self, operator, value):
|
2020-07-09 22:13:40 +02:00
|
|
|
model_domain = [("model", "=", self._name)]
|
2017-07-10 13:28:35 +02:00
|
|
|
if operator not in expression.NEGATIVE_TERM_OPERATORS:
|
|
|
|
model_domain += ["|"] * 4
|
|
|
|
model_domain += [
|
2020-07-09 22:13:40 +02:00
|
|
|
("record_name", operator, value),
|
|
|
|
("subject", operator, value),
|
|
|
|
("body", operator, value),
|
|
|
|
("email_from", operator, value),
|
|
|
|
("reply_to", operator, value),
|
2017-07-10 13:28:35 +02:00
|
|
|
]
|
2020-07-09 22:13:40 +02:00
|
|
|
recs = self.env["mail.message"].search(model_domain)
|
|
|
|
return [("id", "in", recs.mapped("res_id"))]
|
2017-01-10 10:20:26 +01:00
|
|
|
|
|
|
|
message_content = fields.Text(
|
2020-07-09 22:13:40 +02:00
|
|
|
help="Message content, to be used only in searches",
|
2022-04-20 13:24:43 +02:00
|
|
|
compute="_compute_message_content",
|
2020-07-09 22:13:40 +02:00
|
|
|
search="_search_message_content",
|
|
|
|
)
|
2017-01-10 10:20:26 +01:00
|
|
|
|
2022-04-20 13:24:43 +02:00
|
|
|
def _compute_message_content(self):
|
|
|
|
# Always assign a value to avoid CacheMiss errors
|
|
|
|
self.message_content = False
|
|
|
|
|
2017-07-10 13:28:35 +02:00
|
|
|
@api.model
|
2020-07-09 22:13:40 +02:00
|
|
|
def fields_view_get(
|
|
|
|
self, view_id=None, view_type="form", toolbar=False, submenu=False
|
|
|
|
):
|
2017-07-10 13:28:35 +02:00
|
|
|
"""
|
|
|
|
Override to add message_content field in all the objects
|
|
|
|
that inherits mail.thread
|
|
|
|
"""
|
|
|
|
res = super(MailThread, self).fields_view_get(
|
2020-07-09 22:13:40 +02:00
|
|
|
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
|
|
|
|
)
|
|
|
|
if view_type == "search" and self._fields.get("message_content"):
|
|
|
|
doc = etree.XML(res["arch"])
|
|
|
|
res["fields"].update(
|
|
|
|
{"message_content": {"type": "char", "string": _("Message Content")}}
|
|
|
|
)
|
2020-10-06 12:29:14 +02:00
|
|
|
for node in doc.xpath("/search/field[last()]"):
|
2017-07-10 13:28:35 +02:00
|
|
|
# Add message_content in search view
|
2020-07-09 22:13:40 +02:00
|
|
|
elem = etree.Element("field", {"name": "message_content"})
|
2017-07-10 13:28:35 +02:00
|
|
|
node.addnext(elem)
|
2020-07-09 22:13:40 +02:00
|
|
|
res["arch"] = etree.tostring(doc)
|
2017-07-10 13:28:35 +02:00
|
|
|
return res
|