From 85a485034b90db866da720a8edc5aee83365be72 Mon Sep 17 00:00:00 2001 From: hiroh-odoo Date: Mon, 16 May 2022 07:17:35 +0000 Subject: [PATCH] [IMP] sale_(project): improve ux' for project Purpose of this PR to improve the generic usage of project app So in this commit done the following changes: - when a project is archived, the 'tasks' stat button should count/show archived tasks - when delete project it's milestone should also be deleted automatically. - project.task > blocked by notebook: it should be possible to select tasks in projects that are not allowing 'task dependencies' - project.task portal form view: hide the description if it is empty task-2853991 closes odoo/odoo#94138 Related: odoo/enterprise#28654 Signed-off-by: Laurent Stukkens (ltu) --- addons/project/models/project.py | 20 +++++++++++++------ addons/project/models/project_milestone.py | 2 +- .../views/project_portal_templates.xml | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index bfbae2e554a..7abffa31fa0 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -236,18 +236,25 @@ class Project(models.Model): project.doc_count = docs_count.get(project.id, 0) def _compute_task_count(self): - task_data = self.env['project.task']._read_group( - [('project_id', 'in', self.ids), - ('is_closed', '=', False)], - ['project_id', 'display_project_id:count'], ['project_id']) + domain = [('project_id', 'in', self.ids), ('is_closed', '=', False)] + fields = ['project_id', 'display_project_id:count'] + groupby = ['project_id'] + task_data = self.env['project.task']._read_group(domain, fields, groupby) result_wo_subtask = defaultdict(int) result_with_subtasks = defaultdict(int) for data in task_data: result_wo_subtask[data['project_id'][0]] += data['display_project_id'] result_with_subtasks[data['project_id'][0]] += data['project_id_count'] + task_all_data = self.env['project.task'].with_context(active_test=False)._read_group(domain, fields, groupby) + all_tasks_wo_subtasks = defaultdict(int) + for data in task_all_data: + all_tasks_wo_subtasks[data['project_id'][0]] += data['display_project_id'] + for project in self: project.task_count = result_wo_subtask[project.id] project.task_count_with_subtasks = result_with_subtasks[project.id] + if not project.active: + project.task_count = all_tasks_wo_subtasks[project.id] def _default_stage_id(self): # Since project stages are order by sequence first, this should fetch the one with the lowest sequence number. @@ -749,6 +756,7 @@ class Project(models.Model): context = ast.literal_eval(context) context.update({ 'create': self.active, + 'active_test': self.active }) action['context'] = context return action @@ -1193,10 +1201,10 @@ class Task(models.Model): # Tracking of this field is done in the write function depend_on_ids = fields.Many2many('project.task', relation="task_dependencies_rel", column1="task_id", column2="depends_on_id", string="Blocked By", tracking=True, copy=False, - domain="[('allow_task_dependencies', '=', True), ('id', '!=', id)]") + domain="[('project_id', '!=', False), ('id', '!=', id)]") dependent_ids = fields.Many2many('project.task', relation="task_dependencies_rel", column1="depends_on_id", column2="task_id", string="Block", copy=False, - domain="[('allow_task_dependencies', '=', True), ('id', '!=', id)]") + domain="[('project_id', '!=', False), ('id', '!=', id)]") dependent_tasks_count = fields.Integer(string="Dependent Tasks", compute='_compute_dependent_tasks_count') is_blocked = fields.Boolean(compute='_compute_is_blocked', store=True, recursive=True) diff --git a/addons/project/models/project_milestone.py b/addons/project/models/project_milestone.py index a9ca91545b5..ba6645d0434 100644 --- a/addons/project/models/project_milestone.py +++ b/addons/project/models/project_milestone.py @@ -15,7 +15,7 @@ class ProjectMilestone(models.Model): return self.env.context.get('default_project_id') or self.env.context.get('active_id') name = fields.Char(required=True) - project_id = fields.Many2one('project.project', required=True, default=_get_default_project_id) + project_id = fields.Many2one('project.project', required=True, default=_get_default_project_id, ondelete='cascade') deadline = fields.Date(tracking=True, copy=False) is_reached = fields.Boolean(string="Reached", default=False, copy=False) reached_date = fields.Date(compute='_compute_reached_date', store=True) diff --git a/addons/project/views/project_portal_templates.xml b/addons/project/views/project_portal_templates.xml index 68ca6c83c1a..c51d94e3069 100644 --- a/addons/project/views/project_portal_templates.xml +++ b/addons/project/views/project_portal_templates.xml @@ -320,7 +320,7 @@
-
+

Description