Skip to content

Commit 89317da

Browse files
committed
[IMP] Add a "Parent Lead" oe_stat_button to child tasks of leads
1 parent 9d7942e commit 89317da

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

crm_project_task/models/project_task.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@ def default_get(self, fields):
3030
# permission to read them
3131
self = self._get_sudo_env_with_context()
3232
return super().default_get(fields)
33+
34+
def action_open_parent_lead(self):
35+
return {
36+
"name": self.env._("Parent Lead"),
37+
"view_mode": "form",
38+
"res_model": "crm.lead",
39+
"res_id": self.lead_id.id,
40+
"type": "ir.actions.act_window",
41+
"context": self.env.context,
42+
}

crm_project_task/tests/test_crm_project_task.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,21 @@ def test_res_config_settings_related_default_project(self):
221221

222222
settings.crm_default_project_id = self.project_2
223223
self.assertEqual(self.company.crm_default_project_id, self.project_2)
224+
225+
def test_action_open_parent_lead(self):
226+
task = self.env["project.task"].create(
227+
{
228+
"name": "Task linked to lead",
229+
"lead_id": self.lead.id,
230+
"project_id": self.project.id,
231+
}
232+
)
233+
234+
action = task.action_open_parent_lead()
235+
236+
self.assertEqual(action["type"], "ir.actions.act_window")
237+
self.assertEqual(action["name"], self.env._("Parent Lead"))
238+
self.assertEqual(action["view_mode"], "form")
239+
self.assertEqual(action["res_model"], "crm.lead")
240+
self.assertEqual(action["res_id"], self.lead.id)
241+
self.assertEqual(action["context"], task.env.context)

crm_project_task/views/project_task.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
<field name="model">project.task</field>
88
<field name="inherit_id" ref="project.view_task_form2" />
99
<field name="arch" type="xml">
10+
<xpath expr="//div[@name='button_box']" position="inside">
11+
<button
12+
name="action_open_parent_lead"
13+
type="object"
14+
class="oe_stat_button"
15+
icon="fa-handshake-o"
16+
invisible="not lead_id"
17+
string="Parent Lead"
18+
/>
19+
</xpath>
1020
<xpath expr="//page[@name='extra_info']" position="inside">
1121
<group name="crm" string="Lead/Opportunity">
1222
<field name="lead_id" />

0 commit comments

Comments
 (0)