Merge PR #887 into 15.0

Signed-off-by etobella
This commit is contained in:
OCA-git-bot 2022-07-05 16:10:47 +00:00
commit c29fc8f06b
5 changed files with 78 additions and 3 deletions

View File

@ -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"],

View File

@ -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()

View File

@ -9,3 +9,7 @@
* `Pesol <https://www.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:
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
-->
<!-- 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 -->
<record id="mail_activity_view_form_board" model="ir.ui.view">
<field name="name">mail.activity.boards.view.form</field>
@ -18,7 +57,8 @@
class="centre oe_link"
nolabel="1"
>
<h1><field name="res_name" /></h1>
<field name="res_name" invisible="1" />
<h1><field name="related_model_instance" /></h1>
</button>
<field name="activity_category" invisible="1" />
<field name="res_model" invisible="1" />
@ -88,7 +128,12 @@
name="decoration-success"
>(date_deadline &gt; current_date)</attribute>
</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>
</record>