From 45b2d20ce5d9c56aafc73e3cd5e1c40b39fc21dd Mon Sep 17 00:00:00 2001 From: Santiago Rodriguez Date: Thu, 1 Aug 2024 09:56:42 -0600 Subject: [PATCH 1/4] [ADD] crm_lead_to_task: Add relationship and smart buttons --- crm_lead_to_task/__init__.py | 1 + crm_lead_to_task/__manifest__.py | 1 + crm_lead_to_task/models/__init__.py | 2 ++ crm_lead_to_task/models/crm_lead.py | 27 +++++++++++++++++++ crm_lead_to_task/models/project_task.py | 22 +++++++++++++++ crm_lead_to_task/views/crm_lead_views.xml | 13 ++++++++- crm_lead_to_task/views/project_task_views.xml | 19 +++++++++++++ .../wizard/crm_lead_convert2task.py | 1 + 8 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 crm_lead_to_task/models/__init__.py create mode 100644 crm_lead_to_task/models/crm_lead.py create mode 100644 crm_lead_to_task/models/project_task.py create mode 100644 crm_lead_to_task/views/project_task_views.xml diff --git a/crm_lead_to_task/__init__.py b/crm_lead_to_task/__init__.py index 73db51cb2da..a90b62cfa26 100644 --- a/crm_lead_to_task/__init__.py +++ b/crm_lead_to_task/__init__.py @@ -1,2 +1,3 @@ # License LGPL-3 - See https://www.gnu.org/licenses/lgpl-3.0.html +from . import models from . import wizard diff --git a/crm_lead_to_task/__manifest__.py b/crm_lead_to_task/__manifest__.py index 10613798c24..b1e50bd646c 100644 --- a/crm_lead_to_task/__manifest__.py +++ b/crm_lead_to_task/__manifest__.py @@ -18,5 +18,6 @@ "security/ir.model.access.csv", "wizard/crm_lead_convert2task_views.xml", "views/crm_lead_views.xml", + "views/project_task_views.xml", ], } diff --git a/crm_lead_to_task/models/__init__.py b/crm_lead_to_task/models/__init__.py new file mode 100644 index 00000000000..b90fb24ae6c --- /dev/null +++ b/crm_lead_to_task/models/__init__.py @@ -0,0 +1,2 @@ +from . import crm_lead +from . import project_task diff --git a/crm_lead_to_task/models/crm_lead.py b/crm_lead_to_task/models/crm_lead.py new file mode 100644 index 00000000000..a6deb7d73d4 --- /dev/null +++ b/crm_lead_to_task/models/crm_lead.py @@ -0,0 +1,27 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +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(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_view_tasks(self): + self.ensure_one() + return { + "type": "ir.actions.act_window", + "res_model": "project.task", + "view_mode": "tree,form", + "domain": [('lead_id', '=', self.id)], + "context": {"default_search_lead_id": self.id}, + "name": _("Tasks from crm lead %s") % self.name, + } diff --git a/crm_lead_to_task/models/project_task.py b/crm_lead_to_task/models/project_task.py new file mode 100644 index 00000000000..0b742634bee --- /dev/null +++ b/crm_lead_to_task/models/project_task.py @@ -0,0 +1,22 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, fields, models + + +class ProjectTask(models.Model): + _inherit = "project.task" + + lead_id = fields.Many2one('project.task') + + def action_view_lead(self): + self.ensure_one() + return { + "type": "ir.actions.act_window", + "res_model": "crm.lead", + "view_mode": "form", + "res_id": self.lead_id.id, + "target": "current", + "name": _("Lead: %s") % self.lead_id.name, + } + diff --git a/crm_lead_to_task/views/crm_lead_views.xml b/crm_lead_to_task/views/crm_lead_views.xml index c71064dfbab..cfd276cc30b 100644 --- a/crm_lead_to_task/views/crm_lead_views.xml +++ b/crm_lead_to_task/views/crm_lead_views.xml @@ -3,7 +3,7 @@ crm.lead - + + diff --git a/crm_lead_to_task/views/project_task_views.xml b/crm_lead_to_task/views/project_task_views.xml new file mode 100644 index 00000000000..3f0e36237df --- /dev/null +++ b/crm_lead_to_task/views/project_task_views.xml @@ -0,0 +1,19 @@ + + + + project.task.view.form.inherit.crm.lead.to.task + project.task + + + + + + + + + + diff --git a/crm_lead_to_task/wizard/crm_lead_convert2task.py b/crm_lead_to_task/wizard/crm_lead_convert2task.py index 109ba4fcecb..d4e9ccbd0ec 100644 --- a/crm_lead_to_task/wizard/crm_lead_convert2task.py +++ b/crm_lead_to_task/wizard/crm_lead_convert2task.py @@ -39,6 +39,7 @@ def action_lead_to_project_task(self): "project_id": self.project_id.id, "partner_id": partner.id, "email_cc": lead.email_cc, + "lead_id": lead.id, } task = self.env["project.task"].create(vals) # move the mail thread From 3c741d0eef13f90560ca676f02b0a79cb2fda599 Mon Sep 17 00:00:00 2001 From: Santiago Rodriguez Date: Thu, 1 Aug 2024 10:43:05 -0600 Subject: [PATCH 2/4] [FIX] crm_lead_to_task: pre-commit --- crm_lead_to_task/models/crm_lead.py | 6 ++--- crm_lead_to_task/models/project_task.py | 3 +-- crm_lead_to_task/views/crm_lead_views.xml | 24 ++++++++++++++----- crm_lead_to_task/views/project_task_views.xml | 10 ++++++-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/crm_lead_to_task/models/crm_lead.py b/crm_lead_to_task/models/crm_lead.py index a6deb7d73d4..f3188727655 100644 --- a/crm_lead_to_task/models/crm_lead.py +++ b/crm_lead_to_task/models/crm_lead.py @@ -7,10 +7,10 @@ class CrmLead(models.Model): _inherit = "crm.lead" - task_ids = fields.One2many('project.task', 'lead_id') + task_ids = fields.One2many("project.task", "lead_id") task_count = fields.Integer(compute="_compute_task_count") - @api.depends('task_ids') + @api.depends("task_ids") def _compute_task_count(self): for lead in self: lead.task_count = len(lead.task_ids) @@ -21,7 +21,7 @@ def action_view_tasks(self): "type": "ir.actions.act_window", "res_model": "project.task", "view_mode": "tree,form", - "domain": [('lead_id', '=', self.id)], + "domain": [("lead_id", "=", self.id)], "context": {"default_search_lead_id": self.id}, "name": _("Tasks from crm lead %s") % self.name, } diff --git a/crm_lead_to_task/models/project_task.py b/crm_lead_to_task/models/project_task.py index 0b742634bee..0b5b039741a 100644 --- a/crm_lead_to_task/models/project_task.py +++ b/crm_lead_to_task/models/project_task.py @@ -7,7 +7,7 @@ class ProjectTask(models.Model): _inherit = "project.task" - lead_id = fields.Many2one('project.task') + lead_id = fields.Many2one("project.task") def action_view_lead(self): self.ensure_one() @@ -19,4 +19,3 @@ def action_view_lead(self): "target": "current", "name": _("Lead: %s") % self.lead_id.name, } - diff --git a/crm_lead_to_task/views/crm_lead_views.xml b/crm_lead_to_task/views/crm_lead_views.xml index cfd276cc30b..a1cd4335437 100644 --- a/crm_lead_to_task/views/crm_lead_views.xml +++ b/crm_lead_to_task/views/crm_lead_views.xml @@ -3,7 +3,7 @@ crm.lead - + diff --git a/crm_lead_to_task/views/project_task_views.xml b/crm_lead_to_task/views/project_task_views.xml index 3f0e36237df..34be798c1e4 100644 --- a/crm_lead_to_task/views/project_task_views.xml +++ b/crm_lead_to_task/views/project_task_views.xml @@ -3,11 +3,17 @@ project.task.view.form.inherit.crm.lead.to.task project.task - + -