[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.

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 <miquel.raich@eficent.com>
This commit is contained in:
Laurent Mignon (ACSONE) 2019-12-03 14:29:08 +01:00 committed by Miquel Raïch
parent 68017623da
commit f1515d3987
5 changed files with 76 additions and 2 deletions

View File

@ -8,7 +8,7 @@
"development_status": "Beta", "development_status": "Beta",
"category": "Social Network", "category": "Social Network",
"website": "https://github.com/OCA/social", "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", "license": "AGPL-3",
"installable": True, "installable": True,
"depends": ["calendar", "board"], "depends": ["calendar", "board"],

View File

@ -17,6 +17,24 @@ class MailActivity(models.Model):
calendar_event_id_partner_ids = fields.Many2many( calendar_event_id_partner_ids = fields.Many2many(
related="calendar_event_id.partner_ids", readonly=True 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): def open_origin(self):
self.ensure_one() self.ensure_one()

View File

@ -9,3 +9,7 @@
* `Pesol <https://www.pesol.es>`_: * `Pesol <https://www.pesol.es>`_:
* Pedro Gonzalez (pedro.gonzalez@pesol.es) * Pedro Gonzalez (pedro.gonzalez@pesol.es)
* `ACSONE SA/NV <https://www.acsone.eu>`_
* Laurent Mignon <laurent.mignon@acsone.eu>

View File

@ -202,3 +202,11 @@ class TestMailActivityBoardMethods(TransactionCase):
for act in acts: for act in acts:
self.assertIn(act, self.partner_client.activity_ids.ids) 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)

View File

@ -4,6 +4,45 @@
VIEWS VIEWS
--> -->
<!-- FORM POP
Add a link to the related model instance to ease navigation
-->
<record id="mail_activity_view_form_popup" model="ir.ui.view">
<field
name="name"
>mail.activity.view.form.popup (in mail_activity_board)</field>
<field name="model">mail.activity</field>
<field name="inherit_id" ref="mail.mail_activity_view_form_popup" />
<field name="arch" type="xml">
<field name="activity_type_id" position="before">
<field
name="related_model_instance"
attrs="{'invisible': [('related_model_instance','=', False)]}"
/>
</field>
</field>
</record>
<!-- CALENDAR VIEW
Add a link to the related model instance to ease navigation
-->
<record id="mail_activity_view_calendar" model="ir.ui.view">
<field
name="name"
>mail.activity.view.form.calendar (in mail_activity_board)</field>
<field name="model">mail.activity</field>
<field name="inherit_id" ref="mail.mail_activity_view_calendar" />
<field name="arch" type="xml">
<field name="res_name" position="before">
<field name="related_model_instance" />
</field>
<field name="res_name" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
<!-- FORM VIEW --> <!-- FORM VIEW -->
<record id="mail_activity_view_form_board" model="ir.ui.view"> <record id="mail_activity_view_form_board" model="ir.ui.view">
<field name="name">mail.activity.boards.view.form</field> <field name="name">mail.activity.boards.view.form</field>
@ -88,7 +127,12 @@
name="decoration-success" name="decoration-success"
>(date_deadline &gt; current_date)</attribute> >(date_deadline &gt; current_date)</attribute>
</xpath> </xpath>
<field name="res_name" position="before">
<field name="related_model_instance" />
</field>
<field name="res_name" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field> </field>
</record> </record>