From f1515d3987a3fd5a684f843c0d6ba38009c747b9 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 3 Dec 2019 14:29:08 +0100 Subject: [PATCH 1/2] [IMP] mail_activity_board: Direct access to related model instance Add a direct access from activity calendar and form views to the linked model instance. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bedore this change, it was not possible to access to the model instance linked to an activity from the calendar view nor from the view opened by clicling on the activity into the calendar [IMP] mail_activiy_board: Restrict related_model_instance selection to models supporting mail acitvities Co-Authored-By: Miquel Raïch --- mail_activity_board/__manifest__.py | 2 +- mail_activity_board/models/mail_activity.py | 18 ++++++++ mail_activity_board/readme/CONTRIBUTORS.rst | 4 ++ .../tests/test_mail_activity_board.py | 8 ++++ .../views/mail_activity_view.xml | 46 ++++++++++++++++++- 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/mail_activity_board/__manifest__.py b/mail_activity_board/__manifest__.py index 87e1241..5e6d92b 100644 --- a/mail_activity_board/__manifest__.py +++ b/mail_activity_board/__manifest__.py @@ -8,7 +8,7 @@ "development_status": "Beta", "category": "Social Network", "website": "https://github.com/OCA/social", - "author": "SDi, David Juaneda, Sodexis, Odoo Community Association (OCA)", + "author": "SDi, David Juaneda, Sodexis, ACSONE SA/NV, Odoo Community Association (OCA)", "license": "AGPL-3", "installable": True, "depends": ["calendar", "board"], diff --git a/mail_activity_board/models/mail_activity.py b/mail_activity_board/models/mail_activity.py index 8cfd77a..1862f67 100644 --- a/mail_activity_board/models/mail_activity.py +++ b/mail_activity_board/models/mail_activity.py @@ -17,6 +17,24 @@ class MailActivity(models.Model): calendar_event_id_partner_ids = fields.Many2many( related="calendar_event_id.partner_ids", readonly=True ) + 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): + models = self.env["ir.model"].search([("is_mail_activity", "=", True)]) + return [(model.model, model.name) for model in models] def open_origin(self): self.ensure_one() diff --git a/mail_activity_board/readme/CONTRIBUTORS.rst b/mail_activity_board/readme/CONTRIBUTORS.rst index 5530d75..adad24f 100644 --- a/mail_activity_board/readme/CONTRIBUTORS.rst +++ b/mail_activity_board/readme/CONTRIBUTORS.rst @@ -9,3 +9,7 @@ * `Pesol `_: * Pedro Gonzalez (pedro.gonzalez@pesol.es) + +* `ACSONE SA/NV `_ + + * Laurent Mignon diff --git a/mail_activity_board/tests/test_mail_activity_board.py b/mail_activity_board/tests/test_mail_activity_board.py index 6aede0d..f83d971 100644 --- a/mail_activity_board/tests/test_mail_activity_board.py +++ b/mail_activity_board/tests/test_mail_activity_board.py @@ -202,3 +202,11 @@ class TestMailActivityBoardMethods(TransactionCase): for act in acts: self.assertIn(act, self.partner_client.activity_ids.ids) + + def test_related_model_instance(self): + """This test case checks the direct access from the activity to the + linked model instance + """ + self.assertEqual(self.act3.related_model_instance, self.partner_client) + self.act3.write({"res_id": False, "res_model": False}) + self.assertFalse(self.act3.related_model_instance) diff --git a/mail_activity_board/views/mail_activity_view.xml b/mail_activity_board/views/mail_activity_view.xml index 2949532..238ee33 100644 --- a/mail_activity_board/views/mail_activity_view.xml +++ b/mail_activity_board/views/mail_activity_view.xml @@ -4,6 +4,45 @@ VIEWS --> + + + mail.activity.view.form.popup (in mail_activity_board) + mail.activity + + + + + + + + + + + mail.activity.view.form.calendar (in mail_activity_board) + mail.activity + + + + + + + 1 + + + + mail.activity.boards.view.form @@ -88,7 +127,12 @@ name="decoration-success" >(date_deadline > current_date) - + + + + + 1 + From 055bd44d5c17a5424d0badcf283c06c04cf357bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Tue, 19 Apr 2022 12:39:24 +0200 Subject: [PATCH 2/2] [IMP] mail_activity_board: direct access from activity board form view --- mail_activity_board/views/mail_activity_view.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mail_activity_board/views/mail_activity_view.xml b/mail_activity_board/views/mail_activity_view.xml index 238ee33..9c3f365 100644 --- a/mail_activity_board/views/mail_activity_view.xml +++ b/mail_activity_board/views/mail_activity_view.xml @@ -57,7 +57,8 @@ class="centre oe_link" nolabel="1" > -

+ +