Skip to content

Commit

Permalink
[15.0][ADD] link between lead and task
Browse files Browse the repository at this point in the history
- Added field lead_id in task.
- Added field task_ids in lead.
- Added smart button in lead to show related tasks.
  • Loading branch information
EmilioPascual committed Jul 31, 2023
1 parent 238a380 commit c06b9e8
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 13 deletions.
1 change: 1 addition & 0 deletions crm_project_task/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"views/res_config_settings.xml",
"wizards/crm_create_task.xml",
"views/crm_lead.xml",
"views/project_task.xml",
],
}
27 changes: 26 additions & 1 deletion crm_project_task/i18n/crm_project_task.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Project-Id-Version: Odoo Server 15.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-25 13:19+0000\n"
"PO-Revision-Date: 2023-07-25 13:19+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: crm_project_task
#: model:ir.model.fields,field_description:crm_project_task.field_crm_lead__task_count
msgid "#Task"
msgstr ""

#. module: crm_project_task
#: model_terms:ir.ui.view,arch_db:crm_project_task.res_config_settings_view_form
msgid ""
Expand Down Expand Up @@ -95,9 +102,16 @@ msgstr ""

#. module: crm_project_task
#: model:ir.model.fields,field_description:crm_project_task.field_crm_create_task__lead_id
#: model:ir.model.fields,field_description:crm_project_task.field_project_task__lead_id
msgid "Lead"
msgstr ""

#. module: crm_project_task
#: model:ir.model,name:crm_project_task.model_crm_lead
#: model_terms:ir.ui.view,arch_db:crm_project_task.view_task_form2_inherit_crm_project_task
msgid "Lead/Opportunity"
msgstr ""

#. module: crm_project_task
#: code:addons/crm_project_task/wizards/crm_create_task.py:0
#, python-format
Expand All @@ -110,6 +124,12 @@ msgstr ""
msgid "Projects"
msgstr ""

#. module: crm_project_task
#: model:ir.model,name:crm_project_task.model_project_task
#: model:ir.model.fields,field_description:crm_project_task.field_crm_lead__task_ids
msgid "Task"
msgstr ""

#. module: crm_project_task
#: code:addons/crm_project_task/wizards/crm_create_task.py:0
#, python-format
Expand All @@ -131,6 +151,11 @@ msgid ""
"id=%(lead)d>%(name)s</a>."
msgstr ""

#. module: crm_project_task
#: model_terms:ir.ui.view,arch_db:crm_project_task.inherit_crm_lead_view_form_crm_project_task
msgid "Task(s)"
msgstr ""

#. module: crm_project_task
#: model:ir.model,name:crm_project_task.model_crm_create_task
msgid "Wizard to create task"
Expand Down
2 changes: 2 additions & 0 deletions crm_project_task/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from . import res_config_settings
from . import res_company
from . import project_task
from . import crm_lead
24 changes: 24 additions & 0 deletions crm_project_task/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Moduon Team S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)

from odoo import api, fields, models


class CrmLead(models.Model):
_inherit = "crm.lead"

task_ids = fields.One2many("project.task", "lead_id")
task_count = fields.Integer("#Task", compute="_compute_task_count")

@api.depends("task_ids")
def _compute_task_count(self):
for lead in self:
lead.task_count = len(lead.task_ids)

def action_tasks(self):
self.ensure_one()
ctx = self._context.copy()
action = self.env.ref("project.action_view_task").sudo().read()[0]
ctx.update({"default_lead_id": self.id})
action.update({"context": ctx, "domain": [("lead_id", "=", self.id)]})
return action
10 changes: 10 additions & 0 deletions crm_project_task/models/project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2023 Moduon Team S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)

from odoo import fields, models


class CrmLead(models.Model):
_inherit = "project.task"

lead_id = fields.Many2one("crm.lead")
39 changes: 28 additions & 11 deletions crm_project_task/tests/test_crm_project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,23 @@ def test_create_task(self):
self.company.crm_default_project_id = self.project
task_name = "Task Test"
task_description = "Line1</br>Line2"
prev_tasks = self.project.task_ids
self.env["crm.create.task"].with_user(self.user_salesman).create(
{
"lead_id": self.lead.id,
"task_name": task_name,
"description": task_description,
}
).create_task()
tasks = self.project.task_ids
self.assertEqual(len(prev_tasks) + 1, len(tasks))
task = tasks - prev_tasks
action = (
self.env["crm.create.task"]
.with_user(self.user_salesman)
.create(
{
"lead_id": self.lead.id,
"task_name": task_name,
"description": task_description,
}
)
.create_task()
)
task = self.env["project.task"].browse(action["res_id"])
self.assertEqual(task.name, task_name)
self.assertEqual(task.project_id, self.company.crm_default_project_id)
self.assertEqual(task.partner_id, self.partner)
self.assertEqual(task.lead_id, self.lead)

def test_create_task_no_project(self):
self.company.crm_default_project_id = False
Expand All @@ -78,3 +81,17 @@ def test_create_task_no_project(self):
)
with self.assertRaises(UserError):
wizard.create_task()

def test_action_tasks(self):
self.company.crm_default_project_id = self.project
self.env["crm.create.task"].with_user(self.user_salesman).create(
{
"lead_id": self.lead.id,
"task_name": "Task Test",
"description": "Line1</br>Line2",
}
).create_task()
action = self.lead.action_tasks()
tasks = self.env["project.task"].search(action["domain"])
tasks_lead = tasks.mapped("lead_id")
self.assertEqual(self.lead, tasks_lead)
12 changes: 11 additions & 1 deletion crm_project_task/views/crm_lead.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@
type="action"
class="oe_highlight"
context="{'default_lead_id': active_id, 'default_task_name': name}"
attrs="{'invisible': [('active','=',False)]}"
attrs="{'invisible': ['|', ('active','=',False), ('task_count', '!=', 0)]}"
/>
</xpath>
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
<button
name="action_tasks"
type="object"
class="oe_stat_button"
icon="fa-tasks"
>
<field string="Task(s)" name="task_count" widget="statinfo" />
</button>
</xpath>
</field>
</record>

Expand Down
17 changes: 17 additions & 0 deletions crm_project_task/views/project_task.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Moduon Team S.L.
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
<odoo>
<record id="view_task_form2_inherit_crm_project_task" model="ir.ui.view">
<field name="name">project.task.form.inherit</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2" />
<field name="arch" type="xml">
<xpath expr="//page[@name='extra_info']" position="inside">
<group name="crm" string="Lead/Opportunity">
<field name="lead_id" />
</group>
</xpath>
</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions crm_project_task/wizards/crm_create_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def create_task(self):
}

def _get_data_create(self, project):
"""Get dict to create task"""
return {
"name": self.task_name,
"project_id": project.id,
"partner_id": self.lead_id.partner_id.id,
"lead_id": self.lead_id.id,
"description": self.description,
"user_ids": [(6, 0, [])],
}

0 comments on commit c06b9e8

Please sign in to comment.