2018-11-02 10:38:21 +01:00
|
|
|
# Copyright 2018 David Juaneda - <djuaneda@sdi.es>
|
2021-01-22 10:36:00 +01:00
|
|
|
# Copyright 2018 ForgeFlow S.L. <https://www.forgeflow.com>
|
2018-11-02 10:38:21 +01:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
2020-07-08 20:37:18 +02:00
|
|
|
from odoo import api, fields, models
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MailActivity(models.Model):
|
|
|
|
_inherit = "mail.activity"
|
|
|
|
|
|
|
|
res_model_id_name = fields.Char(
|
2019-10-23 12:19:26 +02:00
|
|
|
related="res_model_id.name", string="Origin", readonly=True
|
|
|
|
)
|
|
|
|
duration = fields.Float(related="calendar_event_id.duration", readonly=True)
|
2018-11-02 10:38:21 +01:00
|
|
|
calendar_event_id_start = fields.Datetime(
|
2019-10-23 12:19:26 +02:00
|
|
|
related="calendar_event_id.start", readonly=True
|
|
|
|
)
|
2018-11-02 10:38:21 +01:00
|
|
|
calendar_event_id_partner_ids = fields.Many2many(
|
2019-10-23 12:19:26 +02:00
|
|
|
related="calendar_event_id.partner_ids", readonly=True
|
|
|
|
)
|
2019-12-03 14:29:08 +01:00
|
|
|
related_model_instance = fields.Reference(
|
|
|
|
selection="_selection_related_model_instance",
|
|
|
|
compute="_compute_related_model_instance",
|
|
|
|
string="Document",
|
|
|
|
)
|
|
|
|
|
|
|
|
@api.depends("res_id", "res_model")
|
|
|
|
def _compute_related_model_instance(self):
|
|
|
|
for record in self:
|
|
|
|
ref = False
|
|
|
|
if record.res_id:
|
|
|
|
ref = "{},{}".format(record.res_model, record.res_id)
|
|
|
|
record.related_model_instance = ref
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _selection_related_model_instance(self):
|
2022-08-23 10:28:36 +02:00
|
|
|
models = self.env["ir.model"].sudo().search([("is_mail_activity", "=", True)])
|
2019-12-03 14:29:08 +01:00
|
|
|
return [(model.model, model.name) for model in models]
|
2018-11-02 10:38:21 +01:00
|
|
|
|
|
|
|
def open_origin(self):
|
|
|
|
self.ensure_one()
|
|
|
|
vid = self.env[self.res_model].browse(self.res_id).get_formview_id()
|
|
|
|
response = {
|
2019-10-23 12:19:26 +02:00
|
|
|
"type": "ir.actions.act_window",
|
|
|
|
"res_model": self.res_model,
|
|
|
|
"view_mode": "form",
|
|
|
|
"res_id": self.res_id,
|
|
|
|
"target": "current",
|
|
|
|
"flags": {"form": {"action_buttons": False}},
|
|
|
|
"views": [(vid, "form")],
|
2018-11-02 10:38:21 +01:00
|
|
|
}
|
|
|
|
return response
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def action_activities_board(self):
|
2019-10-23 12:19:26 +02:00
|
|
|
action = self.env.ref("mail_activity_board.open_boards_activities").read()[0]
|
2018-11-02 10:38:21 +01:00
|
|
|
return action
|
2018-11-30 13:21:01 +01:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _find_allowed_model_wise(self, doc_model, doc_dict):
|
|
|
|
doc_ids = list(doc_dict)
|
2019-10-23 12:19:26 +02:00
|
|
|
allowed_doc_ids = (
|
|
|
|
self.env[doc_model]
|
|
|
|
.with_context(active_test=False)
|
|
|
|
.search([("id", "in", doc_ids)])
|
|
|
|
.ids
|
|
|
|
)
|
|
|
|
return {
|
|
|
|
message_id
|
|
|
|
for allowed_doc_id in allowed_doc_ids
|
|
|
|
for message_id in doc_dict[allowed_doc_id]
|
|
|
|
}
|
2018-11-30 13:21:01 +01:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _find_allowed_doc_ids(self, model_ids):
|
2019-10-23 12:19:26 +02:00
|
|
|
ir_model_access_model = self.env["ir.model.access"]
|
2018-11-30 13:21:01 +01:00
|
|
|
allowed_ids = set()
|
|
|
|
for doc_model, doc_dict in model_ids.items():
|
2019-10-23 12:19:26 +02:00
|
|
|
if not ir_model_access_model.check(doc_model, "read", False):
|
2018-11-30 13:21:01 +01:00
|
|
|
continue
|
|
|
|
allowed_ids |= self._find_allowed_model_wise(doc_model, doc_dict)
|
|
|
|
return allowed_ids
|